What happens when I pass arguments to a Clojure sy

2019-02-21 10:19发布

问题:

If I do this:

('a 'b 'c)

I get this:

c

Why?

回答1:

The link Hauleth posted is a good overview to symbols but the answer to your question is that calling a symbol as a function is equivalent to looking that symbol up in the first argument.

('a 'b)

is equivalent to

(get 'b 'a)

The documentation for get shows that you can pass an optional third argument as the default. In your example 'c is treated as the default and returned since 'b is not a map and 'a can't be found.