Changes for clojure.core/alter

jafingerhut on Wed, 28 Mar 2012
;; alter is a way to change the value of a reference.

;; Here we're defining a ref named 'names' and setting its value to
;; an empty vector.
user=> (def names (ref []))
#'user/names

;; A function to add a name to the vector (notice the meat's wrapped
;; in a dosync
user=> (defn add-name [name]
         (dosync
           (alter names conj name)))
#'user/add-name

user=> (add-name "zack")
["zack"]

user=> (add-name "shelley")
["zack" "shelley"]

;; Notice that the var 'names' points to the reference that we created
user=> (println names)
#<Ref@658ba380: [zack shelley]>

;; To get the actual value of the ref, you use the '@' symbol, or deref
user=> (println @names)
[zack shelley]

user=> (println (deref names))
[zack shelley]
TimMc on Tue, 08 Feb 2011
;; alter is a way to change the value of a reference.

;; Here we're defining a ref named 'names' and setting its value to
;; an empty vector.
user=> (def names (ref []))
#'user/names

;; A function to add a name to the vector (notice the meat's wrapped
;; in a dosync
user=> (defn add-name [name]
         (dosync
           (alter names conj name)))
#'user/add-name

user=> (add-name "zack")
["zack"]

user=> (add-name "shelley")
["zack" "shelley"]

;; Notice that the var 'names' points to the reference that we created
user=> (println names)
#<Ref@658ba380: [zack shelley]>

;; To get the actual value of the ref, you use the '@' symbol, or deref
user=> (println @names)
[zack shelley]

user=> (println (deref names))
[zack shelley]

zkim on Sun, 18 Jul 2010
;; alter is a way to change the value of a reference.

;; Here we're defining a ref named 'names' and settings it's value to
;; an empty vector.
user=> (def names (ref []))
#'user/names

;; A function to add a name to the vector (notice the meat's wrapped
;; in a dosync
user=> (defn add-name [name]
         (dosync
           (alter names conj name)))
#'user/add-name

user=> (add-name "zack")
["zack"]

user=> (add-name "shelley")
["zack" "shelley"]

;; Notice that the var 'names' points to the reference that we created
user=> (println names)
#<Ref@658ba380: [zack shelley]>

;; To get the actual value of the ref, you use the '@' symbol, or deref
user=> (println @names)
[zack shelley]

user=> (println (deref names))
[zack shelley]

zkim on Sun, 18 Jul 2010
;; Alter is a way to change the value of a reference.

;; Here we're defining the a ref named 'names' and settings it's value to
;; an empty vector.
user=> (def names (ref []))
#'user/names

;; A function to add a name to the vector (notice the meat's wrapped
;; in a dosync
user=> (defn add-name [name]
         (dosync
           (alter names conj name)))
#'user/add-name

user=> (add-name "zack")
["zack"]

user=> (add-name "shelley")
["zack" "shelley"]

;; Notice that the var 'names' points to the reference that we created
user=> (println names)
#<Ref@658ba380: [zack shelley]>

;; To get the actual value of the ref, you use the '@' symbol, or deref
user=> (println @names)
[zack shelley]

user=> (println (deref names))
[zack shelley]

zkim on Sun, 18 Jul 2010
;; Refs are one of Clojure's conncurrency primitives
;; http://clojure.org/refs

;; Here we're defining the a ref named 'names' and settings it's value to
;; an empty vector.
user=> (def names (ref []))
#'user/names

;; A function to add a name to the vector (notice the meat's wrapped
;; in a dosync
user=> (defn add-name [name]
         (dosync
           (alter names conj name)))
#'user/add-name

user=> (add-name "zack")
["zack"]

user=> (add-name "shelley")
["zack" "shelley"]

;; Notice that the var 'names' points to the reference that we created
user=> (println names)
#<Ref@658ba380: [zack shelley]>

;; To get the actual value of the ref, you use the '@' symbol, or deref
user=> (println @names)
[zack shelley]

user=> (println (deref names))
[zack shelley]