String prepend: Difference between revisions

Line 278:
 
=={{header|Clojure}}==
 
<lang clojure>(def s (ref "World"))
===A pure function implementation with immutability ===
<lang clojure>
(defn str-prepend [a-string, to-prepend]
(str to-prepend a-string))
</lang>
 
=== REPL demonstrations with mutability in mind ===
a) with the atom data structure
 
<lang clojure>
(def s (atom "World"))
(swap! s #(str "Hello, " %))
 
user=> @s
user=> "Hello, Wolrd"
</lang>
 
b) with the ref data structure
<lang clojure>
<lang clojure>(def s (ref "World"))
(dosync (alter s #(str "Hello " %)))
 
user=> @s
user=> "Hello World"</lang>
</lang>
 
=={{header|COBOL}}==
Anonymous user