Clojure – struct-map

Clojure struct-map

In this guide, we will discuss 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.

Syntax

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.

Example

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

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

Output

The above program produces the following output.

{:EmployeeName John, :Employeeid 1}

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply