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

[REBOL] Re: The evaluation semantics

From: lmecir::mbox::vol::cz at: 3-Sep-2005 23:10

Volker Nitsch napsal(a):
>On 9/3/05, Ladislav Mecir <[lmecir--mbox--vol--cz]> wrote: > >> >>I was curious what is a more expected precedence for unbiased people, >>and it looks, that the expression: >> >> abs -4 + -5 >> >>is rather expected to yield -1 than 9. >> >>Moreover, the evaluation order in Rebol can be called exception-based, >>because in case: >> >> abs -4 + -5 >> >>the operator + takes precedence, while in case >> >> -4 + abs -5 >> >>the function ABS is evaluated as first. These aren't all the evaluation >>exceptions in Rebol, the quantity of evaluation exceptions is quite high. >> >> >> > >To me the number of exceptions is quite low: >Rebol looks at the next two values at the same time. >If you have a value followed by an operator, >it is evaluated first. If it is followed by another value+operator, >these are evaluated left to right. >Else it uses the next value, as we are used too. > > abs -4 + -5 >rebol sees "abs -4". No op, so takes "abs". >Then "-4 +". Operator. >Now it introduces a paren (so to speak). >That gives "abs ( -4 +" >First thing is closing that paren with the -5: > "abs ( -4 + (-5) )" >and that gives 9. > > -4 + abs -5 >rebol sees "-4 +". introducing paren: >"(-4 +". The right side has no more operators, so rebol sees only "abs". >Normal evaluation. "Abs" needs one arg. >There is "-5 end-of-block". No operator. >So "abs -5". That is "joined": >"( -4 + (abs - 5) )" > >As a result, an operator can "steal" an argument from the left >function. Thus with > abs -4 + -5 >the "+" can steal the -4. with > -4 + abs -5 >there is nothing which can be stolen from. > >That is why rebol-conditions sometimes looks "reversed", > if "volker" = ask "your name?" [..] >instead of > if ask "your name?" = "volker" [..] >The "=" cant steal in the second case. >Thus we need to write > if (ask "your name?") = "volker" [..] >and since we are lazy we save that paren. :) > >>-L >> >>-- >>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 >
As I said, there *are* exceptions: abc: func [:x] [abs x] abc -4 + -5 ; == -1 -L