April 26th, 2013
In Technology
No Comments
If you enjoy this article, see the other most popular articles
If you enjoy this article, see the other most popular articles
If you enjoy this article, see the other most popular articles
Clojure is immutable — what this really means
(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.
Here’s the difference:
# python
def foo():
x = 23
y = lambda: x
x = 44
return yprint foo()()
# ruby
def foo():
x = 23
y = lambda { x }
x = 44
yputs foo.call
// javascript
var foo = function(){
var x = 23;
var y = function(){ return x; }
x = 44;
return y;
};
alert( foo()() );; clojure
(defn foo []
(let [x 23
y (fn [] x)
x 44]
y))(println ((foo)))
One of these things is not like the others… one of these things is not the same. (I can’t remember which childhood TV show that’s from).
Three of the snippets above print 44. The other prints 23. That may not seem very significant, but it is. Immutability runs deeper than just unmodifiable vectors and maps.
Post external references
- 1
http://chrisperkins.blogspot.com/2011/04/clojure-does-not-have-variables.html
February 8, 2022 9:33 am
From Michael S on How I recovered from Lyme Disease: I fasted for two weeks, no food, just water
"Did you have Bartonella, too? Seems it uses autogenesis..."