This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-24
Channels
- # beginners (13)
- # cider (1)
- # cljsrn (2)
- # clojars (5)
- # clojure (110)
- # clojure-czech (1)
- # clojure-dusseldorf (3)
- # clojure-japan (1)
- # clojure-spec (39)
- # clojurescript (13)
- # cloverage (2)
- # cursive (2)
- # defnpodcast (4)
- # lein-figwheel (7)
- # off-topic (1)
- # om (38)
- # om-next (4)
- # perun (1)
- # planck (3)
- # reactive (8)
- # rethinkdb (1)
- # ring-swagger (1)
- # specter (17)
- # vim (1)
- # yada (4)
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
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