Clojure Koans 3 Lists Notebook

This is my third notebook in which I break down the Clojure Koans exercises into answers, skills, and questions.

As always, please note that these notebooks contain spoilers. You have been warned ;)

Initial Thoughts: As my first dialect of LISP, Clojure seems incredibly well suited to handling lists while being itself syntactically made up of lists. I've yet to observe any drawbacks to the consistency and simplicity of the language syntax.

Original Clojure Koans repository is here: https://github.com/functional-koans/clojure-koans/

{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
        ;; complient is used for autocompletion
        ;; add your libs here (and restart the runtime to pick up changes)
        compliment/compliment {:mvn/version "0.3.9"}}}
deps.edn
Extensible Data Notation
{:hello (clojure-version)}
0.1s
Clojure

;; "Lists can be expressed by function or a quoted form"
(= '(1 2 3 4 5) (list 1 2 3 4 5))
;; skill 3001: create a list via "quoted form"
;; skill 3002: create a list via the `list` function and some # of arguments
;; question 3001: Can an empty list be created via `(list)` (ie. call to `list` w/ zero arguments)
0.0s
Clojure
;; "They are Clojure seqs (sequences), so they allow access to the first"
(= 1 (first '(1 2 3 4 5)))
;; question 3002: Is a list in Clojure a sequence? Why or why not?
;; skill 3003: Get the first item/element (?) of a list by using the `first` function
0.0s
Clojure
;; "As well as the rest"
(= '(2 3 4 5) (rest '(1 2 3 4 5)))
;; skill 3004: Get all items of a list except for the first by using the `rest` function
0.0s
Clojure
;; "Count your blessings"
(= 3 (count '(dracula dooku chocula)))
;; skill 3005: Measure the quantity of items in a list using the `count` function
0.0s
Clojure
;; "Before they are gone"
(= 0 (count '()))
0.0s
Clojure
;; "The rest, when nothing is left, is empty"
(= '() (rest '(100)))
0.0s
Clojure
;; "Construction by adding an element to the front is easy"
(= '(:a :b :c :d :e) (cons :a '(:b :c :d :e)))
;; skill 3006: Append an item to the front of a list in Clojure by using the `cons` function. (confirm wording 2021_04_25)
;; question 3003: What are the differences between the `cons` and `conj` functions?
0.0s
Clojure
;; "Conjoining an element to a list isn't hard either"
(= '(:e :a :b :c :d) (conj '(:a :b :c :d) :e))
;; skill 3007: Append an item to the front of a list in Clojure by using the `conj` function (confirm wording 2021_04_25)
0.0s
Clojure
;; "You can use a list like a stack to get the first element"
(= :a (peek '(:a :b :c :d :e)))
;; skill 3008: Inspect/Return the first element of a list by using the stack function `peek`
0.0s
Clojure
;; "Or the others"
(= '(:b :c :d :e) (pop '(:a :b :c :d :e)))
;; skill 3009: Inspect/Return all elements of a list but the first by using the stack function `pop`
0.0s
Clojure
;; "But watch out if you try to pop nothing"
(= "No dice!" (try
                 (pop '())
                 (catch IllegalStateException e
                   "No dice!")))
;; skill 3010: Run code that will throw an exception/error and handle it "gracefully" inside of a "try-catch" block by using `try` and `catch`
0.0s
Clojure
;; "The rest of nothing isn't so strict"
(= '() (try
          (rest '())
          (catch IllegalStateException e
            "No dice!")))
;; question 3004: What is the difference between an error and an exception in Clojure?
;; question 3005: What things in Clojure are identical to Java?
;; question 3006: What things in Clojure are identical to other LISPs?
;; question 3007: What are the primary differences between Clojure and Java?
;; question 3008: What are the primary differences between Clojure and other LISPs?
;; question 3009: What are the top 25 most common "gotchas" in Clojure?
;; question 3010: Conceptually speaking, what do most learners of Clojure struggle with / what are the biggest pain points?
0.1s
Clojure

That's it for today's post :)

If you have any further questions, comments, or suggestions, please leave them as a reply to the Twitter post on my Twitter page @avidrucker

Runtimes (1)