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

[REBOL] Re: series issues

From: joel::neely::fedex::com at: 1-Oct-2001 14:20

I'm not totally sure what the question(s) is(are), but I'll try... mgkiourt wrote:
> Could you please elucidate the followingcode > A. do["hello"]=="hello" > do[print "hello"]==hello > do "1"+"2"==3 >
DO applied to a block causes all expressions in the block to be evaluated, with the value of the last expression serving as the value of the entire DO [...] expression.
>> do ["hello"]
== "hello" Simply evaluating a string produces the string itself. The double equal sign printed by the interpreter ("==") indicates that the following output is the value of an expression.
>> do [print "hello"]
hello The result of printing a string is that the string show up in the output (console window, in this case). The absence of a double equal is a clue that we're looking at *output* (a side effect of PRINT) rather than a value. Since PRINT has no resulting value (it is UNSET) there's no double equal at all.
>> do "1" + "2"
** Script Error: Cannot use add on string! value ** Where: halt-view ** Near: do "1" + "2"
>> do "1"+"2"
** Script Error: Cannot use add on string! value ** Where: halt-view ** Near: do "1" + "2" None of these are legal REBOL syntax.
>> do "1 + 2"
== 3
The value of DO applied to a string is obtained by LOADing the string (converting it to an internal REBOL structure) and then applying DO to that structure.
>> load "1 + 2"
== [1 + 2 ] LOADing the string "1 + 2" creates a block containing the expression 1 + 2 which evaluates to 3 when DOne.
> B.>>set[number num ten]10 > ==10 > >>print [number num ten] > 10 10 10 > >>set[one two three][1 2 3] > >>print three > 3 > 3 > >>print[one two three] > 1 2 3 >
When you give SET a block as its first argument, and a single (non-block) value as the second argument, it SETs all words in the first block to the same value (the second argument). In your first expression set [number num ten] 10 all three words were set to the integer value ten. When you give SET two blocks, the words in the first block are set to the corresponding values from the second block. HTH! -jn- -- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com