diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-09-10 07:46:09 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-09-10 07:46:09 -0700 |
commit | 3dcd7bb0633d943a84f2e6e8bf47efca8bb0df16 (patch) | |
tree | a6d6f68b8d36a7d1a3f6797253c2326ebf9edf89 | |
parent | ffe675fea6aabfe3428ebec8ff17863aeec98e5e (diff) | |
download | txr-3dcd7bb0633d943a84f2e6e8bf47efca8bb0df16.tar.gz txr-3dcd7bb0633d943a84f2e6e8bf47efca8bb0df16.tar.bz2 txr-3dcd7bb0633d943a84f2e6e8bf47efca8bb0df16.zip |
matcher: use function for match and match-ecase error.
* stdlib/match.tl (match-pat-error, match-error): New functions.
(match, match-ecase): Generate more compact code which just
calls match-pat-error rather than throwf, and doesn't contain any string
literals.
-rw-r--r-- | stdlib/match.tl | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/stdlib/match.tl b/stdlib/match.tl index 30389ce1..1442eb56 100644 --- a/stdlib/match.tl +++ b/stdlib/match.tl @@ -645,12 +645,18 @@ ,result ,else))))) +(defun match-pat-error (sym pat val) + (throwf 'match-error "~s: ~s failed to match object ~s" sym pat val)) + +(defun match-error (sym val) + (throwf 'match-error "~s: failed to match object ~s" sym val)) + (defmacro match (pat obj . body) (with-gensyms (val) ^(let ((,val ,obj)) (if-match ,pat ,val (progn ,*body) - (throwf 'match-error "~s: ~s failed to match object ~s" 'match ',pat ,val))))) + (match-pat-error 'match ',pat ,val))))) (defmacro while-match (:form *match-form* :env e pat obj . body) (let ((cm (compile-match pat : (get-var-list e)))) @@ -687,7 +693,7 @@ (with-gensyms (else) ^(match-case ,obj ,*clauses - ((var ,else) (throwf 'match-error "~s: failed to match object ~s" 'match-ecase ,else))))) + ((var ,else) (match-error 'match-ecase ,else))))) (defmacro while-match-case (:form *match-form* :env e obj . clauses) (unless [all clauses [andf proper-listp [chain len plusp]]] |