[REBOL] Re: Defining new infix operators ?
From: larry:ecotope at: 20-Apr-2001 16:11
Interesting speculation, and there were early statements from RT that the
infix form was translated to prefix by the interpreter before evaluation.
But I think there has been some optimisation along the way that invalidates
models of the behavior. Here is an interesting test (450 MHz PII):
>> t: now/time loop 10'000'000 [3 + 4] now/time - t
>> t: now/time loop 10'000'000 [+ 3 4] now/time - t
>> t: now/time loop 10'000'000 [add 3 4] now/time - t
Notice that "+" used as an infix operator is at least 1.5 times faster than
when used as a prefix operator. The prefix "+" and "add" execute in the same
time. If there were a simple translation from infix to prefix, the infix
form would be slower.
----- Original Message -----
From: "GS Jones" <[gjones05--mail--orion--org]>
Sent: Friday, April 20, 2001 3:38 PM
Subject: [REBOL] Re: Defining new infix operators ?
> Hello, REBOLers !
> Just for a bit of "syntactic sugar" :-) :
> Is it possible to define new infix operators ?
> I tried :
> >> ||: make op! ... etc.
> ** Script Error: Cannot use make on datatype! value
> It would be a very nice feature (a la Prolog, or C++) to define (or
> "overload") some operators.
> Geza Lakner MD
Interesting idea. In fact, I've been pondering the chicken and egg argument
about REBOL in terms of whether the operators are natively prefix or infix.
My guess is that they are defined as prefix, like most of REBOL, and then
REBOL uses a dialect in essence in evaluating expressions as infix.
It is "easy" to define new operators as prefix. For example:
|| 1 2 ; yields 3
I know that this is not quite the syntactic sugar that you're looking for,
but it demonstrates REBOL's flexibility, nonetheless.
Maybe if it's not "top secret", or something, RT can put my mind to rest
over whether the infix notation is just a type of dialect. I.m really
curious about this one.