Anonymous user
String prepend: Difference between revisions
→{{header|Clojure}}
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>
(dosync (alter s #(str "Hello " %)))
user=> @s
user=> "Hello World"
</lang>
=={{header|COBOL}}==
|