Clojure - defstruct



This function is used for defining the structure which is required.

Syntax

Following is the syntax.

(defstruct structname keys)

Parameters − ‘structname’ is the name to be given to the structure. ‘keys’ is the keys which needs to be a part of the structure.

Return Value − Returns a structure object.

Example

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

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (println (defstruct Employee :EmployeeName :Employeeid)))
(Example)

Note that the above function is only used to create your structure, we will see more functions which can be used to work with structures.

Output

The above program produces the following output.

#'clojure.examples.example/Employee
clojure_structmaps.htm
Advertisements