Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate a function in map

Tags:

clojure

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?

like image 710
Jarzka Avatar asked Sep 26 '26 19:09

Jarzka


1 Answers

(: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.

like image 151
Dax Fohl Avatar answered Sep 29 '26 10:09

Dax Fohl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!