Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: how is 'set' working ?

From: rebol:techscribe at: 19-Dec-2000 11:09

Hi Sasha, The code fragment you are looking at: "set arg string!" is part of a parser rule, and therefor it is part of the parse dialect. The parse dialect includes a word called "set", which is different from the default "set" function that REBOL normally uses. As a parse rule "set arg string!" means "match data in the parse input stream whose datatype is a string!. Once you accomplish that match, then set the word "arg" to the beginning of the string you found, and then do whatever is contained in the following parentheses (i.e. "(append string arg)"). In contrast, when you enter "set arg string!" at the REBOL prompt you are not using "set" as above (i.e. as defined in the parse dialect), you are instead using the REBOL's set function. The REBOL function set expects a word (or a block containing words), and a value (or a block of values). The set function associates the word with the value. Because you are entering the word at the REBOL console, REBOL will try to evaluate the word arg, before its value is handed over to the set function. Therefore you get the error message. Before the set function was called REBOL discovered that the word arg does not evaluate to anything. Instead you must use the literal word 'arg (as you do in your second example.) Now REBOL evaluates the literal word 'arg, which evaluates to the word arg, and that word (arg) is passed to set as its first argument. When you enter the expression
>> set 'arg string! (append string arg)
you are setting the word arg to the value string!, which is the string datatype designator. Later you append arg to a string. Whenever a value is insert into a string (append uses insert) the value is converted to a string, if it is not already a string. Try
>> print mold head insert "" string!
You will see that the datatype designator string! is converted to the string "string". In your expression you are appending arg, which evaluates to string! to a string, and therefore the string "string" (after conversion) is appended to the value referenced by the word string, which was previously set to "who". Hope this helps, Elan riachtchenko wrote: