[hack/toy] Reified variables

Vassili Bykov vassili at parcplace.com
Thu May 2 15:25:11 UTC 2002


As promised to a few people at Smalltalk Solutions, here is a hack I did a 
while ago to create an illusion of variables having some first-class 
status.  See the file-out (known to work in 3.3a).

The basic idea is that whenever there is a variable "foo" in scope, a 
keyword-like expression "foo:" (or "foo :") is allowed in the receiver 
position. It evaluates to an instance of (a subclass of) ReifiedVariable, 
which is an object that understands messages #value and #value: to get and 
set the value of the variable. This is pretty much all there is to it, plus 
a number of methods implemented in ReifiedVariable to do various 
variable-like things. For example,

   a := 3

actually works as

   (a:) = 3

where = is a message to the variable to assign the argument. (Sure, it 
clashes with comparison, but I figured that will do for a hack). Other 
things one can do are things like

   a: + 4       "increment the value of a by 4"
   a: decrement "decrement it by 1"
   p := a:      "assign reified a to p (done by reified p!)"
   p + 10       "increment a by 10 through p"
   a: <> p:     "swap a and p"

See the example methods on the class side of ReifiedVariable.

Of course, this is not nearly as cool as the "reifier" quote of 
Smalltalk-72, but FWIW...

Cheers,

--Vassili
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ReifiedVariables.cs
Type: application/octet-stream
Size: 9671 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20020502/1368081a/ReifiedVariables.obj
-------------- next part --------------



More information about the Squeak-dev mailing list