1
votes

I am new at Clojure. I have a map like

{:title "The Little Schemer"
 :authors [friedman , felleisen]}

I want to transform it to:

{:title "The Little Schemer"
 :authors #{friedman , felleisen}}

I attempted like:

(def friedman {:name "Daniel Friedman" :birth-year 1944})
(def felleisen {:name "Matthias Felleisen"})

(defn old-book->new-book [book]
  (set  (:authors book)
        )
  )

(println (old-book->new-book {:title "The Little Schemer"
                              :authors [friedman , felleisen]}))

; => Output: #{{:name Daniel Friedman, :birth-year 1944} {:name Matthias Felleisen}}
; => Expected-Output: #{friedman , felleisen}

Here the defs friedman and felleisen gets executed and there results are getting transformed to set. But, I want the function names to be converted to set instead of their results.

1

1 Answers

1
votes

First of all try to println this:

(println {:title "The Little Schemer"
      :authors [friedman , felleisen]})

The output will be:

{:title The Little Schemer, :authors [{:name Daniel Friedman, :birth-year 1944} {:name Matthias Felleisen}]}

So, what happened here? As You know in this context friedman and felleisen is a variables, so, if You print them - they will be appear in a print message by values. For example:

(def a 1)
(println a)

Will print 1, because of a is just a variable.

The code which you shown here do what You want and when you print it - then values of variable of friedman and felleisen substitute by values.

Your vector of autors((:authors [friedman felleisen])) after disposing the function set will be converted to a set, what we saw from Your output.