Automatically getting function arguments in Rebol
This works at the shell level:
>> a: "hello" == "hello" >> get to-lit-word "a" == "hello" But inside such a function:
f: func [ arg1 ] [ v1: get 'arg1 ? v1 v2: get to-lit-word "arg1" ? v2 ] >> f "goodbye" V1 is a string of value: "goodbye" ** Script Error: arg1 has no value ** Where: f ** Near: v2: get to-lit-word "arg1" How to get the value of an argument using "get"?
First, I mentioned that when using v1 and v2 in a similar FUNC, you write them in an encompassing context. Thus, they will act as "global variables." To suppress what you put in your FUNC-spec func [arg1 /local v1 v2] .
(Note: Rebol3 has a FUNCTION function that automatically scans LANs and creates a basic FUNC for you, but FUNCTION means something else in Rebol2, so this is available as FUNCT.)
Also: when you write get 'a , you do not pass the lit-word to receive. Their illumination is what makes them not look up, and when the evaluator runs through it ... the illuminated word is evaluated as a word:
>> type? 'a == word! If you really want to pass a backlit argument to a function, you will have to quote it:
>> type? quote 'a == lit-word! GET, apparently, does not refuse that you give him a bright word !, although I think it would be clearer if he were more narrowly typed. In any case, I would write it as get to-word "a" .
I am probably a bad person to try to answer your main question. But I will point out that even the first template does not work in Rebol 3:
>> a: "hello" == "hello" >> get to-word "a" ** Script error: a word is not bound to a context ** Where: get ** Near: get to-word "a" For GET to find the meaning of a word, this is not enough to just “be a word”. This word should be tied to some object that acts as a "context"; and anchor is a property associated with the word itself.
Rebol 2 is slightly different from Rebol 3. But if you want fire information, there are a few posts on the topic:
What is a summary of the differences in binding behavior between Rebol 2 and 3?
Often I find that I can get around where I would say to-word "some-string" , instead saying load "some-string" . So, in Rebol3:
>> a: "hello" == "hello" >> get load "a" == "hello" These function arguments look different. You can manually bind the converted word to the context that you get by requesting something else in this context:
f: func [arg1 /local dummy] [ v2: get bind (to-word "arg1") (bind? 'dummy) ? v2 ] >> f "goodbye" V2 is a string of value "goodbye" This works in Rebol2, but not Rebol3, unless you use closure:
f: closure [arg1 /local dummy] [ v2: get bind (to-word "arg1") (bind? 'dummy) ? v2 ] >> f "goodbye" V2 is a string of value "goodbye" In the category of mysterious statements about Rebol (for example, “there are no variables, the colon is not an assignment operator”), you can add to “Rebol does not really have a scope”.
Is there a general explanation of the scope in Rebol and Red .
You will need to ask the experts for more details in the chat ...