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:
@@ -14,39 +14,39 @@
|
||||
|
||||
(define-test t-and-nil-are-opposites
|
||||
;; NOT is a function which returns the boolean opposite of its argument.
|
||||
(true-or-false? ____ (not nil))
|
||||
(true-or-false? ____ (not t)))
|
||||
(true-or-false? t (not nil))
|
||||
(true-or-false? nil (not t)))
|
||||
|
||||
(define-test nil-and-empty-list-are-the-same-thing
|
||||
;; In Common Lisp, NIL is also the empty list.
|
||||
(true-or-false? ____ '())
|
||||
(true-or-false? ____ (not '())))
|
||||
(true-or-false? NIL '())
|
||||
(true-or-false? t (not '())))
|
||||
|
||||
(define-test in-lisp-many-things-are-true
|
||||
;; In Common Lisp, the canonical values for truth is T.
|
||||
;; However, everything that is non-NIL is true, too.
|
||||
(true-or-false? ____ 5)
|
||||
(true-or-false? ____ (not 5))
|
||||
(true-or-false? ____ "a string")
|
||||
(true-or-false? t 5)
|
||||
(true-or-false? nil (not 5))
|
||||
(true-or-false? t "a string")
|
||||
;; Even an empty string...
|
||||
(true-or-false? ____ "")
|
||||
(true-or-false? t "")
|
||||
;; ...or a list containing a NIL...
|
||||
(true-or-false? ____ (list nil))
|
||||
(true-or-false? t (list nil))
|
||||
;; ...or an array with no elements...
|
||||
(true-or-false? ____ (make-array 0))
|
||||
(true-or-false? t (make-array 0))
|
||||
;; ...or the number zero.
|
||||
(true-or-false? ____ 0))
|
||||
(true-or-false? t 0))
|
||||
|
||||
(define-test and
|
||||
;; The logical operator AND can take multiple arguments.
|
||||
(true-or-false? ____ (and t t t t t))
|
||||
(true-or-false? ____ (and t t nil t t))
|
||||
(true-or-false? t (and t t t t t))
|
||||
(true-or-false? nil (and t t nil t t))
|
||||
;; If all values passed to AND are true, it returns the last value.
|
||||
(assert-equal ____ (and t t t t t 5)))
|
||||
(assert-equal 5 (and t t t t t 5)))
|
||||
|
||||
(define-test or
|
||||
;; The logical operator OR can also take multiple arguments.
|
||||
(true-or-false? ____ (or nil nil nil t nil))
|
||||
(true-or-false? t (or nil nil nil t nil))
|
||||
;; OR returns the first non-NIL value it encounters, or NIL if there are none.
|
||||
(assert-equal ____ (or nil nil nil))
|
||||
(assert-equal ____ (or 1 2 3 4 5)))
|
||||
(assert-equal nil (or nil nil nil))
|
||||
(assert-equal 1 (or 1 2 3 4 5)))
|
||||
|
||||
Reference in New Issue
Block a user