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

[REBOL] : [] in a function => was {Re: Re: to-char}

From: jason:cunliffe:verizon at: 13-Feb-2002 20:44

From: "Carl Read" <[carl--cybercraft--co--nz]>
> > What is going on when I call it within a function and then call the > > function repeatedly [when the previous values remain]. ie: why do I > > _really_ need clear or copy? > > The reason can be seen in the above, in that it remains the same > block. Meaning you haven't made a copy of the block. Continuing on > with the above, this shows the difference 'copy makes...
Carl..thanks ok. This is what I still don't deeply get:
>> someblock: []
== []
>> append someblock "a"
== ["a"]
>> append someblock "b"
== ["a" "b"]
>> append someblock "c"
== ["a" "b" "c"]
>> someblock: []
== []
>> someblock
== []
>> head someblock
== [] BUT.. when I do the same thing within a script function: change-block: func [str [string!] /local someblock][ someblock: [] append someblock str return someblock ]
>> change-block "hello"
== ["hello"]
>> change-block "goodbye"
== ["hello" "goodbye"] Q: Why, at the console does someblock: [] create a fresh block, but within a script function someblock: [] persists and needs to be remedied by copy [], clear [] or make block! 123 statements?
> More on functions: A series is created when the function is first > created and not each time the function is called, which is why what's > in a series will persist from function-call to function-call unless > you specifically clear it or make a copy of it. Whether to use 'copy > or 'clear (or neither for that matter) will depend on the behaviour > you want from the series.
aha!, but this sounds like the second time I call my change-block function, it is sees 'someblock: []' rebol says "oh I already got that", yet when it reads copy, clear make it changes its mind and redfines someblock? This seems pretty inconsistent to me. I know how to use it, but want to grok further rebolzen. Please keep trying to explain me this rudiment.. thanks again ./Jason