The symbol itself does not hold your function, the Var it names does.
This says "take the contents (@
= deref
) of the Var (resolve
) named by the symbol (symbol
) whose name is "squared"
and apply it (as a function) to the argument 2
:
(@(resolve (symbol "squared")) 2)
This says "take the Var named by the symbol etc.":
((resolve (symbol "squared")) 2)
Both will work, since Vars, when asked to act as a function, defer to the functions stored in them. (If you try to use a Var as a function when it is not bound to a function, an error will result.)
This says "take the symbol named "squared"
and apply it as a function to the argument 2
" -- note that the symbol itself is used as the function:
((symbol "squared") 2)
Now symbols can be used as functions (they implement the clojure.lang.IFn
interface), but the way they act when used in this way is that they look themselves up in their argument, i.e. treat their argument as a map and perform a lookup inside it:
('foo {'foo 2})
; is equivalent to
(get {'foo 2} 'foo)
If the argument passed to a symbol is not something it makes sense to do lookups in, nil
is returned.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…