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

后端 未结 2 611
青春惊慌失措
青春惊慌失措 2020-12-31 04:21

Perhaps you can help me find this in the docs. I\'m using pound-quote to be able to pass around unevaluated function names prior to execution. For example:

(         


        
2条回答
  •  太阳男子
    2020-12-31 04:48

    #' 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! :)

提交回复
热议问题