Merge pull request #8 from latacora/revert-5-03_lists

Revert " List Clj is complete"
This commit is contained in:
pfarwick-latacora 2021-06-15 16:48:38 -05:00 committed by GitHub
commit a3da63eedd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,43 +3,43 @@
(meditations
"Lists can be expressed by function or a quoted form"
(= '(1 2 3 4 5) (list 1 2 3 4 5))
(= '(__ __ __ __ __) (list 1 2 3 4 5))
"They are Clojure seqs (sequences), so they allow access to the first"
(= 1 (first '(1 2 3 4 5)))
(= __ (first '(1 2 3 4 5)))
"As well as the rest"
(= '(2 3 4 5)(rest '(1 2 3 4 5)))
(= __ (rest '(1 2 3 4 5)))
"Count your blessings"
(= 3 (count '(dracula dooku chocula)))
(= __ (count '(dracula dooku chocula)))
"Before they are gone"
(= 0 (count '()))
(= __ (count '()))
"The rest, when nothing is left, is empty"
(= () (rest '(100)))
(= __ (rest '(100)))
"Construction by adding an element to the front is easy"
(= '(:a :b :c :d :e) (cons :a '(:b :c :d :e)))
(= __ (cons :a '(:b :c :d :e)))
"Conjoining an element to a list isn't hard either"
(= '(:e :a :b :c :d) (conj '(:a :b :c :d) :e))
(= __ (conj '(:a :b :c :d) :e))
"You can use a list like a stack to get the first element"
(= :a (peek '(:a :b :c :d :e)))
(= __ (peek '(:a :b :c :d :e)))
"Or the others"
(= '(:b :c :d :e)(pop '(:a :b :c :d :e)))
(= __ (pop '(:a :b :c :d :e)))
"But watch out if you try to pop nothing"
(= "No dice!" (try
(= __ (try
(pop '())
(catch IllegalStateException e
"No dice!")))
"The rest of nothing isn't so strict"
(= ()(try
(= __ (try
(rest '())
(catch IllegalStateException e
"No dice!"))))