revLISP (actually is scheme...) Some doubts on implementation.
Dar Scott
dsc at swcp.com
Thu Mar 25 22:47:02 EST 2004
On Thursday, March 25, 2004, at 07:36 PM, Andre Garzia wrote:
> Scheme is a LISP-like system. The interpreter is based on cells. Cells
> have some attributes like pointers (sorry, this is C-like talk, I
> should have said references) to other cells and some info on it's
> container and ID... How should I implement a structure in Rev, should
> I go for keyed arrays? can an array contain another array as an
> element?
Currently, an array cannot contain another array as an element. There
is a request for that, since that can be interpreted as a
multidimensional array. I hope it comes. This might also allow the
use of arrays as property values.
There are a couple ways to go for a generic simple lisp depending on
how much you want to do. For Scheme you may need to modify this.
1
If you do not share or mutate shared data, then a cons tree or list can
be a single string structured in a way that has pairs. For example,
suppose you use the first letter for type info. A "C" means cons and
other letters refer to other types. After the C is 9 digits. This is
the length of the CAR or first of the pair. The data after the first
is the rest or the CDR. These can be nested arbitrarily deep.
Philosophically, this is much like how I made "boxes".
2
Another way to go is to use a global array (or several) as your memory
space.
A. One array
Each element is a leaf value or a cons cell. The first letter
designates the type. A cons cell after the type is a pair of indexes
into the array. You can probably come up with a better way to organize
this.
B. Three arrays
Like above but one array for the type, one for the value and one for
the second value if the type is a cons.
You can add reference counting or garbage collection to either of A or
B. You can share sub structures and you can mutate parts, even shared
parts.
Your exercise might help you think up all kinds of ways to store info
as Revolution values. I don't know how XML data is stored; it might
give a clue to a third method.
Dar Scott
More information about the use-livecode
mailing list