Hi Robert,

1. Your localvar, even though you call it localvar is a global word. To
make it a local word, either say:

test: func [input [block!] /local localvar] []

or

test: func [input [block!]] [
  use [localvar] [
  ]
] 

2. As a matter of principle it's not a good idea to use the word input as
an argument of a function, since input is the REBOL function that collects
user input. It's harmless in your example, since the new binding of input
does not affect the global word, and therefore it remains the function it
defaults to, however, you may get unexpected results if you were to want to
use the default input in the function. It's simply better left alone.

3. The behavior you describe has been documented and discussed repeatedly
on the list. The literal string "" is not a constant. It is a string that
will grow as you add items to it and retain those items. Therefore, when
you re-enter the function you will find the values that you appended
previously still populate the literal string:
>> f: func [][ append "" "abc" ]
>> source f
f: func [][append "" "abc"]
>> f
== "abc"
>> f
== "abcabc"
>> source f
f: func [][append "abcabc" "abc"]


4. In order to start with an empty string each time you enter the function
you can 

a) use clear 

localvar: clear ""

>> f: func [][ append clear "" "abc" ]
>> source f
f: func [][append clear "" "abc"]
>> f
== "abc"
>> f
== "abc"
>> source f
f: func [][append clear "abc" "abc"]

b) use copy
localvar: copy ""

c) or - as you point out - use make
localvar: make string! 0



;- Elan >> [: - )]

Reply via email to