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

Defining new infix operators ?

 [1/4] from: geza67::freestart::hu at: 20-Apr-2001 18:41


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 ( la Prolog, or C++) to define (or overload ) some operators. Cheers: Geza Lakner MD

 [2/4] from: gjones05:mail:orion at: 20-Apr-2001 17:38


From: <[geza67--freestart--hu]>
> Hello, REBOLers ! > Just for a bit of "syntactic sugar" :-) :
<<quoted lines omitted: 6>>
> Cheers: > 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: ||: :or || 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. --Scott Jones

 [3/4] from: larry:ecotope at: 20-Apr-2001 16:11


Hi Scott 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 pure models of the behavior. Here is an interesting test (450 MHz PII):
>> t: now/time loop 10'000'000 [3 + 4] now/time - t
== 0:00:08
>> t: now/time loop 10'000'000 [+ 3 4] now/time - t
== 0:00:12
>> t: now/time loop 10'000'000 [add 3 4] now/time - t
== 0:00:12 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. Cheers -Larry ----- Original Message ----- From: "GS Jones" <[gjones05--mail--orion--org]> To: <[rebol-list--rebol--com]> Sent: Friday, April 20, 2001 3:38 PM Subject: [REBOL] Re: Defining new infix operators ? From: <[geza67--freestart--hu]>
> Hello, REBOLers ! > Just for a bit of "syntactic sugar" :-) :
<<quoted lines omitted: 6>>
> Cheers: > 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: ||: :or || 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. --Scott Jones

 [4/4] from: gjones05:mail:orion at: 21-Apr-2001 4:26


> From: <[geza67--freestart--hu]> > > Hello, REBOLers !
<<quoted lines omitted: 12>>
> > 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.
<<quoted lines omitted: 7>>
> curious about this one. > --Scott Jones
From: "Larry Palmiter"
> Hi Scott > > 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
> "pure" models of the behavior. Here is an interesting test (450 MHz PII): > >> t: now/time loop 10'000'000 [3 + 4] now/time - t
<<quoted lines omitted: 4>>
> == 0:00:12 > 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. > > Cheers > -Larry
Most excellent, Larry. That was a clever approach, (it would have been even *more* clever if I had thought of it ;-), and I agree with your conclusion. Now maybe I can sleep again at night knowing that it is infix before prefix (a curious play on words, if I must say so). Thanks. --Scott Jones

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted