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