![]() | ![]() | ![]() | ccase-using | ![]() |
|
| test keyplace {clause}* => result* | [Macro] |
Purpose
Conditionally execute the forms in a clause that is selected by
matching the result of evaluating keyplace according to test,
generating a correctable error if no clause is selected.
Package :gbbopen-tools
Module :gbbopen-tools
Arguments and values
| test | A symbol designating a comparison predicate (not evaluated) | |
| keyplace | A form; evaluated to produce a test-key and possibly also used later as a place if no keys match (see below) | |
| results | The values returned by evaluating the last form in the selected clause |
Returns
The values returned by the last form in the selected clause.
Errors
No clause was selected.
Detailed syntax
| clause ::= | (keys form*) |
Terms
| test-key | An object produced by evaluating keyplace | |
| keys | An object or a list of objects. | |
| form | A form |
Description
The specified test symbol is not evaluated; however the comparison predicate that
it designates must be available during expansion of the case-using
form.
The keyplace is first evaluated to produce the test-key.
Each of the clauses is then considered in turn. If the test-key
matches that clause according to test, then the forms in that clause are evaluated
as an implicit progn, and the values it returns are returned as the value of
the ccase-using form.
If no clause is selected, a correctable error of type
case-using-failure (a subclass of type-error) is signaled. The
offending datum is the test-key and the expected type is type
equivalent to (member (union keys :test test). Common Lisp's store-value restart can be used
to correct the error.
Ccase-using is a generalization of Common Lisp's ccase macro.
See also
case-using-failure
case-using
ecase-using
Examples
> (defparameter *x* "a")
*x*
> (ccase-using string= *x*
("a" 1)
(("b" "c" "d") 2))
1
> (setf *x* "d")
"d"
> (ccase-using string= *x*
("a" 1)
(("b" "c" "d") 2))
2
> (setf *x* "C")
"C"
> (ccase-using string= *x*
("a" 1)
(("b" "c" "d") 2))
Error: "C" fell through an ecase-using string= form;
the valid keys are "a", "b", "c", and "d".
Restart actions (select using :c n):
0: Supply a new value for *x*.
>> :c 0
Enter a form to evaluate as the new value for *x*: "a"
*x* is now "a"
1
>
The GBBopen Project
![]() | ![]() | ![]() | ccase-using | ![]() |