Hacker News new | past | comments | ask | show | jobs | submit login

What are the practical differences between special vars in Lisp and dynamic vars in Clojure? The obvious ones are that `def ^:dynamic` can't be local to a function, and that Clojure uses a separate form, `binding`, rather than `let`, to set their values.



For me the largest difference is that Clojure carries over all your dynamic bindings when creating new threads (via 'future') and in lazy seqs, whereas Common Lisp (typically) does not. I now understand why they choose to do it this way, but I wish the documentation was much clearer in this regards.


The CL standard doesn't deal with threads at all, so different implementations do things differently. But typically the user can control what the initial bindings of a thread are through keyword arguments to whatever function spawns threads.


I made a dialect once called VoqLisp in which a thread carried the dynamic bindings visible in the code which spawned it.

This then resembled POSIX environment variables: "FOO=bar command arg" and was handy in a similar way. You could use let to set up a bunch of parameters affecting the thread, and then create it in that body.


ANSI CL in fact uses the term "dynamic variable". The "special" aspect of a d. v. is the marking of a symbol itself for binding dynamically, rather than lexically. I.e. special treatment applies to it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: