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:
> 
> I was wondering how '? (or 'help) can take a word as an input without the
> word or it's function being evaluated first. Rebol evaluates from
> right-to-left as in:
> 
> >> return-string: does [ print "ABC" return " A string! "]
> >> print trim return-string
> ABC
> A string!
> 
> In that example 'return-string is evaluated first (I think), then 'trim,
> then 'print. So what about:
> 
> >> ? return-string
> USAGE:
>     RETURN-STRING
> 
> DESCRIPTION:
>     (undocumented)
> 
> If this followed the same rule as before then the string "ABC" should have
> been printed before the help text. Since '? isn't a native function I
> can't see how it can break the standard convention. I thought
> 
> >> source ?
> 
> ... would provide an answer but the output just confused the hell outta
> me. I have tried to write functions like this in the past but never had
> any success. Clearly my concecpt of the standard convention must be wrong.
> Could somebody clarify it for me in plain english please.
> 
> SpliFF
> 
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to