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

I should have said simple math and boolean logic.

Of course 1 + 2 * 3 is more familiar that way, vs the Lisp way. But you have the Lisp way wrong (unless your example was Smalltalk)... it would be:

    (+ 1 (* 2 3))
Which could be read left-to-right as "sum 1 and the product of 2 and 3".

Also, most math functions in Lisp are variadic. So if you have this in infix:

    x + y + z + 1
    // x plus y plus z plus one
You could do it in Lisp as:

    (+ x y z 1)
    ;; sum x y z and one
There are plenty of cases where an algorithm is naturally expressed as a map or a reduce, where infix or prefix has nothing to do with it. I don't find myself using a lot of the kind of math that would be better in infix.

It might even be useful to give math operators new names in Lisp, because of the way that things like < > = == are a bit awkward when read as their equivalents in infix. They are all variadic, after all.

Compare:

    (x == 10 && y == 10) && (x < y && y < z && z < 100)
Vs.

    (and (== x y 10) (< x y z 100))
That's already an improvement, but the reading is strange. So what if we alias those operators?

    (all-true? (same? x y 10) (ascending? x y z 100))
I don't know if I'd actually use those names, and I don't think I would do this in code, but you get the point. You can even tell how a list of numbers is sorted in Lisp by simply doing:

    (apply < nums)


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

Search: