Bladeren bron

Complete first 10 lessons

Lily Carpenter 9 jaren geleden
bovenliggende
commit
77eb3e0695
10 gewijzigde bestanden met toevoegingen van 175 en 174 verwijderingen
  1. 13 13
      koans/arrays.lsp
  2. 7 9
      koans/asserts.lsp
  3. 14 14
      koans/atoms-vs-lists.lsp
  4. 44 44
      koans/equality-distinctions.lsp
  5. 18 18
      koans/evaluation.lsp
  6. 24 24
      koans/lists.lsp
  7. 5 5
      koans/multiple-values.lsp
  8. 17 17
      koans/nil-false-empty.lsp
  9. 23 18
      koans/special-forms.lsp
  10. 10 12
      koans/vectors.lsp

+ 13 - 13
koans/arrays.lsp

@@ -15,7 +15,6 @@
15 15
 
16 16
 ;; see http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node157.html
17 17
 
18
-
19 18
 (define-test test-basic-array-stuff
20 19
     " the first block of code defines an 8x8 array, then fills
21 20
       the elements with a checkerboard pattern"
@@ -26,20 +25,21 @@
26 25
       (dotimes (y 8)
27 26
         (if (evenp (+ x y))
28 27
             (setf (aref chess-board x y) :black)
29
-            (setf (aref chess-board x y) :white)
30
-            )))
28
+            (setf (aref chess-board x y) :white))))
31 29
     (assert-true (typep chess-board 'array))
32
-    (assert-equal (aref chess-board 0 0) ___)
33
-    (assert-equal (aref chess-board 2 3) ___)
30
+    (assert-equal (aref chess-board 0 0) :black)
31
+    (assert-equal (aref chess-board 2 3) :white)
34 32
     "array-rank returns the number of dimensions of the array"
35
-    (assert-equal ___ (array-rank chess-board))
33
+    (assert-equal 2 (array-rank chess-board))
36 34
     "array-dimensions returns a list of the cardinality of the array dims"
37
-    (assert-equal ___ (array-dimensions chess-board))
38
-    (assert-equal ___ (array-total-size chess-board))))
35
+    (assert-equal '(8 8) (array-dimensions chess-board))
36
+    (assert-equal 64 (array-total-size chess-board))))
39 37
 
40 38
 (define-test test-make-your-own-array
41 39
     "make your own array that meets the specifications below."
42
-  (let ((color-cube nil))
40
+  (let ((color-cube (make-array '(3 3 3))))
41
+    (setf (aref color-cube 0 1 2) :red)
42
+    (setf (aref color-cube 2 1 0) :white)
43 43
     "you may need to modify your array after you make it"
44 44
     (if (typep color-cube '(simple-array T (3 3 3)))
45 45
         (progn
@@ -63,8 +63,8 @@
63 63
 (define-test test-make-array-from-list
64 64
   (let ((x))
65 65
     (setf x (make-array '(4) :initial-contents '(:one :two :three :four)))
66
-    (assert-equal (array-dimensions x) ____)
67
-    (assert-equal ____ (aref x 0))))
66
+    (assert-equal (array-dimensions x) '(4))
67
+    (assert-equal :one (aref x 0))))
68 68
 
69 69
 
70 70
 (define-test test-row-major-index
@@ -74,5 +74,5 @@
74 74
     (setf my-array (make-array '(2 2 2 2)))
75 75
     (dotimes (i (* 2 2 2 2))
76 76
       (setf (row-major-aref my-array i) i))
77
-    (assert-equal (aref my-array 0 0 0 0) ____)
78
-    (assert-equal (aref my-array 1 1 1 1) ____)))
77
+    (assert-equal (aref my-array 0 0 0 0) 0)
78
+    (assert-equal (aref my-array 1 1 1 1) 15)))

+ 7 - 9
koans/asserts.lsp

@@ -25,23 +25,21 @@
25 25
 
26 26
 (define-test assert-true
27 27
     "t is true.  Replace the blank with a t"
28
-    (assert-true ___))
28
+    (assert-true t))
29 29
 
30 30
 (define-test assert-false
31 31
     "nil is false"
32
-    (assert-false ___))
32
+    (assert-false nil))
33 33
 
34 34
 (define-test fill-in-the-blank
35 35
     "sometimes you will need to fill the blank to complete"
36
-    (assert-equal 2 ___))
36
+    (assert-equal 2 2))
37 37
 
38 38
 (define-test fill-in-the-blank-string
39
-    (assert-equal ___ "hello world"))
39
+    (assert-equal "hello world" "hello world"))
40 40
 
41 41
 (define-test test-true-or-false
42
-    "sometimes you will be asked to evaluate whether statements 
42
+    "sometimes you will be asked to evaluate whether statements
43 43
      are true (t) or false (nil)"
44
-    (true-or-false? ___ (equal 34 34))
45
-    (true-or-false? ___ (equal 19 78)))
46
-
47
-
44
+    (true-or-false? t (equal 34 34))
45
+    (true-or-false? nil (equal 19 78)))

+ 14 - 14
koans/atoms-vs-lists.lsp

@@ -19,30 +19,30 @@
19 19
      white-space or parentheses.  The function 'listp' will return true if
20 20
      the input is a list.  The function 'atom' will return true if the
21 21
      input is an atom."
22
-  (true-or-false? ___ (listp '(1 2 3)))
23
-  (true-or-false? ___ (atom '(1 2 3)))
22
+  (true-or-false? t (listp '(1 2 3)))
23
+  (true-or-false? nil (atom '(1 2 3)))
24 24
 
25
-  (true-or-false? ___ (listp '("heres" "some" "strings")))
26
-  (true-or-false? ___ (atom '("heres" "some" "strings")))
25
+  (true-or-false? t (listp '("heres" "some" "strings")))
26
+  (true-or-false? nil (atom '("heres" "some" "strings")))
27 27
 
28
-  (true-or-false? ___ (listp "a string"))
29
-  (true-or-false? ___ (atom "a string"))
28
+  (true-or-false? nil (listp "a string"))
29
+  (true-or-false? t (atom "a string"))
30 30
 
31
-  (true-or-false? ___ (listp 2))
32
-  (true-or-false? ___ (atom 2))
31
+  (true-or-false? nil (listp 2))
32
+  (true-or-false? t (atom 2))
33 33
 
34
-  (true-or-false? ___ (listp '(("first" "list") ("second" "list"))))
35
-  (true-or-false? ___ (atom '(("first" "list") ("second" "list")))))
34
+  (true-or-false? t (listp '(("first" "list") ("second" "list"))))
35
+  (true-or-false? nil (atom '(("first" "list") ("second" "list")))))
36 36
 
37 37
 
38 38
 (define-test test-empty-list-is-both-list-and-atom
39 39
     "the empty list, nil, is unique in that it is both a list and an atom"
40
-  (true-or-false? ___ (listp nil))
41
-  (true-or-false? ___ (atom nil)))
40
+  (true-or-false? t (listp nil))
41
+  (true-or-false? t (atom nil)))
42 42
 
43 43
 
44 44
 (define-test test-keywords
45 45
     "symbols like :hello or :like-this are treated differently in lisp.
46 46
      Called keywords, they are symbols that evaluate to themselves."
47
-  (true-or-false? ___ (equal :this-is-a-keyword :this-is-a-keyword))
48
-  (true-or-false? ___ (equal :this-is-a-keyword ':this-is-a-keyword)))
47
+  (true-or-false? t (equal :this-is-a-keyword :this-is-a-keyword))
48
+  (true-or-false? t (equal :this-is-a-keyword ':this-is-a-keyword)))

+ 44 - 44
koans/equality-distinctions.lsp

@@ -18,42 +18,42 @@
18 18
     "(eq x y) is true if and only if x and y are the same identical object
19 19
      eq is like comparing pointers in c.  If the values are EQ, any non-nil
20 20
      value may be returned."
21
-  (true-or-false? ___ (eq 'a 'a))
22
-  (true-or-false? ___ (eq 3 3.0))
23
-  (true-or-false? ___ (eq '(1 2) '(1 2)))
24
-  (true-or-false? ___ (eq "Foo" "Foo"))
25
-  (true-or-false? ___ (eq "Foo" (copy-seq "Foo")))
26
-  (true-or-false? ___ (eq "FOO" "Foo")))
21
+  (true-or-false? t (eq 'a 'a))
22
+  (true-or-false? nil (eq 3 3.0))
23
+  (true-or-false? nil (eq '(1 2) '(1 2)))
24
+  (true-or-false? nil (eq "Foo" "Foo"))
25
+  (true-or-false? nil (eq "Foo" (copy-seq "Foo")))
26
+  (true-or-false? nil (eq "FOO" "Foo")))
27 27
 
28 28
 (define-test test-eql
29 29
     "(eql x y) is true if (eq x y)
30 30
      also it is true if x and y are numeric of the same type
31 31
      and represent the same number.
32 32
      (eql x y) also if x and y are the same characters."
33
-   (true-or-false? ___ (eql 'a 'a))
34
-   (true-or-false? ___ (eql 3 3))
35
-   (true-or-false? ___ (eql 3 3.0))
36
-   (true-or-false? ___ (eql '(1 2) '(1 2)))
37
-   (true-or-false? ___ (eql  '(:a . :b) '(:a . :b)))
38
-   (true-or-false? ___ (eql #\S #\S))
39
-   (true-or-false? ___ (eql "Foo" "Foo"))
40
-   (true-or-false? ___ (eql "Foo" (copy-seq "Foo")))
41
-   (true-or-false? ___ (eql "FOO" "Foo")))
33
+   (true-or-false? t (eql 'a 'a))
34
+   (true-or-false? t (eql 3 3))
35
+   (true-or-false? nil (eql 3 3.0))
36
+   (true-or-false? nil (eql '(1 2) '(1 2)))
37
+   (true-or-false? nil (eql  '(:a . :b) '(:a . :b)))
38
+   (true-or-false? t (eql #\S #\S))
39
+   (true-or-false? nil (eql "Foo" "Foo"))
40
+   (true-or-false? nil (eql "Foo" (copy-seq "Foo")))
41
+   (true-or-false? nil (eql "FOO" "Foo")))
42 42
 
43 43
 (define-test test-equal
44 44
     "(equal x y) is true if (eql x y), or
45 45
      x and y are lists with equal elements, or
46 46
      x and y character or bit arrays with equal elements"
47
-   (true-or-false? ___ (equal 'a 'a))
48
-   (true-or-false? ___ (equal 3 3))
49
-   (true-or-false? ___ (equal 3 3.0))
50
-   (true-or-false? ___ (equal '(1 2) '(1 2)))
51
-   (true-or-false? ___ (equal  '(:a . :b) '(:a . :b)))
52
-   (true-or-false? ___ (equal  '(:a . :b) '(:a . :doesnt-match)))
53
-   (true-or-false? ___ (equal #\S #\S))
54
-   (true-or-false? ___ (equal "Foo" "Foo"))
55
-   (true-or-false? ___ (equal "Foo" (copy-seq "Foo")))
56
-   (true-or-false? ___ (equal "FOO" "Foo")))
47
+   (true-or-false? t (equal 'a 'a))
48
+   (true-or-false? t (equal 3 3))
49
+   (true-or-false? nil (equal 3 3.0))
50
+   (true-or-false? t (equal '(1 2) '(1 2)))
51
+   (true-or-false? t (equal  '(:a . :b) '(:a . :b)))
52
+   (true-or-false? nil (equal  '(:a . :b) '(:a . :doesnt-match)))
53
+   (true-or-false? t (equal #\S #\S))
54
+   (true-or-false? t (equal "Foo" "Foo"))
55
+   (true-or-false? t (equal "Foo" (copy-seq "Foo")))
56
+   (true-or-false? nil (equal "FOO" "Foo")))
57 57
 
58 58
 (define-test test-equalp
59 59
     "(equalp x y) if (equal x y) or
@@ -61,32 +61,32 @@
61 61
      if x and y are arrays with the same dimensions and equal elements
62 62
      if x and y are numeric of different types but one may be upgraded to
63 63
      the other type without loss and still exhibit equality."
64
-   (true-or-false? ___ (equalp 'a 'a))
65
-   (true-or-false? ___ (equalp 3 3))
66
-   (true-or-false? ___ (equalp 3 3.0))
67
-   (true-or-false? ___ (equalp '(1 2) '(1 2)))
68
-   (true-or-false? ___ (equalp  '(:a . :b) '(:a . :b)))
69
-   (true-or-false? ___ (equalp  '(:a . :b) '(:a . :doesnt-match)))
70
-   (true-or-false? ___ (equalp #\S #\S))
71
-   (true-or-false? ___ (equalp "Foo" "Foo"))
72
-   (true-or-false? ___ (equalp "Foo" (copy-seq "Foo")))
73
-   (true-or-false? ___ (equalp "FOO" "Foo")))
64
+   (true-or-false? t (equalp 'a 'a))
65
+   (true-or-false? t (equalp 3 3))
66
+   (true-or-false? t (equalp 3 3.0))
67
+   (true-or-false? t (equalp '(1 2) '(1 2)))
68
+   (true-or-false? t (equalp  '(:a . :b) '(:a . :b)))
69
+   (true-or-false? nil (equalp  '(:a . :b) '(:a . :doesnt-match)))
70
+   (true-or-false? t (equalp #\S #\S))
71
+   (true-or-false? t (equalp "Foo" "Foo"))
72
+   (true-or-false? t (equalp "Foo" (copy-seq "Foo")))
73
+   (true-or-false? t (equalp "FOO" "Foo")))
74 74
 
75 75
 (define-test test-numeric-equal
76 76
     "(= x y) is only for numerics
77 77
      and can take multiple arguments
78 78
      if x or y is not numeric there will be a compiler error."
79
-   (true-or-false? ___ (= 99.0 99 99.000))
80
-   (true-or-false? ___ (= 0 1 -1))
81
-   (true-or-false? ___ (= (/ 2 3) (/ 6 9) (/ 86 129))))
79
+   (true-or-false? t (= 99.0 99 99.000))
80
+   (true-or-false? nil (= 0 1 -1))
81
+   (true-or-false? t (= (/ 2 3) (/ 6 9) (/ 86 129))))
82 82
 
83
-; EQ, EQL, EQUAL, and EQUALP are general equality predicates.
83
+; EQ, EQL, EQUAL, and EQUAL are general equality predicates.
84 84
 ; Additionally, Lisp also provides the type-specific predicates.
85 85
 ; For example, STRING= and STRING-EQUAL are predicates for strings.
86 86
 (define-test test-string-equal
87 87
   "string-equal is just like string= except that differences in case are ignored."
88
-  (true-or-false? ___ (string= "Foo" "Foo"))
89
-  (true-or-false? ___ (string= "Foo" "FOO"))
90
-  (true-or-false? ___ (string= "together" "frog" :start1 1 :end1 3 :start2 2))
91
-  (true-or-false? ___ (string-equal "Foo" "FOO"))
92
-  (true-or-false? ___ (string-equal "together" "FROG" :start1 1 :end1 3 :start2 2)))
88
+  (true-or-false? t (string= "Foo" "Foo"))
89
+  (true-or-false? nil (string= "Foo" "FOO"))
90
+  (true-or-false? t (string= "together" "frog" :start1 1 :end1 3 :start2 2))
91
+  (true-or-false? t (string-equal "Foo" "FOO"))
92
+  (true-or-false? t (string-equal "together" "FROG" :start1 1 :end1 3 :start2 2)))

+ 18 - 18
koans/evaluation.lsp

@@ -22,21 +22,21 @@
22 22
      with the function name the first element of that list."
23 23
 
24 24
   "in these examples, the function names are +, -, and *"
25
-  (assert-equal ___ (+ 2 3))
26
-  (assert-equal ___ (- 1 3))
27
-  (assert-equal ___ (* 7 4))
25
+  (assert-equal 5 (+ 2 3))
26
+  (assert-equal -2 (- 1 3))
27
+  (assert-equal 28 (* 7 4))
28 28
   "'>' and '=' are the boolean functions (predicates) 'greater-than' and
29 29
    'equal to'"
30
-  (assert-equal ___ (> 100 4))
31
-  (assert-equal ___ (= 3 3))
30
+  (assert-equal t (> 100 4))
31
+  (assert-equal t (= 3 3))
32 32
   "'NUMBERP' is a predicate which returns true if the argument is a number"
33
-  (assert-equal ___ (numberp 5))
34
-  (assert-equal ___ (numberp "five")))
33
+  (assert-equal t (numberp 5))
34
+  (assert-equal nil (numberp "five")))
35 35
 
36 36
 
37 37
 (define-test test-evaluation-order
38 38
     "Arguments to functions are evaluated before the function"
39
-  (assert-equal ___ (* (+ 1 2) (- 13 10))))
39
+  (assert-equal 9 (* (+ 1 2) (- 13 10))))
40 40
 
41 41
 
42 42
 (define-test test-quoting-behavior
@@ -45,17 +45,17 @@
45 45
      the literal list.
46 46
      Evaluating the form (+ 1 2) returns the number 3,
47 47
      but evaluating the form '(+ 1 2) returns the list (+ 1 2)"
48
-  (assert-equal ____ (+ 1 2))
49
-  (assert-equal ____ '(+ 1 2))
48
+  (assert-equal 3 (+ 1 2))
49
+  (assert-equal (quote (+ 1 2)) '(+ 1 2))
50 50
   "'LISTP' is a predicate which returns true if the argument is a list"
51 51
   " the '(CONTENTS) form defines a list literal containing CONTENTS"
52
-  (assert-equal ___ (listp '(1 2 3)))
53
-  (assert-equal ___ (listp 100))
54
-  (assert-equal ___ (listp "Word to your moms I came to drop bombs"))
55
-  (assert-equal ___ (listp nil))
56
-  (assert-equal ___ (listp (+ 1 2)))
57
-  (assert-equal ___ (listp '(+ 1 2)))
52
+  (assert-equal t (listp '(1 2 3)))
53
+  (assert-equal nil (listp 100))
54
+  (assert-equal nil (listp "Word to your moms I came to drop bombs"))
55
+  (assert-equal t (listp nil))
56
+  (assert-equal nil (listp (+ 1 2)))
57
+  (assert-equal t (listp '(+ 1 2)))
58 58
   "equalp is an equality predicate"
59
-  (assert-equal ___ (equalp 3 (+ 1 2)))
59
+  (assert-equal t (equalp 3 (+ 1 2)))
60 60
   "the '(xyz ghi) syntax is syntactic sugar for the (QUOTE (xyz ghi)) function."
61
-  (true-or-false? ___ (equalp '(/ 4 0) (quote (/ 4 0)))))
61
+  (true-or-false? t (equalp '(/ 4 0) (quote (/ 4 0)))))

+ 24 - 24
koans/lists.lsp

@@ -23,8 +23,8 @@
23 23
         (some-evens nil))
24 24
     (setf fruits '(orange pomello clementine))
25 25
     (setf some-evens (list (* 2 1) (* 2 2) (* 2 3)))
26
-    (assert-equal fruits ___)
27
-    (assert-equal ___ (length some-evens))))
26
+    (assert-equal fruits (list 'orange 'pomello 'clementine))
27
+    (assert-equal 3 (length some-evens))))
28 28
 
29 29
 
30 30
 (define-test test-list-cons
@@ -35,15 +35,15 @@
35 35
       (assert-equal '(:one) nums)
36 36
 
37 37
       (setf nums (cons :two nums))
38
-      (assert-equal ___ nums)
38
+      (assert-equal '(:two :one) nums)
39 39
 
40 40
       "lists can contain anything, even mixtures of different things"
41 41
       (setf nums (cons 333 nums))
42
-      (assert-equal ___ nums)
42
+      (assert-equal '(333 :two :one) nums)
43 43
 
44 44
       "lists can of course contain lists"
45 45
       (setf nums (cons '("the" "rest") nums))
46
-      (assert-equal ___ nums)))
46
+      (assert-equal '(("the" "rest") 333 :two :one) nums)))
47 47
 
48 48
 
49 49
 (define-test test-push-pop
@@ -60,8 +60,8 @@
60 60
       (assert-equal '(10 20 30 40) stack)
61 61
 
62 62
       (setf firstval (pop stack))
63
-      (assert-equal ___ firstval)
64
-      (assert-equal ___ stack)))
63
+      (assert-equal 10 firstval)
64
+      (assert-equal '(20 30 40) stack)))
65 65
 
66 66
 
67 67
 (define-test test-append
@@ -72,38 +72,38 @@
72 72
         (xyz '(:x :y :z))
73 73
         (abcxyz nil))
74 74
     (setf abcxyz (append abc xyz))
75
-    (assert-equal ___ abc)
76
-    (assert-equal ___ xyz)
77
-    (assert-equal ___ abcxyz)))
75
+    (assert-equal '(:a :b :c) abc)
76
+    (assert-equal '(:x :y :z) xyz)
77
+    (assert-equal '(:a :b :c :x :y :z) abcxyz)))
78 78
 
79 79
 
80 80
 (define-test test-accessing-list-elements
81 81
     (let ((noms '("peanut" "butter" "and" "jelly")))
82 82
       (assert-equal "peanut" (first noms))
83
-      (assert-equal ___ (second noms))
84
-      (assert-equal ___ (fourth noms))
83
+      (assert-equal "butter" (second noms))
84
+      (assert-equal "jelly" (fourth noms))
85 85
       "last returns a singleton list of the final element"
86
-      (assert-equal ___ (last noms))
86
+      (assert-equal '("jelly") (last noms))
87 87
       (assert-equal "butter" (nth 1 noms)) ; k 1
88
-      (assert-equal ___ (nth 0 noms))
89
-      (assert-equal ___ (nth 2 noms))
88
+      (assert-equal "peanut" (nth 0 noms))
89
+      (assert-equal "and" (nth 2 noms))
90 90
       "'elt' is similar to 'nth', with the arguments reversed"
91
-      (assert-equal ___ (elt noms 2))))
91
+      (assert-equal "and" (elt noms 2))))
92 92
 
93 93
 
94 94
 (define-test test-slicing-lists
95 95
     (let ((noms '("peanut" "butter" "and" "jelly")))
96
-      (assert-equal ___ (subseq noms 0 1))
97
-      (assert-equal ___ (subseq noms 0 2))
98
-      (assert-equal ___ (subseq noms 2 2))
99
-      (assert-equal ___ (subseq noms 2))))
96
+      (assert-equal '("peanut") (subseq noms 0 1))
97
+      (assert-equal '("peanut" "butter") (subseq noms 0 2))
98
+      (assert-equal nil (subseq noms 2 2))
99
+      (assert-equal '("and" "jelly") (subseq noms 2))))
100 100
 
101 101
 
102 102
 (define-test test-list-breakdown
103 103
     "car (aka. 'first') returns the first value in a list"
104
-  (assert-equal ___ (car '(1 2 3)))
105
-  (assert-equal ___ (car nil))
104
+  (assert-equal 1 (car '(1 2 3)))
105
+  (assert-equal nil (car nil))
106 106
     "cdr (aka. 'rest') refers to the remainder of the list,
107 107
      after the first element"
108
-  (assert-equal ___ (cdr '(1 2 3)))
109
-  (assert-equal ___ (cdr nil)))
108
+  (assert-equal '(2 3) (cdr '(1 2 3)))
109
+  (assert-equal nil (cdr nil)))

+ 5 - 5
koans/multiple-values.lsp

@@ -24,7 +24,7 @@ This is distinct from returning a list or structure of values."
24 24
       (assert-equal x 1)
25 25
       (setf x (multiple-value-list (floor 3/2)))
26 26
       (assert-equal x '(1 1/2)))
27
-  (assert-equal (multiple-value-list (floor 99/4)) ____))
27
+  (assert-equal (multiple-value-list (floor 99/4)) '(24 3/4)))
28 28
 
29 29
 (defun next-fib (a b)
30 30
   (values b (+ a b)))
@@ -33,16 +33,16 @@ This is distinct from returning a list or structure of values."
33 33
     (let ((x)
34 34
           (y))
35 35
       (setf x (next-fib 2 3))
36
-      (assert-equal x ___)
36
+      (assert-equal x 3)
37 37
       (setf x (multiple-value-list (next-fib 2 3)))
38
-      (assert-equal x ___)
38
+      (assert-equal x '(3 5))
39 39
       "multiple-value-bind binds the variables in the first form
40 40
        to the outputs of the second form.  And then returns the output
41 41
        of the third form using those bindings"
42 42
       (setf y (multiple-value-bind (b c) (next-fib 3 5) (* b c)))
43
-      (assert-equal y ___)
43
+      (assert-equal y 40)
44 44
       "multiple-value-setq is like setf, but can set multiple variables"
45 45
       (multiple-value-setq (x y) (values :v1 :v2))
46 46
       (assert-equal (list x y) '(:v1 :v2))
47 47
       (multiple-value-setq (x y) (next-fib 5 8))
48
-      (assert-equal (list x y) ____)))
48
+      (assert-equal (list x y) '(8 13))))

+ 17 - 17
koans/nil-false-empty.lsp

@@ -14,42 +14,42 @@
14 14
 
15 15
 (define-test test-t-and-nil-are-opposites
16 16
     "not is a function which returns the boolean opposite of its argument"
17
-   (true-or-false? ___ (not nil))
18
-   (true-or-false? ___ (not t)))
17
+   (true-or-false? t (not nil))
18
+   (true-or-false? nil (not t)))
19 19
 
20 20
 
21 21
 (define-test test-nil-and-empty-list-are-the-same-thing
22
-  (true-or-false? ___ ())
23
-  (true-or-false? ___ (not ())))
22
+  (true-or-false? nil ())
23
+  (true-or-false? t (not ())))
24 24
 
25 25
 
26 26
 (define-test test-lots-of-things-are-true
27 27
    " every value, other than nil, is boolean true"
28
-   (true-or-false? ___ 5)
29
-   (true-or-false? ___ (not 5))
30
-   (true-or-false? ___ "A String")
28
+   (true-or-false? t 5)
29
+   (true-or-false? nil (not 5))
30
+   (true-or-false? t "A String")
31 31
    "only nil is nil.  Everything else is effectively true."
32 32
    "the empty string"
33
-   (true-or-false? ___ "")
33
+   (true-or-false? t "")
34 34
    "a list containing a nil"
35
-   (true-or-false? ___ '(nil))
35
+   (true-or-false? t '(nil))
36 36
    "an array with no elements"
37
-   (true-or-false? ___ (make-array '(0)))
37
+   (true-or-false? t (make-array '(0)))
38 38
    "the number zero"
39
-   (true-or-false? ___ 0))
39
+   (true-or-false? t 0))
40 40
 
41 41
 
42 42
 (define-test test-and
43 43
    "and can take multiple arguments"
44
-   (true-or-false? ___ (and t t t t t))
45
-   (true-or-false? ___ (and t t nil t t))
44
+   (true-or-false? t (and t t t t t))
45
+   (true-or-false? nil (and t t nil t t))
46 46
    "if no nils, and returns the last value"
47
-   (assert-equal ___ (and t t t t t 5)))
47
+   (assert-equal 5 (and t t t t t 5)))
48 48
 
49 49
 
50 50
 (define-test test-or
51 51
    "or can also take multiple arguments"
52
-   (true-or-false? ____  (or nil nil nil t nil))
52
+   (true-or-false? t  (or nil nil nil t nil))
53 53
    "or returns the first non nil value, or nil if there are none."
54
-   (assert-equal ____ (or nil nil nil))
55
-   (assert-equal ____ (or 1 2 3 4 5)))
54
+   (assert-equal nil (or nil nil nil))
55
+   (assert-equal 1 (or 1 2 3 4 5)))

+ 23 - 18
koans/special-forms.lsp

@@ -29,14 +29,14 @@
29 29
     "setf is used to assign values to symbols.  These symbols may refer to
30 30
      variables with lexical or dynamic scope."
31 31
   (setf my-name "David")
32
-  (assert-equal my-name ____)
32
+  (assert-equal my-name "David")
33 33
   " In SBCL, if the symbol isn't defined as a variable, via a top-level defvar
34 34
   or let statement, the setf call may result in a warning."
35 35
   (setf my-clones-name my-name)
36
-  (assert-equal "David" ____)
36
+  (assert-equal "David" my-clones-name)
37 37
   (setf a 5)
38 38
   (setf b 10)
39
-  (setf c ___)
39
+  (setf c 50)
40 40
   (assert-equal 50 c))
41 41
 
42 42
 
@@ -46,20 +46,20 @@
46 46
      lexical form.  After which, the previous value, if it exists, is visible again."
47 47
   (setf a 10)
48 48
   (setf b 20)
49
-  (assert-equal a ___)
50
-  (assert-equal b ___)
49
+  (assert-equal a 10)
50
+  (assert-equal b 20)
51 51
   (let ((a 1111)
52 52
         (b 2222))
53
-    (assert-equal a ___)
54
-    (assert-equal b ___))
55
-  (assert-equal a ___)
56
-  (assert-equal b ___))
53
+    (assert-equal a 1111)
54
+    (assert-equal b 2222))
55
+  (assert-equal a 10)
56
+  (assert-equal b 20))
57 57
 
58 58
 
59 59
 (define-test test-let-default-value
60 60
     "let vars have a default value"
61 61
     (let ((x))
62
-      (assert-equal ___ x)))
62
+      (assert-equal nil x)))
63 63
 
64 64
 (define-test test-let-bindings-are-parallel
65 65
     "When defining the bindings in the let form, later bindings may not depend
@@ -67,15 +67,15 @@
67 67
   (setf a 100)
68 68
   (let ((a 5)
69 69
         (b (* 10 a)))
70
-    (assert-equal b ___)))
70
+    (assert-equal b 1000)))
71 71
 
72 72
 (define-test test-let*-bindings-are-series
73 73
     "let* is like let, but successive bindings may use values of previous ones"
74 74
   (setf a 100)
75 75
   (let* ((a 5)
76 76
          (b (* 10 a)))
77
-    (assert-equal b ___))
78
-  (assert-equal a ___))
77
+    (assert-equal b 50))
78
+  (assert-equal a 100))
79 79
 
80 80
 
81 81
 (define-test write-your-own-let-statement
@@ -83,13 +83,15 @@
83 83
   (setf a 100)
84 84
   (setf b 23)
85 85
   (setf c 456)
86
-  (let ((a 0)
87
-        (b __)
88
-        (c __))
86
+  (let ((a a)
87
+        (b (* a 2))
88
+        (c "Jellyfish"))
89 89
     (assert-equal a 100)
90 90
     (assert-equal b 200)
91 91
     (assert-equal c "Jellyfish"))
92
-  (let* ((a 0))
92
+  (let* ((a 121)
93
+         (b 200)
94
+         (c (+ a (/ b a))))
93 95
     (assert-equal a 121)
94 96
     (assert-equal b 200)
95 97
     (assert-equal c (+ a (/ b a)))))
@@ -102,12 +104,15 @@
102 104
         (cond ((> a 0) :positive)
103 105
               ((< a 0) :negative)
104 106
               (t :zero)))
105
-  (assert-equal ____ c))
107
+  (assert-equal :positive c))
106 108
 
107 109
 
108 110
 (defun cartoon-dads (input)
109 111
   " you should be able to complete this cond statement"
110 112
   (cond ((equal input :this-one-doesnt-happen) :fancy-cat)
113
+        ((equal input :bart) :homer)
114
+        ((equal input :stewie) :peter)
115
+        ((equal input :stan) :randy)
111 116
         (t :unknown)))
112 117
 
113 118
 (define-test test-your-own-cond-statement

+ 10 - 12
koans/vectors.lsp

@@ -16,29 +16,29 @@
16 16
 
17 17
 (define-test test-vector-types
18 18
   " #(x y z) defines a vector literal containing x y z"
19
-  (true-or-false? ___ (typep #(1 11 111) 'vector))
20
-  (assert-equal ___ (aref #(1 11 111) 1)))
19
+  (true-or-false? t (typep #(1 11 111) 'vector))
20
+  (assert-equal 11 (aref #(1 11 111) 1)))
21 21
 
22 22
 
23 23
 (define-test test-length-works-on-vectors
24
-  (assert-equal (length #(1 2 3)) ___ ))
24
+  (assert-equal (length #(1 2 3)) 3 ))
25 25
 
26 26
 
27 27
 (define-test test-bit-vector
28 28
     "#*0011 defines a bit vector literal with four elements, 0, 0, 1 and 1"
29
-  (assert-equal #*0011 (make-array '4 :element-type 'bit))
30
-  (true-or-false? ____ (typep #*1001 'bit-vector))
31
-  (assert-equal ____ (aref #*1001 1)))
29
+  (assert-equal #*0011 (make-array '4 :element-type 'bit :initial-contents '(0 0 1 1)))
30
+  (true-or-false? t (typep #*1001 'bit-vector))
31
+  (assert-equal 0 (aref #*1001 1)))
32 32
 
33 33
 
34 34
 (define-test test-some-bitwise-operations
35
-    (assert-equal ___ (bit-and #*1100 #*1010))
36
-    (assert-equal ___ (bit-ior #*1100 #*1010))
37
-    (assert-equal ___ (bit-xor #*1100 #*1010)))
35
+    (assert-equal #*1000 (bit-and #*1100 #*1010))
36
+    (assert-equal #*1110 (bit-ior #*1100 #*1010))
37
+    (assert-equal #*0110 (bit-xor #*1100 #*1010)))
38 38
 
39 39
 
40 40
 (defun list-to-bit-vector (my-list)
41
-  nil)
41
+  (make-array (length my-list) :element-type 'bit :initial-contents my-list))
42 42
 
43 43
 (define-test test-list-to-bit-vector
44 44
     "you must complete list-to-bit-vector"
@@ -46,5 +46,3 @@
46 46
   (assert-equal (aref (list-to-bit-vector '(0)) 0) 0)
47 47
   (assert-equal (aref (list-to-bit-vector '(0 1)) 1) 1)
48 48
   (assert-equal (length (list-to-bit-vector '(0 0 1 1 0 0 1 1))) 8))
49
-
50
-