Clojure – Reference Values

Clojure reference values

In this guide, we will discuss Clojure Reference Values. Reference values are another way Clojure can work with the demand to have mutable variables. Clojure provides mutable data types such as atoms, agents, and reference types.

Following are the operations available for reference values.

Sr.No.Operations & Description
1ref
This is used to create a reference value. When creating a reference value, there is an option to provide a validator function, which will validate the value created.
2ref-set
This function is used to set the value of a reference to a new value irrespective of whatever is the older value.
3alter
This function is used to alter the value of a reference type but in a safe manner. This is run in a thread, which cannot be accessed by another process.
4dosync
Runs the expression (in an implicit do) in a transaction that encompasses expression and any nested calls.
5commute
Commute is also used to change the value of a reference type just like alter and ref-set.

Next Topic : Click Here

This Post Has One Comment

Leave a Reply