Search code examples
rebolinfix-operator

Is it possible to define new infix operator in Rebol


I wish something like:

>> op : infix-func [self x] [ 2 * x + self ]
>> 3 op 2
== 7

It is possible?


Solution

  • Not currently possible, no. You can assign an existing operator to a new word in Rebol 3, and that new word will be an infix operator, but you can't make new operators from Rebol code.

    If it did work it would probably currently look like make op! [[self x] [2 * x + self]]

    Partially I think it's really just a matter of no one having gotten around to it. But it's open source now so maybe a concrete implementation proposal could be taken seriously.

    The one caveat would be that the core Rebol evaluator gets a lot of benefit out of avoiding infix. Those few native infix operators were added as an appeasement to help the really basic things you might do like compare for equality look "normal". It's a balance to strike, and to ask whether if you are looking for new infix operators if what you really want is a dialect, lest a "sentence" of Rebol become harder to grok...