On 9/3/05, Ladislav Mecir <[EMAIL PROTECTED]> wrote: >=20 > I was curious what is a more expected precedence for unbiased people, > and it looks, that the expression: >=20 > abs -4 + -5 >=20 > is rather expected to yield -1 than 9. >=20 > Moreover, the evaluation order in Rebol can be called exception-based, > because in case: >=20 > abs -4 + -5 >=20 > the operator + takes precedence, while in case >=20 > -4 + abs -5 >=20 > the function ABS is evaluated as first. These aren't all the evaluation > exceptions in Rebol, the quantity of evaluation exceptions is quite high. >=20
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".=20 Normal evaluation. "Abs" needs one arg.=20 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" =3D ask "your name?" [..] instead of if ask "your name?" =3D "volker" [..] The "=3D" cant steal in the second case.=20 Thus we need to write if (ask "your name?") =3D "volker" [..] and since we are lazy we save that paren. :) > -L >=20 > -- > To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject. >=20 >=20 --=20 -Volker "Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem." David Wheeler -- To unsubscribe from the list, just send an email to lists at rebol.com with unsubscribe as the subject.
