3 ms·
For me the example printing `1` makes sense because I think `let` as being something immutable, so I wouldn't expect `setv` to mutate that variable (would expec
by m45t3r 4y ago
For me the example printing `1` makes sense because I think `let` as being something immutable, so I wouldn't expect `setv` to mutate that variable (would expect either a compiler error or the introduction of a new local variable).
But maybe it is because I am familiar with Clojure (where `setv` or equivalents doesn't exist) and not other Lisps.
This would be the equivalent Clojure code anyway:
user=> (let [a 1] (defn foo [] (def a 2)) (foo) (println a))
1
nil
So yeah, makes sense for me. But can understand why some other people would expect the other way though.
- gilch 4y agoEquivalent in Common Lisp: * (let ((a 1)) (defun foo () (setq a 2)) (foo) (print a)) 2 2