StructMaps are used for creating structures in Clojure. For
example, if you wanted to create a structure which comprised of an
Employee Name and Employeeid, you can do that with StructMaps.
The following operations are possible in Clojure with regards to StructMaps.
The following operations are possible in Clojure with regards to StructMaps.
S.No. | Operations & Description |
---|---|
1 | defstruct This function is used for defining the structure which is required. |
2 | struct This function is used to define a structure object of the type, which is created by the defstruct operation. |
3 | 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. |
4 | Accessing Individual Fields Individual fields of the structure can be accessed by accessing the keys along with the structure object. |
5 | Immutable Nature By default structures are also immutable, so if we try to change the value of a particular key, it will not change. |
6 | Adding a New Key to the Structure Since structures are immutable, the only way that another key can be added to the structure is via the creation of a new structure. An example on how this can be achieved is shown in the following program. |
No comments:
Post a Comment