3 ms·
Non-Clojure user here (but with just enough Lisp experience to make a fool of themselves)... > When Clojure evaluates the symbol router [(an argument)] here, i
by AceJohnny2 4y ago
Non-Clojure user here (but with just enough Lisp experience to make a fool of themselves)...
> When Clojure evaluates the symbol router [(an argument)] here, it goes through almost the exact same process as it did for the symbol +, but without checking if it’s a special form. It looks for the var in the current namespace that maps to the symbol router, dereferences it, _and saves the function object it retrieves as the first argument before evaluating the second argument_, and then calling the function that run-jetty evaluated to.
Why does it save the resolved function object, which is an argument at that scope? That sounds counter-productive to the reloadable functionality.
Is it a performance optimization?
If anything, it demonstrates that reloadable code is inherently at odds with performance.
- jaccarmac 4y agoNo expert on Clojure semantics, but I'm pretty sure what's being discussed is common to almost all runtime environments. When you pass an argument to a function, the function doesn't keep track of the name of whatever you pass, it keeps track of the thing you pass. (A few languages bind late enough that you are essentially passing names during function invocation, but AFAIK not many.) The difference is that when you redefine a function in Clojure, you're not updating the memory location of the old function but updating the function that a given var (one of Clojure's synchronization primitives) points to. The var quote, then, is roughly the equivalent of passing a pointer, while the naked syntax is roughly like passing a dereferenced pointer. I find the "save" language in TFA a bit confusing.
- AceJohnny2 4y agoThanks, that makes it a bit clearer.