Hacker News new | ask | show | jobs
by catnaroek 3768 days ago
> 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.

1 comments

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.
> I'm inclined to think the clojure repl is more conducive to experimenting.

I'm inclined to think the Clojure REPL is more conducive to flailing around. Now, this might sound like derision, but it isn't intended that way: Flailing around can be a very time-efficient way to familiarize oneself with an unknown domain, especially if the cost of making wrong design decisions is small.

But at some point one has to consolidate what one already has, and, in my experience, Clojure makes this very difficult.

> I guess one programmer's sandbox is another programmer's hellish nightmare of mutability.

If you absolutely want mutable definitions, you can have them in Haskell (with some noise) and ML (with no noise) too: http://pastebin.com/00ScnFxC . So a Haskell or ML programmer always has at their disposal whatever they think is the best tool for the job.

Can I have it the other way around in Clojure?

> Flailing around

Haha, yes. This is how I feel about Matlab, actually. But I suppose Clojure is no different in this respect.

I much prefer the Haskell approach: make dangerous things hard to do. Unfortunately, a majority of programmers consider that to be "unpractical".