Fork me on GitHub

Howdy 🙂 I am a little confused about the var function aka #' reader macro. In which scenarios do we need to retrieve a var object from a symbol ? I am aware of interning, so there is a map inside each namespaces that maps symbols to Var objects. The way I understand this is that the value from a Var is somehow cached so the evaluator doesn't have to find the value each time it sees a symbol that points to some var. Correct me if I am wrong.


there aren't many reasons that you need the actual var object, unless you're doing metaprogramming


one use case is to get to the var metadata


e.g. (meta #'conj)


a somewhat common "trick" is to use a var as an extra level of indirection for functions that might get redefined, this can be useful during development


(ring-jetty-adapter handler) <--- every time handler gets redefined you need to start and stop jetty, because it will still be using the old version


(ring-jetty-adapter #'handler) <--- now each time ring calls the handler, it does a lookup of the var, so it always uses the most current version of handler


calling a var as a function automatically calls the function inside the var, so this works transparently


it's also useful when you want to use a var as a mutable cell, this isn't very common (most of the time it's better to use an atom). I've mostly seen it used with Component, see the example in the README


Anyone know how to get the Figwheel heads-up display to stay up on error?


@plexus Thank you, now it's clear.