可变量的结构与表示
赋值
1 2 3
| float a = 0.1; Person p1 = new Person("Jackson"); p1.salary = 100000;
|
如何实现上述语义呢?
盒子里的变量
In Racket
: substitution-value
1 2 3 4 5 6
| #lang typed-plai
(define-type ExprC) ... [BoxC (val : Value)] )
|
In Java
: ref-replacement
1 2 3 4 5 6 7 8 9 10 11 12
| class Box<T> { private T the_value; Box(T v) { this.the_value = v; } T get() { return the_value; } void set(T v) { the_value = v; } }
|