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

[REBOL] Re: ?

From: rebol:techscribe at: 10-Jan-2001 21:38

Hi SpliFF, 1. Try
>> print 1 print 2 print 3
You'll get 1 2 3 which goes to show that - as a rule - REBOL evaluates from left to right, unless instructed to do otherwise. "Instructed to do otherwise" is a little cryptic, so here goes:
>> return-string: does [print "ABC" return " A string! "] >> print trim return-string
Left to right: First print is evaluated. The word print evaluates to a function that expects an argument. Aha. Let's fetch an argument for print, otherwise we cannot complete the evaluation. The next token in the input stream is the word trim. Now trim is evaluated. Hey, it's also a function, and the trim function also requires an argument. This argument must be a string. Let's look at the next token. The word return-string is evaluated. Oh my, it's also a function. Let's evaluate that function. The return-string function is now evaluated. During the evaluation of the return-string function first the string ABC is printed, because the function is being evaluated from left to right, and then return is evaluated, which is a function (actually a value of type native!) that requires an argument of type any-type! (any-type! includes the type unset! which is represented by no value, i.e. f: does [return] - return here with no argument - is legal) that returns the string " A string! ". (BTW, you do not *have* to use return here, since the last value of a block is returned by default, i.e. f: does [return "this"] is works the same as f: does ["this"]). trim is passed " A string! " as its argument, it is successfullly evaluated, and the result of evaluating it is passed to print. Regarding ? using help would be more useful in your case. You will see that ? is a function that expects a literal word ('word) as its argument. When ? is evaluated REBOL looks attempt to interpret the next token in the input stream as a word, and does not evaluate that word, because ? wants a literal word, i.e. the word itself, and not its value. So return-string is not evaluated, instead the literal word return-string is passed to ?. Hope this helps, Elan SpliFF wrote: