Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using a Symbol as a function is not the same thing as evaluating it. Symbols-as-functions work the same way as keywords-as-functions. Like this:</p> <pre><code>user=&gt; (declare a) #'user/a user=&gt; (def a-map {'a "value"}) #'user/a-map user=&gt; ('a a-map) "value" user=&gt; </code></pre> <p>This is not how you would normally use a symbol. They are more commonly used for looking up vars in a namespace, and when generating code in a macro.</p> <p>To break down the layers of indirection, let's define "x" as 1 and see what happens:</p> <pre><code>user=&gt; (def x 1) #'user/x </code></pre> <p>Using <code>def</code>, we have created a "var." The name of the var is the symbol user/x. The <code>def</code> special form returns the var itself to the repl, and this is what we can see printed. Let's try and get a hold of that var:</p> <pre><code>user=&gt; #'x #'user/x </code></pre> <p>The <code>#'</code> syntax is a reader macro that says "give me the var referred to by the following symbol." And in our case, that symbol is "x". We got the same var back as before. Vars are pointers to values, and can be dereferenced:</p> <pre><code>user=&gt; (deref #'x) 1 </code></pre> <p>But the var needs to be found before it can be dereferenced. This is where the callability of symbols come into play. A namespace is like a map, where the symbols are keys and vars are the values, and when we plainly name a symbol, we implicitly look up its var in our namespace. Like this:</p> <pre><code>user=&gt; ('x (.getMappings *ns*)) #'user/x </code></pre> <p>Although, in reality, it is probably more like this:</p> <pre><code>user=&gt; (.findInternedVar *ns* 'x) #'user/x </code></pre> <p>And now we have come full circle on the journey of the unquoted symbol:</p> <pre><code>user=&gt; (deref (.findInternedVar *ns* 'x)) 1 user=&gt; x 1 </code></pre> <p>The two are not entirely equal, though. Because the evaluator does this for all symbols, including <code>deref</code> and *ns*.</p> <p>The thing about quoting is that you essentially bypass this whole mechanism, and just get the plain symbol back. Like the <code>#'</code> reader macro get plain vars back, the ` and ' reader macros will get plain symbols back, with or without a namespace qualification respectively:</p> <pre><code>user=&gt; 'x x user=&gt; `x user/x </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload