75 lines
2.1 KiB
Plaintext
75 lines
2.1 KiB
Plaintext
;; Function To Be Tested: ccase
|
|
;;
|
|
;; Source: Guy L Steele's CLTL
|
|
;; Section: 24.3 ERRORS (Special Forms for Exhaustive Case Analysis)
|
|
;; Page: 436
|
|
;;
|
|
;; Created By: John Park
|
|
;;
|
|
;; Creation Date: Nov 7, 1986
|
|
;;
|
|
;; Last Update: Jan 15, 1987
|
|
;;
|
|
;; Filed As: {ERIS}<LISPCORE>CML>TEST>24-3-ccase.test
|
|
;;
|
|
;;
|
|
;; Syntax: (ccase keyform {({({key}*)|key} {form}*)}*
|
|
;;
|
|
;; Function Description: This control construct is similar to case, but no explicit
|
|
;; otherwise or T clause is permitted. If no clause is satisfied, ccase signals
|
|
;; an error with a message constructed from the clauses. Continuing from this
|
|
;; error causes ccase to accept a new value from the user, store it into keyplace
|
|
;; , and start over, making the clause tests again. Subforms of keyplace may be
|
|
;; evaluated multiple times. The name of this function stands from "continuable
|
|
;; exhaustive case."
|
|
;;
|
|
;; Argument(s): Keyplace: Key (variable)
|
|
;; (type {form}): type case for error checking
|
|
;;
|
|
;; Returns:
|
|
;;
|
|
;; Constraints/Limitations: Due to the nature of ccase function, which enters
|
|
;; the debugger (break), this test should be conducted manually to see if correct
|
|
;; error messages are returned. Tests requiring user interface are commented out.
|
|
|
|
|
|
|
|
(do-test "ccase-test0"
|
|
(macro-function 'ccase) ; Does ccase have a macro definition?
|
|
)
|
|
|
|
(do-test "ccase-test1"
|
|
(and (setq x 'alpha)
|
|
(defun foo () 'foo-for-alpha)
|
|
(defun bar () 'bar-for-omega)
|
|
(defun baz () 'baz-for-zeta)
|
|
(setq alpha 1 omega 2 zeta 3 phi 4)
|
|
(equal (mapcar #'(lambda (x)
|
|
(ccase x
|
|
(alpha (foo))
|
|
(omega (bar))
|
|
((zeta phi) (baz))))
|
|
'(alpha omega zeta phi))
|
|
(list (foo) (bar) (baz) (baz)))
|
|
|
|
)
|
|
) ; This should not break since each of the three clauses is satisfied.
|
|
|
|
|
|
;; The following (ccase-test2) should break with the appropriate error message,
|
|
;; prompt for a new value, and return when the new value satisfies one of the
|
|
;; three clauses
|
|
;; "Error: The value of X, 1/3, is neither an integer nor a symbol"
|
|
;;
|
|
;; (progn (setq x 1/3)
|
|
;; (ccase x
|
|
;; (alpha (foo))
|
|
;; (omega (bar))
|
|
;; ((zeta phi) (baz)))
|
|
;; )
|
|
|
|
STOP
|
|
|
|
|
|
|