Hi Russell
Thanks for the corrections. Silly me, I fell into the "negate" trap. I agree
that it would be preferable for REBOL to implement the prefix "-" as a
binary operator, so that it worked like "+", etc. And have the unary "-" be
just no space before a number. IIRC it used to be this way in Core 2.1 or
so. I think there was also some talk at the time of making "+", "*", etc.
work only as infix operators with the prefix versions being "add",
"multiply", etc.
I still wonder if one can always avoid parens with use of both perfix and
infix forms.
Cheers
-Larry
----- Original Message -----
From: Russell Yost <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, October 21, 2000 3:04 PM
Subject: [REBOL] Re: Expression evaluator (an example of parsing blocks)
> I believe Larry has encountered a problem in his first example. See
> inserted comments below:
> Russell [EMAIL PROTECTED]
> ----- Original Message -----
> From: "Larry Palmiter" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> 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
> >
> > Counter example?
> >
> > ----- Original Message -----
> > From: Gabriele Santilli <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Saturday, October 21, 2000 4:46 AM
> > Subject: [REBOL] Re: Expression evaluator (an example of parsing blocks)
> > -------snip--------------------
> >
> > --
> > 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.
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.