Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Mathematica has Infix [0], which expresses the adjacency with a ~ (because Mathematica reserves pure blankspace for multiplication). But it works fine to do eg. `"hello"~StringJoin~" world"`; I was always surprised we could only have the predefined operators in many other languages and we couldn't define our own.

This seems like a great attempt. I would be worried about how much parsing and backtracking might be required to infer the infix precedence in a totally general system (like garden-path sentences[1]) or actually ambiguous parse trees (which is cured by adopting some rule like right precedence and parens, but what rule you pick makes some 'natural language' constructions work over others).

[0] https://reference.wolfram.com/language/ref/Infix.html

[1] https://en.wikipedia.org/wiki/Garden-path_sentence



Haskell supports user-defined operators (made up of symbols) and also lets you use functions in infix position by surrounding the name in backticks, e.g.

    2 `plus` 3
rather than

    plus 2 3


In Postgres you can define custom operators via `create operator`[0]

    -- infix
    select a <!!!> b;

    -- prefix
    select <||> a;
A lot of custom types end up using this [1].

    select @-@ '[(0,0),(1,0),(1,1)]'::path;
    -- 2

[0] https://www.postgresql.org/docs/current/sql-createoperator.h... [1] https://www.postgresql.org/docs/current/functions-geometry.h...


Similarly, Agda has a well-typed mixfix operator syntax – you define a function like (_foo_bar_baz) and can automatically write "X foo Y bar Z baz". It does mean that the operator parser has to be extensible at runtime, but it's not a huge cost for a dependently-typed language.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: