I am a total newbie to clojure and trying to follow some tutorials basically. I have a question about defrecords.
Here is the thing that I am trying to do :
(defrecord somemap [key1 key2 key3 key4])
(defn give-me-map [m1 m2]
(somemap. m1 m2))
On the code above, i would like to have key3 and key4 as optional, so that i wont need to give values to them each time a create a somemap object.
there is a similar question here, but it does the reverse of what i am trying to do here.
So the is it possible to define defrecord with optional fields?
When you use
(defrecord T [...]), two factory functions are created:->Tandmap->T.The first uses the positional parameters as keys. The second applies an arbitrary map to the record.
You can keep
key3andkey4in the constructor and usemap->somemap.