Please help me understand about initialising a series in a function. I have the following test case. The aim is to have an empty block each time the function is run.
test-me: function [str [string!]] [ my-series:  print [">" my-series] foreach x str [append my-series to-integer to-string x] ] test-me "123" test-me "456" test-me "789"
However the output emitted by the print statement in the function shows me the series is not initialised to empty each time the function is called, i.e. I see:
> > 1 2 3 > 1 2 3 4 5 6
so I guess
my-series:  is not the best way to init an empty series for this case.
@xqlab thanks alot -
clear is good. This is a bit counter-intuitive, unless a series can be like a static variable (in the way I did it). I guess I take it away as another learning :-). The reason why it's confusing is in the REPL it seems to work logically:
>> a: [1 2 3] == [1 2 3] >> a:  ==  >> a == 
of course it might just be the behaviour in a function is different.
clear is the most memory-saving option.
word: is, and how it is evaluated. It is deeply different from what you would have in another language (like in JS:
v=). Understanding such expression is a key part of understanding Redbol.
word: is data, which eventually gets evaluated. In JS,
v=;is just code.
@dockimbel The last 5 lines of the documentation cleared everything:
One more thing. The colon (:) suffix in a word is not an assignment operator (as in other languages), it's part of the set-word! datatype literal syntax. When evaluated, it binds the word to the result of next expression. It doesn't do anything more than that. So a: "" does not "reset" or "reinitialize" the "variable" a. That is an incorrect interpretation, it just makes the word a refer to the literal string "" which follows it.
word!and that never changes. A word can exist and be manipulated, without referring to any other value. A word can refer to values of any type. Making a word refer to a value (let's say a string), does not change the type of the word, it is still
word!. So, in Redbol, you have two distinct entities: word and the referred value. Such distinction does not exist in most other languages, which just have "variables", that's why such term can be misleading in Redbol.