atom
?In Clojure, all variables are immutable except for the agent
and atom
, which are methods that allow variables to change their state. An atom in Clojure is a datatype that handles the sharing and synchronizing of the Clojure independent state as Clojure data structures are immutable.
reset
method?The reset
method updates the value of an atom
without considering the old one.
(reset! nameofAtom value)
From the syntax above, we can see that the reset
method uses two parameters:
nameofAtom
: The atom
we want to update.value
: The new value of the atom.The reset
method returns atom
with a new value.
Let's see an example:
(ns clojure.examples.example(:gen-class))(defn func [](def atomm (atom 1))(println @atomm)(reset! atomm 2)(println @atomm))(func)
func.
atomm
to 1
using an atom.
atomm.
reset
method to change the value to 2.
atomm.
func.