Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Call-a-function/Clojure/call-a-function-13.clj
Normal file
18
Task/Call-a-function/Clojure/call-a-function-13.clj
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
;; Set up a variable that we will pass to a function
|
||||
(def the-queen {:name "Elizabeth"
|
||||
:title "Your Majesty"
|
||||
:address "Buckingham Palace"
|
||||
:pets ["Corgi" "Horse"]})
|
||||
|
||||
;; A function to modify the data
|
||||
(defn adopt-pet [person pet]
|
||||
"Adds pet to the person's list of pets"
|
||||
(update person
|
||||
:pets
|
||||
#(conj % pet)))
|
||||
|
||||
;; Calling the function returns a new data structure with the modified pets
|
||||
(adopt-pet the-queen "Ferret"); => {:name "Elizabeth":title "Your Majesty" :address "Buckingham Palace" :pets ["Corgi" "Horse" "Ferret]}
|
||||
|
||||
;; The original data structure is not changed
|
||||
the-queen; => {:name "Elizabeth" :title "Your Majesty" :address "Buckingham Palace" :pets ["Corgi" "Horse"]}
|
||||
Loading…
Add table
Add a link
Reference in a new issue