Fork me on GitHub
#beginners
<
2016-09-24
>
smnplk03:09:03

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.

plexus06:09:01

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

plexus06:09:49

one use case is to get to the var metadata

plexus06:09:09

e.g. (meta #'conj)

plexus06:09:10

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

plexus06:09:03

(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

plexus06:09:02

(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

plexus06:09:31

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

plexus06:09:01

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

mudphone07:09:50

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

smnplk14:09:02

@plexus Thank you, now it's clear.