Avi Drucker / Apr 25 2021 / Published
Remix of Clojure by Nextjournal
Clojure Koans 18 Quote Notebook
{: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
Initial Thoughts
...
;; "Wrap a quote around a list to suppress evaluation"
(= (quote (1 2 3 4 5)) (1 2 3 4 5))
;; skill 18001: wrap a list with the `quote` macro/function (?) instead of prefixing with the single quote
;; question 18002: Where is it beneficial to use `quote` instead of the shortcut single quote?*
;; skill 18002: Create a list data/literal (?) by using the single quote prefix
;; question 18003: What are the considerations (usefulness/benefits/pitfalls/tradeoffs) of/when quoting as well as what (and where) are examples of these?
Clojure
;; "There is a shortcut too!"
(= (quote (1 2 3 4 5)) (1 2 3 4 5))
;; question 18004: Is the "shortcut" referring to the single quote, and if not, then what?
Clojure
;; "You can quote symbols as well as lists... without evaluation!"
(= age (let [age 9] (quote age)))
;; question 18005: Where/when is it useful/beneficial to quote non-lists?
;; question 18006: Since `age` is a local binding, what is `'age` outside of that local scope? An unbound binding?
Clojure
;; "You can use a literal list as a data collection without having Clojure try to call a function"
(= (cons 1 (quote (2 3))) (list 1 2 3) (cons 1 [2 3]))
;; question 18007: Is there a difference between a "literal list" and a "list literal"?
Clojure
;; "The quote affects all of its arguments, not just the top level"
(= (list 1 (+ 2 3)) (1 (+ 2 3)))
;; question 18008: Does the `list` function only affect the top level of its arguments?
;; question 18009: What is an unambiguous (more clear and specific) way of expressing "The single quote prefix macro (?) affects (?) all of its arguments." ?
Clojure
;; "Syntax-quote (`) acts similarly to the normal quote"
(= (list 1 2 3) (1 2 3) (1 2 3))
;; question 18010: How does the syntax-quote (`) differe from the "normal" quote?
;; question 18011: What are the primary use-cases for syntax quoting?
;; question 18012: What are the usefulness/benefits/pitfalls/tradeoffs of syntax-quoting as well as unquoting?
Clojure
;; "Unquote (~) within a syntax-quoted expression lets you mark specific expressions as requiring evaluation"
(= (list 1 5) (1 (+ 2 3)) (1 5))
;; skill 18003: Unquote within a syntax-quoted expression to mark specific expressions to be evaluated with the `~` unquote prefix (macro?)
Clojure
Closing Thoughts
...