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

Try writing out typical mathematical formula derivations using only s-expressions. I tried for a period and abandoned the persuit. It’s just not comparable to established mathematical notation.


Two solutions. Threading macros wherein instead of nested parens like (x (y (z))) one writes

    ((->> z)
          y
          x)
In clojure there is an interesting package https://github.com/rplevy/swiss-arrows which allows one to perform successive operations with explicit placement of the result of prior evaluation by placing a <> in the form

    ((->> (z <>))
          (y <> 7)
          (x <>))
In practice it seems like there is often less need to do so as many similar functions or the same variety have the same ordering and other options like as-> exist too.

There is also the idea of processing math expressions infix as expected when desired.

https://github.com/rm-hull/infix

    ($= 3 + 5 * 8)
    ; => 43


The Lisp community has literally tried exactly this, on and off, for the past half century -- and they always come back to s-expressions. Every new Lisp programmers says "I know, I'll make a macro to let me write infix math!", and then abandons it 2 months later. It's not like Lisp programmers aren't aware of how schoolchildren write (+ 2 2).

I've written tons of code in both language families. In infix/prefix (i.e., Algol-family) languages, I frequently wish for a nice consistent prefix syntax. In prefix-only (i.e., Lisp-family) languages, I can't say I've ever wished for infix notation.

I don't understand what the perceived issue is with infix notation, except for unfamiliarity -- and that passes soon enough.




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

Search: