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

[REBOL] Re: Does REBOL cons?

From: massung:g:mail at: 15-Mar-2006 16:48

Hehe. Let me explain why I'm a bit confused and maybe that will help. I just want to build off what you originally replied with. Okay, so, the definition of a cons, of course, is just a trivial, uni-directional, linked-list: (A . (B . (C . NIL))) -> (A B C) (D . NIL) -> (D) The reason that the original list in FOO changes (assuming that REBOL uses conses) is that the cons holding 'C' is modified to also include the D cons: (A . (B . (C . (D . NIL)))) -> (A B C D) And, of course, since the function FOO just makes use of that pre-allocated list in bytecode (or whatever REBOL uses for interpretation of data), the source of FOO changes with each call. However, [d] is no different from [a b c] in the source (meaning that both are "pre-allocated data" - for lack of a better term - they aren't recreated each call). Suppose I wrote the function like this: foo: func [/local a b] [ a: [a b c] b: [d] append a b ] Now, after the first call, the function's source is now: foo: func [/local a b] [ a: [a b c d] b: [d] append a b ] Simple enough. But, the last cons in the list that 'a' points to is the same cons that 'b' points to (if REBOL is consing). So, after the second call, we should have an infinite list: foo: func [/local a b] [ a: [a b c d d d d d ... ] b: [d d d d d d ... ] append a b ] This is what Lisp does, and if REBOL conses, is what I would expect that it would do as well.It could also be that APPEND has a built-in safe guard, in that maybe it copies the second argument to prevent self-referencing objects? Anyway, perhaps this better explains my question. :-) Jeff M. -- massung-gmail.com On 3/15/06, Izkata <Izkata-comcast.net> wrote: