h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
311 stars 23 forks source link

Syntactic Sugar for And #40

Closed Immortalin closed 3 years ago

Immortalin commented 5 years ago

Can and be made infix? Postfix and is highly noisy for complex code.

h3rald commented 5 years ago

I understand but this is how postfix languages typically work. What concerns me is that in case of infix notation you'd probably want parenthesis for precedence in logical operators as well, right? and that wouldn't be too easy to implement in this case.

Could you provide some examples of how you'd expect this to work in min?

ceigey commented 4 years ago

I've just been thinking this week about how a stack based language could handle math-friendly syntax without opening up a can of worms, by coincidence saw this issue just now, unfortunately I never came up with any clever solutions...

Apparently some lisp varieties get around the problem with infix macros. E.g. this example for Common Lisp.

In a language without macros, you could perhaps lazily evaluate a quotation for infixes. E.g. as per this example

ls (ftype "file" ==) filter '> sort

would become

ls (ftype == "file") infix filter '> sort

(then something like ls .(ftype == "file") filter '> sort might be possible as shorthand, assuming .(___) isn't taken).

... but that's obviously adding its own sort of noise.

This doesn't address the precedence problem at all though; just seems like a possible hacky way to introduce the functionality without changing how the language is interpreted/compiled.

h3rald commented 3 years ago

Uhhh well, I may have just added an infix-dequote symbol after all: 78dad59

It lets you write things like:

 ((2 + 3) * 5) infix-dequote ;outputs 25

BUT of course it doesn't have any concept of operator precedence:

(2 + 3 * 5) infix-dequote ;still outputs 25

I'd have to teach it that, but I don't think I'll bother (you can use parentheses to clarify precedence anyway).