Mailing List Archive: 49091 messages

## [REBOL] Re: Expression evaluator (an example of parsing blocks)

### From: rryost:home at: 21-Oct-2000 15:04

```
I believe Larry has encountered a problem in  his first example.  See
Russell [rryost--home--com]
----- Original Message -----
From: "Larry Palmiter" <[larry--ecotope--com]>
To: <[rebol-list--rebol--com]>
Sent: Saturday, October 21, 2000 2:35 PM
Subject: [REBOL] Re: Expression evaluator (an example of parsing blocks)

> Hi Gabriele
>
> > How do you write A * B - C * D in REBOL without using parens? You
> > need to use parens or use the notation:
>
> You can do it without parens by mixing infix and prefix forms:
>
> >> - 4 * 5 3 * 4

The following result obtained by Larry is merely the result of 3 * 4; the
result of - 4 * 5 (-20) has been discarded.
20 - 12 should give 8 as a result.

> == 12
>
> I looked for a more complex example and noted that even with parens, the
> result from REBOL may be surprising, because of the way the interpreter
> evaluates parens.
>
> >> - (4 * 5) ((3 * 4) + (2 * 3))
> == 18                                    ; not the naive expected result

Again, - (4 * 5) {-20} has been discarded; 18 is the result of the following
operation, ((3 * 4) + (2 * 3))

> >> (4 * 5) - ((3 * 4) + (2 * 3))
> == 2                                      ; the expected result
>
> But I found a way to do this without parens (readability becoming an
issue)
> >> + - + 3 * 4 2 * 3 4 * 5
> == 2
>
> This is kind of fun, eh?
>
> Regards
> -Larry

In REBOL, - 12 8 simply negates 12 and discards it, returning 8.  REBOL
defines '-, in the absence of a preceding value, as a unitary (single
operand) operator that negates the following value. I fail to see the
utility of this, and would prefer '- to work like '+ on two following
arguments.  But that's the way it is!

> PS I suspect it can be shown that with suitable rearrangement of terms and
> with both infix and prefix forms available, that parens are not needed.

As Gabriele and I  showed with   subtract 3 * 4 5 * 6
```