Jarzka
Jarzka

Reputation: 773

Evaluate a function in map

Let's say that I have the following map in Clojure:

(def person {:name "Jack" :say-hello #(print "hello")})

Question 1: Is it possible to call the anonymous function of key :say-hello? How?

Question 2 Is it possible to instantiate / clone person vector with different values?

Upvotes: 3

Views: 171

Answers (1)

Dax Fohl
Dax Fohl

Reputation: 10781

(:say-hello person) returns the function, so ((:say-hello person)) calls it.

The function is just a value like all other values, so you can pass it around and create new maps from it.

Upvotes: 9

Related Questions