learning koans

- refreshed understanding of lexical vs. dynamic binding
  https://gigamonkeys.com/book/variables.html
- was taught CASE as simpler variant of COND
This commit is contained in:
efim
2022-07-24 13:18:22 +00:00
parent 49c00c24ee
commit fd03924c10
7 changed files with 116 additions and 110 deletions

View File

@@ -19,25 +19,25 @@
(define-test list-or-atom
;; The function LISTP will return true if the input is a list.
;; The function ATOM will return true if the input is an atom.
(true-or-false? ____ (listp '(1 2 3)))
(true-or-false? ____ (atom '(1 2 3)))
(true-or-false? ____ (listp '("heres" "some" "strings")))
(true-or-false? ____ (atom '("heres" "some" "strings")))
(true-or-false? ____ (listp "a string"))
(true-or-false? ____ (atom "a string"))
(true-or-false? ____ (listp 2))
(true-or-false? ____ (atom 2))
(true-or-false? ____ (listp '(("first" "list") ("second" "list"))))
(true-or-false? ____ (atom '(("first" "list") ("second" "list")))))
(true-or-false? t (listp '(1 2 3)))
(true-or-false? nil (atom '(1 2 3)))
(true-or-false? t (listp '("heres" "some" "strings")))
(true-or-false? nil (atom '("heres" "some" "strings")))
(true-or-false? nil (listp "a string"))
(true-or-false? t (atom "a string"))
(true-or-false? nil (listp 2))
(true-or-false? t (atom 2))
(true-or-false? t (listp '(("first" "list") ("second" "list"))))
(true-or-false? nil (atom '(("first" "list") ("second" "list")))))
(define-test the-duality-of-nil
;; The empty list, NIL, is unique in that it is both a list and an atom.
(true-or-false? ____ (listp nil))
(true-or-false? ____ (atom nil)))
(true-or-false? t (listp nil))
(true-or-false? t (atom nil)))
(define-test keywords
;; Symbols like :HELLO or :LIKE-THIS are keywords. They are treated
;; differently in Lisp: they are constants that always evaluate to themselves.
(true-or-false? ____ (equal :this-is-a-keyword :this-is-a-keyword))
(true-or-false? ____ (equal :this-is-a-keyword ':this-is-a-keyword))
(true-or-false? ____ (equal :this-is-a-keyword :this-is-also-a-keyword)))
(true-or-false? t (equal :this-is-a-keyword :this-is-a-keyword))
(true-or-false? t (equal :this-is-a-keyword ':this-is-a-keyword))
(true-or-false? nil (equal :this-is-a-keyword :this-is-also-a-keyword)))