From bde362af97359c57f4bf1d94ee348f0c05a86e49 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 9 Jan 2017 08:36:23 -0800 Subject: [PATCH] more vigorous type checking --- txexpr/base.rkt | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/txexpr/base.rkt b/txexpr/base.rkt index cab6beb..ffc67d0 100644 --- a/txexpr/base.rkt +++ b/txexpr/base.rkt @@ -150,18 +150,17 @@ (define+provide+safe (txexpr tag [attrs null] [elements null]) ((symbol?) (txexpr-attrs? txexpr-elements?) . ->* . txexpr?) + (unless (txexpr-tag? tag) + (error 'txexpr (format "This is not a txexpr-tag: ~v" tag))) + (unless (txexpr-attrs? attrs) + (error 'txexpr (format "This is not a list of txexpr-attrs: ~v" attrs))) + (unless (txexpr-elements? elements) + (error 'txexpr (format "This is not a list of txexpr-elements: ~v" elements))) + (define result (cons tag (append (if (empty? attrs) empty (list attrs)) elements))) - (if (txexpr? result) - result - (error 'txexpr - (cond - [(not (txexpr-tag? tag)) - (format "This is not a txexpr-tag: ~v" tag)] - [(not (txexpr-attrs? attrs)) - (format "This is not a list of txexpr-attrs: ~v" attrs)] - [(not (txexpr-elements? elements)) - (format "This is not a list of txexpr-elements: ~v" elements)] - [else ""])))) + (unless (txexpr? result) + (error 'txexpr "not a txexpr")) + result) (define+provide+safe (txexpr* tag [attrs null] . elements)