Hacker News new | ask | show | jobs
by i_s 3769 days ago
Pretty strange that you put Clojure in the "anything goes" category when it has been the clear leader when it comes to immutability. Lots of those languages you put in the other categories don't even have persistent data structures in their standard library.
1 comments

Here is why: http://pastebin.com/t3Q3CW4j

This is particularly infuriating because the proper way to handle bound variables is already known: https://en.wikipedia.org/wiki/De_Bruijn_index .

No one is maintaining state by constantly clobbering namespace level variables in Clojure, though. What actually comes into play are ways the language and standard library encourages passing data around and manipulating it, which in Clojure is as immutable as you'll find in any language.
Clojure encourages me to program in the REPL, because there is no other way to know what is going on in such a semantically crazy language, other than trial and error.

And the state of the Clojure REPL is as mutable and imperative as it gets, as my paste showed.

You can rebind variables in ghci, too. I certainly wouldn't say this is evidence that Haskell promotes mutable data.
> You can rebind variables in ghci

No, you can't: http://pastebin.com/SdbKM7V7

In ML and Haskell, a new variable might shadow an old one (if they have the same name), but they are still different variables.

Shadowing is slightly harder to implement than rebinding, but it provides a useful guarantee for the user: the meaning of existing definitions remains stable even if new definitions are introduced into the environment.

You are correct. I failed to consider the implications of the different mechanics in the repl. I'm inclined to think the clojure repl is more conducive to experimenting. That is, you can change any part of your program to see what happens. I guess one programmer's sandbox is another programmer's hellish nightmare of mutability. For what it's worth, I would never redefine a var actual code, but I can't say it hasn't been done by others.
Interestingly, Scala handles it http://pastebin.com/CT36K6Hj It feels like an artifact of the REPL tho, as one shouldn't be able to redefine x
Yep, statically typed languages tend to have no option but to handle this right. Otherwise, they risk unsoundness: Consider what would happen if you did `val x = "foo"` instead of `val x = 0`.

But there's still no type-level distinction between immutable and mutable bindings, which is why included Scala in the “anything goes” category.