Clojure variables are immutable, but with the use of an agent, the storage location can be mutated alongside the use of functions. The changed state of the agent is then returned, as we'll see in the example below.
agent method?The agent method is used to create an agent to handle the mutation of the storage location of a variable.
(agent state)
The agent method receives one parameter, which is the state, as shown above.
The return value of an agent method is an object containing a current state and value.
(ns clojure.examples.example(:gen-class))(defn func [](def names (agent 'chinedu'))(def names (agent 'chioma'))(println names))(func)
func.names variable with the agent method and we set the agent state to chinedu.names variable with the agent method and we set the agent state to chioma.names. Note that the names variable is now chioma instead of chinedu because of the help of the agent method.func.