Clojure is trying to resolve empid
and can't, so it returns an error.
Clojure allows you to define maps with most anything as a key. This includes keywords and strings, which are very common, but also symbols, functions, numbers, data structures such as vectors and other maps, and more.
Your example contains one valid mapping, that is, the function bound to name
which maps to the string "Srini". However, the other mapping is invalid because empid
is not bound to anything.
The most common case is to use keywords for your keys, which have a particular advantage of allowing the values to be accessed via the keywords in a safe (non-NullPointerException
-causing) way:
(:name {:name "Srini" :empid 10000})
=> "Srini"
So, while there may be a case where you'd want to map a function to something, this is clearly not the right way for you here. (as an aside, strings as keywords are particularly useful when reading from a file or database where the data is already a string and there's no advantage to converting to and from a keyword.
name
is a clojure function from core. you want keywords all the way in your maps. – cfrick(let [{flower1 :flower1 flower2 :flower2} {:flower1 "red" :flower2 "blue"}] (str "The flowers are " flower1 " and " flower2))
– Srini