[REBOL] Re: Does REBOL cons?
From: gabriele::colellachiara::com at: 16-Mar-2006 10:38
On Wednesday, March 15, 2006, 11:15:43 PM, you wrote:
JM> Okay, so, I've been trying something out, comparing REBOL to Lisp. The
JM> functions in REBOL make it appear as though the lists (series!) in REBOL are
JM> just your average conses (first, next, associations, etc). Because of this
JM> and constant data optimizations, etc, this function in REBOL makes sense:
You already got many answers, so I guess I'm not saying much news
at this point.
REBOL's blocks are actually "arrays" and not lists. (O(1) random
access, O(N) worst case inserts/removals).
You can picture a REBOL value with a box, that we'll call a value
slot, optionally referring to a data area.
| value slot |
| + - - - - - - . . . - +
+ - - - - > | data . . . |
+ - - - - - - . . . - +
In the current implementation a value slot is exactly 16 bytes. It
can hold any REBOL value; "scalar" values do not refer to the
optional data area depicted above, while series values do.
As you already know, many value slots can refer to the same series
So, a block value is actually a value slot of block type,
containing info such as the current position, and referring to an
array of value slots.
These arrays are automatically reallocated when needed to make
space for new slots (you can guess there's another level of
indirection involved because of this... but this is irrelevant for
Now let's look at what happens in your insert case, and what would
happen with INSERT/ONLY. Let's assume we have at least one free
slot at the tail of the A block.
+--->|[wrd a][wrd b][wrd c]-------|
Without the /ONLY refinents, what happens is that the slots are
copied from B to A:
+--->|[wrd a][wrd b][wrd c][wrd d]|
With /ONLY instead, the slot for the B block is copied into A:
+--->|[wrd a][wrd b][wrd c][block]|
b: [block] |
Hope this sheds some light. :)
(Note that LIST! values are liked lists, instead, but they aren't
cons either, i.e. you wouldn't get an infinite list in your case.
However, you should be able to see that's very easy to implement
cons with two-slots blocks.)
Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/
Colella Chiara software division --- http://www.colellachiara.com/