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

[REBOL] Re: Does REBOL cons?

From: Izkata:Comcast at: 15-Mar-2006 16:29

This goes back to the "everything is data" idea:
>> foo: func [/local a][
[ a: [a b c] [ append a [d] [ ]
>> foo
== [a b c d]
>> foo ;Your function and it's two calls
== [a b c d d]
>> source foo ;Look at the source
foo: func [/local a][ a: [a b c d d] ;Assigning that block to 'a didn't copy it; it pointed at it (using C/C++ terms) append a [d] ]
>> foo
== [a b c d d d]
>> source foo
foo: func [/local a][ a: [a b c d d d] ;Every time 'foo is called, the list gets another addition... append a [d] ] Now, had it been "a: copy [a b c]" instead, 'a wouldn't be pointing at the block in the function, it would be pointing at a new block that looks exactly the same, each time the function is called. Any series (like string!) works the same way. -Izzy