Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when I pass arguments to a Clojure symbol?

If I do this:

('a 'b 'c)

I get this:

c

Why?

like image 748
jes5199 Avatar asked Nov 21 '11 22:11

jes5199


1 Answers

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.

like image 135
nickmbailey Avatar answered Oct 19 '22 04:10

nickmbailey