Hacker News new | past | comments | ask | show | jobs | submit login

I think that VSO confusion arises only when there is a single subject and verb.

Take for example a common prefix notation: (< a b c d) this stands for "are all increasing?"

Since none are really the subject, most Java-like languages (if they had this at all) would have to invent a subject Integer.areIncreasing(myList). No longer does this give you a valuable subject, just a made up subject.

Certainly some operations (mostly arithmetic) are easier on the eyes since we've had a lot of practice with it.

Whenever I do arithmetic, I use threading macros to make it easier to read. Suddenly, it reads like infix, but with more flexibility.

(+ 4 (- 1 (/ 4 2))) ;; what?!

becomes

(_> 4 (/ _ 2) (- 1 _) (+ 4)) ;; ah

In infix, it would be:

(1 - (4 / 2)) + 4

The threading macro isn't quite as nice as the default infix, but it allows for both notations.

I think the second reads very well all things considered, start with 4, divide by 2, subtract from 1, add 4. (_ is the placeholder).




That's really interesting. I can't say that I, personally, find it easier to read than the rather plain polish notation of the first example. I find I have to work really hard to connect the _s together and I find this process unpleasant. Maybe it's just an artefact of not finding bare lisp in general all that appealing.

Re your example with <, the 'natural' object oriented way to do this to me would be to treat the list itself as the subject. [a,b,c,d].isOrdered() say. To the fact that doing it this way in java would be incredibly ugly, I'll only say that I'm not even remotely a fan of java or, for that matter, C++/Java/C#-style static-typed object-orientation.


The threading macro idea is meant to just make it easier for humans to read, so if it's not easier for you, no sense bothering with it. In such, it's not a true prefix vs infix tool, just a tool possible in languages with macros.

As to the are increasing, yes, I suppose the list itself would be a more natural subject.

This is why I love macros, not really infix or prefix specifically, because a macro makes it trivial to just have this:

(. [1 2 3 4].isOrdered)

turn into this:

(isOrdered [1 2 3 4])

That way both the human and the compiler get their preferred view.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: