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

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

From: larry:ecotope at: 21-Oct-2000 14:35

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
== 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
>> (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 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. Counter example? ----- Original Message ----- From: Gabriele Santilli <[g--santilli--tiscalinet--it]> To: <[rebol-list--rebol--com]> Sent: Saturday, October 21, 2000 4:46 AM Subject: [REBOL] Re: Expression evaluator (an example of parsing blocks) -------snip--------------------