Hi Jeff,

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
data.

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.

  [block]
       |
       +--->|[slot1][slot2]...[slotn]|

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).

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.

a:  [block]
         |
         +--->|[wrd a][wrd b][wrd c]-------|

b:  [block]
         |
         +--->|[wrd d]|

Without  the  /ONLY  refinents, what happens is that the slots are
copied from B to A:

a:  [block]
         |
         +--->|[wrd a][wrd b][wrd c][wrd d]|

b:  [block]
         |
         +--->|[wrd d]|

With /ONLY instead, the slot for the B block is copied into A:

a:  [block]
         |
         +--->|[wrd a][wrd b][wrd c][block]|
                                         |
               +-------------------------+
               |
b:  [block]    |
         |     V
         +--->|[wrd d]|

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.)

Regards,
   Gabriele.
-- 
Gabriele Santilli <[EMAIL PROTECTED]>  ---  http://www.rebol.com/
Colella Chiara software division --- http://www.colellachiara.com/

-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to