[REBOL] SV: Re: Func, why does it remeber previous data?
From: micael:gullmes:telenordia:se at: 11-Nov-2000 0:17
Elan,
Thanks, now I understand, and it works like a charm.
Brgds/Micael
-----Ursprungligt meddelande-----
Fran: Elan [mailto:[rebol--techscribe--com]]
Skickat: den 11 november 2000 00:05
Till: [rebol-list--rebol--com]
Amne: [REBOL] Re: Func, why does it remeber previous data?
Hi Micael,
you wrote:
> probe data_to_find: #{ACDC}
> probe append data_to_find do rejoin ["#{" tail_data "}"]
1. You associate the word data_to_find with the binary literal #{ACDC}. Now
any manipulation that is directed at data_to_find will modify the string
${ACDC}. Specifically when you
2. append the result of the expression do rejoin [...] to data_to_find, that
result is appended to the binary literal #{ACDC}. When the function is
called
again at a later point in time data_to_find is assigned to the binary liter
#{ACDC <....>} where <...> is a placeholder for whatever it is you appended
to the literal string on previous function calls.
3. Setting data_to_find to an empty string literal before you set
data_to_find to the binary literal, and/or clearing that string literal does
not (and cannot) in any way effect the binary literal. First the word
pointed
at an empty string literal that was cleared, now it points at a different
literal value, the binary literal that has accumulated data that was
appended
to it during the previous function call.
4. Use data_to_find: copy #{ACDC} or data_to_find: make binary! {ACDC} to
prevent the appended data from accumulating in the binary literal that you
want preserved as is. The copy of the binary literal will be affected by
subsequent manipulations (append ...), whereas the prototype binary literl
#{ACDC} remains unmodified.
If you program in C then think of data_to_find as a pointer to a memory
address. Whatever you do to data_to_find directly effects the value it is
associated with, either the prototype string literal itself, or the unique
copy of it that you force using copy or make binary!.
Hope this helps,
Elan