Clojure - struct-map

This function is used to specifically assign values to key values by explicitly defining which values get assigned to which keys in the structure.


Following is the syntax.

(struct-map structname keyn valuen …. )

Parameters − ‘structname’ is the name to be given to the structure. ‘keyn and valuen’ are the key values which needs to be assigned to the structure.

Return Value − Returns a struct object with the values mapped to the keys of the structure.


An example on how this is used is shown in the following program.

(ns clojure.examples.example
(defn Example []
   (defstruct Employee :EmployeeName :Employeeid)
   (def emp (struct-map Employee :EmployeeName "John" :Employeeid 1))
   (println emp))


The above program produces the following output.

{:EmployeeName John, :Employeeid 1}