Clojure - struct

This function is used to define a structure object of the type, which is created by the defstruct operation.


Following is the syntax.

(struct structname values)

Parameters − ‘structname’ is the name to be given to the structure. ‘values’ is the values which needs to be assigned to the key values of 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 Employee "John" 1))
   (println emp))


The above program produces the following output.

{:EmployeeName John, :Employeeid 1}

It can be clearly seen that the values supplied in the struct function was assigned to the keys for the Employee object.

Kickstart Your Career

Get certified by completing the course

Get Started