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

I don't think this has anything to do with infix versus prefix. It works in Lisp because the reader knows (roughly speaking) that symbols are terminated by whitespace or parentheses.

If you wrote a version of Ruby that was still infix but where you needed to put spaces around all symbols, then "foo-bar" would work fine there, too.

You are echoing Avdi’s point. I understand it, I just happen to disagree with it. If Lisp was an infix language, then yes foo-bar would mean something different to the parser than foo - bar because of the whitespace.

But what’s also at stake is whether that language would be readable to humans without mistakes. Part of what makes Lisp work, IMO, is that you never try to type foo - bar, so you never run into an accident by mistakenly typing foo-bar and having the parser think you meant a hitherto undefined symbol.

Whether that’s a worthy tradeoff is a matter of opinion, and I’ll take Avdi’s word for it that he believes the benefits of calling symbols foo-bar outweigh the odd time you might type the wrong thing. I’m just pointing out in addition to the “whitespace is the separator” argument you both make, there’s also the “foo - bar doesn’t mean foo subtract bar” argument.

Except that in Lisp "-number" is totally different than "- number" and I rarely have to worry about it when I code in Lisp. I code in both Lisp and Ruby on a regular basis, and I don't see the ability to write "x-y" as any real advantage. I already separate my tokens with white space by default because I see "x-y" as a single token.

"you never try to type foo - bar"

Unless you have a function called "foo", and you want to pass it the subtraction function as it's first parameter and the value "bar" as its second. In which case (foo - bar) is perfectly valid, reasonable, and completely different from (foo-bar).

Even though Lisp is not an infix language, foo-bar does mean something different to the parser than foo - bar because of whitespace.

I know that, but it’s highly incidental to my point, as I’m sure you’re aware. It’s obviously true that (foo - bar) is legal, as is (foo-bar), as is (foo - bar + bash), as is (foo-bar + bash) and so on, but they’re still much less likely to be mistaken for foo-bar in an infix language.

I’m sure you knew perfectly well that I meant you never type foo - bar meaning foo subtract bar :-)

Such rules ("all operators must be space-hugged") are special cases, and I think raganwald's point is that such special cases make at-a-glance mental parsing more difficult. Lexing and parsing in Lisp is much more straightforward than in, say, Python. Hence, mental lexing and parsing has fewer barriers. This is a direct result of using s-expressions, which implies no in-fix operators.

It is a special case in other languages, in lisp it is one of a very few highly consistent rules

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact