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,30 +19,30 @@
(define-test function-names
;; In these examples, +, -, *, and / are function names.
(assert-equal ____ (+ 2 3))
(assert-equal ____ (- 1 3))
(assert-equal ____ (* 7 4))
(assert-equal ____ (/ 100 4)))
(assert-equal 5 (+ 2 3))
(assert-equal -2 (- 1 3))
(assert-equal 28 (* 7 4))
(assert-equal 25 (/ 100 4)))
(define-test numberp
;; NUMBERP is a predicate which returns true if its argument is a number.
(assert-equal ____ (numberp 5))
(assert-equal ____ (numberp 2.0))
(assert-equal ____ (numberp "five")))
(assert-equal t (numberp 5))
(assert-equal t (numberp 2.0))
(assert-equal nil (numberp "five")))
(define-test evaluation-order
;; Arguments to a function are evaluated before the function is called.
(assert-equal ____ (* (+ 1 2) (- 13 10))))
(assert-equal 9 (* (+ 1 2) (- 13 10))))
(define-test basic-comparisons
;; The below functions are boolean functions (predicates) that operate on
;; numbers.
(assert-equal ____ (> 25 4))
(assert-equal ____ (< 8 2))
(assert-equal ____ (= 3 3))
(assert-equal ____ (<= 6 (/ 12 2)))
(assert-equal ____ (>= 20 (+ 1 2 3 4 5)))
(assert-equal ____ (/= 15 (+ 4 10))))
(assert-equal t (> 25 4))
(assert-equal nil (< 8 2))
(assert-equal t (= 3 3))
(assert-equal t (<= 6 (/ 12 2)))
(assert-equal t (>= 20 (+ 1 2 3 4 5)))
(assert-equal t (/= 15 (+ 4 10))))
(define-test quote
;; Preceding a list with a quote (') will tell Lisp not to evaluate a list.
@@ -50,17 +50,17 @@
;; the literal list.
;; Evaluating the form (+ 1 2) returns the number 3, but evaluating the form
;; '(+ 1 2) returns the list (+ 1 2).
(assert-equal ____ (+ 1 2))
(assert-equal ____ '(+ 1 2))
(assert-equal ____ (list '+ 1 2))
(assert-equal 3 (+ 1 2))
(assert-equal '(+ 1 2) '(+ 1 2))
(assert-equal '(+ 1 2) (list '+ 1 2))
;; The 'X syntax is syntactic sugar for (QUOTE X).
(true-or-false? ____ (equal '(/ 4 0) (quote (/ 4 0)))))
(true-or-false? t (equal '(/ 4 0) (quote (/ 4 0)))))
(define-test listp
;; LISTP is a predicate which returns true if the argument is a list.
(assert-equal ____ (listp '(1 2 3)))
(assert-equal ____ (listp 100))
(assert-equal ____ (listp "Hello world"))
(assert-equal ____ (listp nil))
(assert-equal ____ (listp (+ 1 2)))
(assert-equal ____ (listp '(+ 1 2))))
(assert-equal t (listp '(1 2 3)))
(assert-equal nil (listp 100))
(assert-equal nil (listp "Hello world"))
(assert-equal t (listp nil))
(assert-equal nil (listp (+ 1 2)))
(assert-equal t (listp '(+ 1 2))))