Fix 12 exercise defects from review wave 1 (scouts a+d)
This commit is contained in:
1 parent
3f753b2a8f
commit
2735c8dca5
18 files changed
+49
-5
No files matched your search
@@ -0,0 +1,8 @@
|
||||
# 00_intro
|
||||
|
||||
The Lisplings flow, and reading your first error.
|
||||
|
||||
intro1 is error-free: edit it, save it, and watch the exercise run
|
||||
again in the terminal (press n to move on, h for a hint). intro2
|
||||
does not load; read the error in the terminal and fix it so the
|
||||
greeting prints.
|
||||
@@ -3,6 +3,9 @@
|
||||
;;; In Lisp the operator comes first: (+ 1 2) is 3. Nesting needs no
|
||||
;;; precedence rules at all: (* 2 (+ 3 4)) is 14.
|
||||
;;;
|
||||
;;; (defun name () ...) just names the expression; chapter 02
|
||||
;;; explains it.
|
||||
;;;
|
||||
;;; Fix each definition.
|
||||
|
||||
;; TODO: Add 10 and 32.
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
;;;
|
||||
;;; A Lisp delight: division is exact. (/ 1 2) is the rational 1/2,
|
||||
;;; not 0.5. Integers, rationals and floats form one number tower.
|
||||
;;;
|
||||
;;; (defun name () ...) just names the expression; chapter 02
|
||||
;;; explains it.
|
||||
|
||||
;; TODO: (2 + 3) multiplied by (4 - 1). Should be 15.
|
||||
(defun calc-a ()
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
;;; '(+ 1 2) evaluates to the list (+ 1 2)
|
||||
;;;
|
||||
;;; 'x is reader shorthand for (quote x).
|
||||
;;;
|
||||
;;; (defun name () ...) just names the expression; chapter 02
|
||||
;;; explains it.
|
||||
|
||||
;; TODO: The form itself, not its value.
|
||||
(defun the-form ()
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
;;; earlier parameter.
|
||||
|
||||
;; TODO: Repeat WORD N times. N is optional and defaults to 2.
|
||||
;; make-list builds a list of n copies (lists arrive in ch. 06).
|
||||
(defun repeat-word (word n)
|
||||
(make-list n :initial-element word))
|
||||
|
||||
@@ -22,5 +23,6 @@
|
||||
(check-equal '("hi" "hi") (repeat-word "hi"))
|
||||
(check-equal '("hi" "hi" "hi" "hi") (repeat-word "hi" 4))
|
||||
(check-equal '(:width 2 :height 2 :depth 2) (make-box 2))
|
||||
(check-equal '(:width 3 :height 3 :depth 3) (make-box 3))
|
||||
(check-equal '(:width 2 :height 5 :depth 2) (make-box 2 :height 5))
|
||||
(check-equal '(:width 2 :height 5 :depth 7) (make-box 2 :height 5 :depth 7))
|
||||
@@ -3,8 +3,9 @@
|
||||
;;; A function may return several values at once:
|
||||
;;; (values 1 2) => 1 and 2
|
||||
;;; Everything except the first value rides along, waiting for
|
||||
;;; MULTIPLE-VALUE-BIND or NTH-VALUE to pick it up. FLOOR is a
|
||||
;;; classic: (floor 10 3) returns 3 AND 1.
|
||||
;;; MULTIPLE-VALUE-BIND or NTH-VALUE to pick it up. The checks
|
||||
;;; below gather the values with MULTIPLE-VALUE-LIST, turning them
|
||||
;;; into a list. FLOOR is a classic: (floor 10 3) returns 3 AND 1.
|
||||
|
||||
;; TODO: Return TWO values: the whole part of A/B and the rest.
|
||||
(defun divide (a b)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
;;; LET may reuse a name: the new binding shadows the old one, and
|
||||
;;; the initializer still evaluates in the outer scope.
|
||||
|
||||
;; TODO: The inner X should be the outer X plus 5 - make it so,
|
||||
;;; without changing either number.
|
||||
;; TODO: Keep the outer 15; make the inner binding the outer X
|
||||
;; plus 5.
|
||||
(defun shadow-add ()
|
||||
(let ((x 15))
|
||||
(let ((x 15))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
;;;
|
||||
;;; SETF assigns to any "place": a variable, a list element, a
|
||||
;;; property. The general shape is (setf PLACE new-value).
|
||||
;;; (getf *account* :balance) reads the property back.
|
||||
|
||||
(defparameter *account* (list :owner "Ada" :balance 100))
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
;;; A single colon reaches only EXPORTED symbols. The kitchen
|
||||
;;; makes soup; only the soup is on the menu.
|
||||
|
||||
;; TODO: The defpackage below is missing (:export #:make-soup).
|
||||
(defpackage #:kitchen
|
||||
(:use #:common-lisp))
|
||||
|
||||
|
||||
@@ -24,3 +24,4 @@
|
||||
|
||||
(check-equal "yum" (catch-empty '(a b)))
|
||||
(check-equal "soup" (catch-empty '()))
|
||||
(check-error (eat '()) 'empty-plate)
|
||||
@@ -31,3 +31,8 @@
|
||||
(check-equal 1 (car-with-default '(1 2 3)))
|
||||
(check-equal nil (car-with-default "not a list"))
|
||||
(check-equal nil (car-with-default nil))
|
||||
(check-equal nil
|
||||
(handler-bind ((error (lambda (e)
|
||||
(declare (ignore e))
|
||||
(invoke-restart (find-restart 'use-nil)))))
|
||||
(safe-car "not a list")))
|
||||
@@ -24,3 +24,6 @@
|
||||
(check (eql 0 (current-depth)))
|
||||
(check (eql 3 (let ((*depth* 3)) (current-depth))))
|
||||
(check (eql 0 (current-depth)))
|
||||
(check (eql 42 (let ((*depth* 42))
|
||||
(with-depth 7 (lambda () nil))
|
||||
(current-depth))))
|
||||
Reference in new issue
Block a user