The operator for creating and deferencing a pointer is . To create a pointer that points to x, one can use
p = >>xOne can combine the two operators = and
p =>> xOne may read the above as ``let p point to x''
To retrieve the value pointed to by p, one can use
v = p>>One may read the above as "Let v be the value that p points to"
To reset the value that p points to
p>> = 3or you may use
p >>= 3
There are two types of pointers. The first is created using
p =>> xHere p is like the address of a local variable x, and through p »= one can reset the value of x. Such a pointer cannot be returned as function return value, otherwise, referencing the return value will result in an error.
If p doesn't exist, or p is not a pointer, then doing
p >>= 3will create a pointer that points to a piece of anonymous data. This is similar to the malloc function in C. Such a pointer can be return by a function. Here the lvalue must be a variable.
There is also a built-in function newpointer that can be used to create a new pointer pointing to given data. For example p »= 3 is equivalent to
p = newpointer(3);
oz 2009-12-22