clojureclojureclr

Clojure: Getting single value and map in structmap


I have a sequence of values that I get from somewhere else, in a known order. I also have one separate value. Both of these I want to put into a struct. I.e.

(defstruct location :name :id :type :visited)

Now I have a list

(list "Name" "Id" "Type")

that is the result of a regexp.

Then I want to put a boolean in :visited; yielding a struct that looks like this:

{:name "Name" :id "Id" :type "Type" :visited true}

How do I do this? I tried various combinations of apply and struct-map. I got as far as:

(apply struct-map location (zipmap [:visited :name :id :type] (cons true (rest match))))

but that may be the wrong way to go about it altogether.


Solution

  • How about:

    (def l (list "Name" "Id" "Type"))
    (defstruct location :name :id :type :visited)
    (assoc
       (apply struct location l)
       :visited true)