zafar.huma
2021-2-20 17:44:02

@zafar.huma has joined the channel


kellysmith12.21
2021-2-20 18:59:30

I’m working on a design for an easy-to-use, extensible way to have infix operators. The infix expressions are macro-rewritten into standard procedure call forms, following the rules for precedence and associativity. That part is straightforward enough, but I am stuck on a question: should there be a way to take into account procedures like +, which normally can take arbitrarily many arguments?

For example, should the infix expression {a + b + c + d} be rewritten as (+ (+ (+ a b) c) d) or as (+ a b c d) ?


sorawee
2021-2-20 22:14:55

I prefer the latter


sorawee
2021-2-20 22:15:31

For the former, you will need to support left assoc and right assoc


sorawee
2021-2-20 22:15:43

And personally I don’t want to deal with that


sorawee
2021-2-20 22:15:54

So I prefer users to specify that explicitly


sorawee
2021-2-20 22:18:03

Another route is to support both :slightly_smiling_face:


sorawee
2021-2-20 22:19:21

For the former and “support both” options, they will require + to contain compile time information about left assoc / right assoc / multi arity.


sorawee
2021-2-20 22:19:36

(or use an external compile-time id table)


sorawee
2021-2-20 22:20:04

That will also mean you can’t have a higher-order operator


kellysmith12.21
2021-2-20 22:31:51

I was already including left and right assoc, as well as precedence. I’m just wondering if the multi arity rule should also be included.


kellysmith12.21
2021-2-20 22:33:39

The way that I’m handling precedence and association is by having the user define an “operator family”, which is a nonextensible set of association and precedence rules for a fixed set of operators.


kellysmith12.21
2021-2-20 22:36:15

The idea is that you could go (define-operator-family arithmetic [* #:left / #:left] [+ #:left - #:left]) then you could write infix arithmetic like {a * b + c / d} which would be rewritten to (+ (* a b) (/ c d))


kellysmith12.21
2021-2-20 22:37:16

The important rule is that an infix expression can only use operators from the same family. And, since families cannot be extended, this means it’s easy to remember how to read an infix expression.


kellysmith12.21
2021-2-20 22:40:26

My intent is that operator families would be defined for things that have an established infix syntax, like arithmetic, boolean algebra, &c.