summaryrefslogtreecommitdiffstats
path: root/stdlib/type.tl
diff options
context:
space:
mode:
authorPaul A. Patience <paul@apatience.com>2022-01-17 06:40:51 -0500
committerKaz Kylheku <kaz@kylheku.com>2022-01-21 22:30:38 -0800
commit2f9f717738b6bf8e1acd728567a0f953fc8a3614 (patch)
treed06f7df85cacedc967082595e1696a485d15a6e7 /stdlib/type.tl
parent27898e3aa3c6d7daa784712731aa03a7e6d60b22 (diff)
downloadtxr-2f9f717738b6bf8e1acd728567a0f953fc8a3614.tar.gz
txr-2f9f717738b6bf8e1acd728567a0f953fc8a3614.tar.bz2
txr-2f9f717738b6bf8e1acd728567a0f953fc8a3614.zip
type: new macro etypecase.
* lisplib.c (type_set_entries): Add etypecase to autoload list. * stdlib/type.tl (etypecase): New macro. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'stdlib/type.tl')
-rw-r--r--stdlib/type.tl11
1 files changed, 11 insertions, 0 deletions
diff --git a/stdlib/type.tl b/stdlib/type.tl
index f75c88e2..8a83a171 100644
--- a/stdlib/type.tl
+++ b/stdlib/type.tl
@@ -37,3 +37,14 @@
'typecase cl))))))
^(let ((,val ,form))
(cond ,*cond-pairs))))
+
+(defmacro etypecase (form . clauses)
+ (if [find t clauses eq car]
+ ^(typecase ,form ,*clauses)
+ (let ((val (gensym)))
+ ^(let ((,val ,form))
+ (typecase ,val
+ ,*clauses
+ (t (throwf 'case-error
+ "~s: unhandled type: ~s"
+ 'etypecase (typeof ,val))))))))