[REBOL] problems with local vars??? Re:(4)
From: agem:crosswinds at: 18-Aug-2000 13:37
i add my description too hope its new :)
REBOL makes no destinction beetween data and program.
not to the user: you can edit text and you can load (do) text.
not to the program: it can edit blocks and load (do) blocks.
the "a:" should be seen as a "bookmark" in a block.
nothing more. in a functions it bookmarks into a part
of the function. if it changes its content, it changes
the function too. if you want to avoid it, you have
to tell the system "i need a new block". which can
be done by
copy "this string (or block or other series)"
or
make string! 1000 ;empty string with 1000 char preallocated
when it comes to do code, the system can not decide
if a block is only read or changed to:
if something [some code]
print "this string"
change [datas here] 'code
yes-way: [some code] if something yes-way ...
and maybe one wishes to really change the function?
simply like c's "statics" or because of clever meta-hacks or
to keep scripts shorter? would need new sytax otherwise.
>> repeat i 10 [append [] i]
== [1 2 3 4 5 6 7 8 9 10]
( do copy [repeat i 10 [append [] i] ] ; in a function ..)
or
repeat i 10 [append list: [] i] probe list
you can collect scripts output with
>> &: func[s][append append "" s ", "]
>> & "this" & "that" third second :&
== "this, that, "
short :)
>> &: func[s][append append "" s ", "]
>> get-res: third second :& 3 ;change if '& changes!
== 3
>> & "this" & "that" res ;use it
== "this, that, "
safer. i remember to change 'get-res if you change '& ..
>> &: func[s][append append res: "" s ", "]
>> & "this" & "that" res
== "this, that, "
better. should have thought before :)
other ways like auto-copy may break concepts i not
know yet.., and may be slower..
--
Volker
--- [bhandley--zip--com--au] wrote on 18-Aug-2000/10:09:43+10:00