From bfeaa7cf0757d3248cdede6d5dabf88e576d67b0 Mon Sep 17 00:00:00 2001 From: qc1iu <416521842@qq.com> Date: Mon, 22 Feb 2016 17:32:30 +0800 Subject: [PATCH] Create quote koan Covers - quote - syntax-quote - unquote --- resources/koans.clj | 7 +++++++ src/koans/24_quote.clj | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/koans/24_quote.clj diff --git a/resources/koans.clj b/resources/koans.clj index 1ae5b97..e48d3b8 100644 --- a/resources/koans.clj +++ b/resources/koans.clj @@ -253,4 +253,11 @@ :park "AT&T Park" 'Giants "Giants"]}] + ["24_quote" {"__"[(1 2 3 4 5) + (1 2 3 4 5) + 'age + quote + '(+ 2 3) + 1 2 3 + 1 5]}] ] diff --git a/src/koans/24_quote.clj b/src/koans/24_quote.clj new file mode 100644 index 0000000..8741b51 --- /dev/null +++ b/src/koans/24_quote.clj @@ -0,0 +1,26 @@ +(ns koans.24-quote + (:require [koan-engine.core :refer :all])) + + +(meditations + "use quote to express a list" + (= (quote __) (list 1 2 3 4 5)) + + "Clojure provide a shotcut" + (= (quote __) '(1 2 3 4 5)) + + "The quote special operator prevents its argument from being evaluated at all" + (= __ (let [age 9] (quote age))) + + "You can use a literal list as a data collection without having Clojure try to call a function" + (= (cons 1 (__ (2 3))) (list 1 2 3) (cons 1 [2 3])) + + "Th quote affects all of its argument, not just the top level" + (= (list 1 __) '(1 (+ 2 3))) + + "Syntax-quote has a few extra features that make it ideal for constructing collections to be used as code." + (= (list __ __ __) `(1 2 3) '(1 2 3)) + + "Unquote is used to demarcate specific forms as requiring evaluation by prefixing fhem with the symbol ~ within the body of a syntax-quote" + (= (list __ __) `(1 ~(+ 2 3)) '(1 5)) + )