Skip to content

Commit 3185b8e

Browse files
committed
typecase vs. ctypecase vs. etypecase
1 parent 7c0b42c commit 3185b8e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Common-Lisp.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,33 @@ According to Common Lisp HyperSpec:
606606
* `fdefinition` takes either a *symbol* or a `(setf symbol)` form that
607607
designates a *function name*
608608

609+
=== `typecase` vs. `etypecase` vs. `ctypecase`
610+
611+
Match type → perform action.
612+
613+
* `typecase`: if no match → returns `nil`.
614+
* `ctypecase`: if no match → returns a _correctable error_.
615+
* `etypecase`: if no match → returns a _non-correctable error_.
616+
617+
Examples:
618+
619+
[source,lisp,linenums]
620+
----
621+
(typecase "a" (string :string)) ; ⇨ :string
622+
(typecase 1 (string :string)) ; ⇨ nil
623+
624+
(let ((x 1))
625+
(ctypecase x
626+
(string :string)
627+
(symbol (symbol-value x)))) ; ⇨ Asks to store value for X or abort
628+
629+
(let ((x 1))
630+
(etypecase x
631+
(string :string)
632+
(symbol (symbol-value x)))) ; ⇨ Error, cannot be corrected
633+
----
634+
635+
609636
== Useful libraries
610637

611638
* Pathnames and operating system interfaces: http://weitz.de/cl-fad[cl-pad],

0 commit comments

Comments
 (0)