Clojure – Atoms reset!

Clojure Atoms reset!

In this guide, we will discuss Clojure Atoms reset! Sets the value of atom to a new value without regard for the current value.

Syntax

Following is the syntax.

(reset! atom-name newvalue)

Parameters − ‘atom-name’ is the name of the atom whose value needs to be reset.‘newvalue’ is the new value, which needs to be assigned to the atom.

Return Value − The atom with the new value set.

Example

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

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (def myatom (atom 1))
   (println @myatom)
   
   (reset! myatom 2)
   (println @myatom))
(example)

Output

The above program produces the following output.

1
2

Next Topic : Click Here

This Post Has One Comment

Leave a Reply