Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Does REBOL cons?

From: gabriele::colellachiara::com at: 16-Mar-2006 10:38

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 <> --- Colella Chiara software division ---