3 ms·
Clojure's Lisp roots make its minimalistic hashes possible. There is a possible reason for separators in a language that doesn't have special syntax for functio
by chc 15y ago
Clojure's Lisp roots make its minimalistic hashes possible. There is a possible reason for separators in a language that doesn't have special syntax for function application (e.g. function calls can be written as "foo bar" rather than "(foo bar)" or "foo(bar)"), but Ruby doesn't take advantage of it. Take this map:
{
foo: capitalize bar,
baz: sanitize quux
}
Without the punctuation, it would be very ambiguous:
{ foo capitalize bar baz sanitize quux }
- rayiner 15y agoI cringe at the thought of whitespace as an infix operator...
- chc 15y agoThat's not really the right way to look at it. Function application is just the default interpretation of two juxtaposed symbols. It's not any worse than "new MyObject()", which has whitespace acting just as much like an infix operator. There's no inherent reason why you'd need a special operator to apply "capitalize" but not "-" or "new" or "def". That's just how C does it, and by an accident of history most mainstream languages just parrot C by default.
- jcromartie 15y agoI don't know about Ruby 1.9, but in 1.8, you can't do (for example): { :foo => rand 40 } It requires parens. So Ruby seems to enforce some limit where it's too ambiguous.