[Newbie]: Problems with lit-words
[1/5] from: brasilv:tin:it at: 27-Oct-2005 11:34
Hi everybody! I know it can sound a bit silly, but I'm going crazy trying to understand how exactly work litteral words. If I write:
>> a: 'b
== b So :
== b Suppose b has not yet a value:
** Script Error: b has no value ** Where: halt-view ** Near: b Now if I do this:
>> set a ""
== "" Why if I make this:
== "" I've this results? Why b got the value set for a? And a is still b? Please let me understand, I'm totally stuck! Thank you, Silvia
[2/5] from: gabriele:colellachiara at: 27-Oct-2005 11:54
Hi Silvia, On Thursday, October 27, 2005, 11:34:24 AM, you wrote: SB> Now if I do this:
>>> set a ""
SB> == "" SB> Why if I make this:
SB> == b
SB> == "" SB> I've this results? Why b got the value set for a? And a is still b? Let me try with an example.
>> my-set: func [word value] [?? word ?? value] >> a: 'b
>> my-set a ""
word: b value: "" == ""
>> my-set 'a ""
word: a value: "" == "" As you can see, the actual arguments you are passing to SET are B and "", so it sets B to "". SET does not even see A; that's because arguments are evaluated, and A's value is B. If you want to pass A, instead of the value of A, you need to use 'A. This is the same thing that happens when you write something like:
>> my-set 'a 1 + 1
word: a value: 2 == 2 The function does not see "1 + 1", it gets the result of evaluating "1 + 1"; in the same way, you don't get A above, but the result of evaluating A, which is B. Hope this makes things a little bit clearer... Regards, Gabriele. -- Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/ Colella Chiara software division --- http://www.colellachiara.com/
[3/5] from: volker::nitsch::gmail::com at: 27-Oct-2005 12:23
On 10/27/05, Silvia Brandimarte <brasilv-tin.it> wrote:
> Hi everybody! > I know it can sound a bit silly, but I'm going crazy trying to understand
<<quoted lines omitted: 5>>> >> a > == b
Right. When a lit-word is directly in code, it it transformed in a normal word. (Its not if you get it from a block, !> first ['b] == 'b )
> Suppose b has not yet a value: > >> b
<<quoted lines omitted: 10>>> == "" > I've this results? Why b got the value set for a? And a is still b?
because it is the same as set 'b "" set wants a word to put something in. In my example 'b is transformed to a normal word, "set" gets b and puts "" in. In your example "b" is fetched from "a", "set" gets b and puts "" in. Thats what you see.
> > Please let me understand, I'm totally stuck! > > Thank you, Silvia > > -- > To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject. >
-- -Volker Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem. David Wheeler
[4/5] from: carlos:lorenz::gmail at: 27-Oct-2005 10:27
Gabriele, These considerations about lit words were really clarifying to me also Thank you 2005/10/27, Gabriele Santilli <gabriele-colellachiara.com>:
> Hi Silvia, > On Thursday, October 27, 2005, 11:34:24 AM, you wrote:
<<quoted lines omitted: 40>>> To unsubscribe from the list, just send an email to > lists at rebol.com <http://rebol.com> with unsubscribe as the subject.
-- *:-.,_,.-:*'``'*:-.,_,.-: Carlos Lorenz *:-.,_,.-:*'``'*:-.,_,.-:
[5/5] from: antonr::lexicon::net at: 28-Oct-2005 15:02
Hi Silvia, Your expression: set a "" is evaluated like this, (using parens to indicate current focus): (set) a "" ; I am a word SET, my value is a function, so let's do it. ; This function expects two arguments, so let's get them first: set (a) "" ; I am a word A, my value is a word B, so let's return B. set a ("") ; I am a string, my value is myself, so let's return that. ; Now SET has all the arguments it needs, so it is done. So the above is as if you typed: set 'b "" which is evaluated like this: (set) 'b "" set ('b) "" ; lit-word 'B evaluates to the word B. set 'b ("") So the overall problem, I think, is that you are expecting the SET function to take its WORD argument literally. What actually happens is that the rebol interpreter reduces A before SET gets to even look at it. If you did: print a you might think it is PRINT which reduces A to its value, but, in fact, A is reduced by the interpreter *before* it is passed to PRINT. The way I think about literal words, words and values is like this. lit-word -> word -> value where "->" means "reduces to", and automatic evaluation usually means moving one step to the right is very easy. So, in your case: 'b (lit-word) -> b (word) -> "" (value) and, you have also set A's value to the word B: a (word) -> b (word) -> "" (value) Anton.
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted