Is pound-quote (hash-quote, #') in Clojure running the resolve and symbol functions?

你离开我真会死。 提交于 2019-11-30 08:38:59

#' is a reader macro that expands to (var foo). What you're doing here is not passing around unevaluated functions, you're passing around vars which contain functions. The reason this works the way it does is because vars are functions that look up their contained value and call it:

user=> (defn foo [x] (+ x 10))
#'user/foo
user=> (#'foo 10)
20
user=> ((var foo) 10)
20

Notice that when I defined the function, a var was returned. It looks like what you've been doing! :)

#' is the reader macro for var. See http://clojure.org/special_forms#var and http://clojure.org/vars

(var foo) returns the var named by the symbol foo, which can hold any kind of value, including functions.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!