improved ASSERT interface

This commit is contained in:
Rolf-Thomas Happe 2003-03-19 21:42:21 +00:00
parent 85539d1d46
commit 9ef33b4651
2 changed files with 18 additions and 22 deletions

View File

@ -6,7 +6,7 @@ The structure SRFI-1+ extends the list lib with REST := CDR. [ I dearly
like (FIRST . REST) lists and (CAR . CDR) trees. ] like (FIRST . REST) lists and (CAR . CDR) trees. ]
* *
structure SRFI-9+ -- SRFI-9 + DEFINE-RECORD-DISCLOSER structure SRFI-9+ -- SRFI-9 + DEFINE-RECORD-DISCLOSER
The structure SRFI-9+ extends SRFI-9 by the convenient record disclosing The structure SRFI-9+ extends SRFI-9 by the convenient record disclosing
@ -20,8 +20,8 @@ just as SRFI-9.
(define-record-discloser rt d) --> unspecified PROCEDURE (define-record-discloser rt d) --> unspecified PROCEDURE
just as DEFINE-RECORD-TYPES: Install the procedure D : rt -> list just as DEFINE-RECORD-TYPES: Install the procedure D : rt -> list
as discloser for records of type RT where RT has been defined with as discloser for records of type RT where RT has been defined with
DEFINE-RECORD-TYPE (from above) and D maps its input record to a DEFINE-RECORD-TYPE (from above) and D maps its input record to a
printable list starting with a symbol. printable list starting with a symbol.
* *
@ -29,27 +29,26 @@ printable list starting with a symbol.
structure KRIMS -- Odds and Ends structure KRIMS -- Odds and Ends
The structure KRIMS gathers miscellaneous tiny utilities mainly for use The structure KRIMS gathers miscellaneous tiny utilities mainly for use
of other sunterlib projects. of other sunterlib projects.
(assert [id] exp) SYNTAX (assert exp x0 ...) SYNTAX
The usual ASSERT macro with an optional ID tag: Signal an error and Signal an error if EXP is false, reporting both the failed assertion EXP
complain if EXP evaluates to false. The error message contains the (literally) and the values of X0 ... Don't evaluate X0 ... if EXP holds
value of ID (if supplied) and the expression EXP. [ ASSERT being a true.
macro, we can change it to the trivial form that doesn't evaluate its
arguments and recompile before selling our stuff ... ]
* *
(receive/name loop formals exp form0 ...) SYNTAX (receive/name loop formals exp form0 ...) SYNTAX
RECEIVE/NAME is a multi-values analogue of named LET (but much less RECEIVE/NAME is a multi-values analogue of named LET (but much less
useful) that helps when chaining n-valued n-ary functions, for instance. useful) that helps when chaining n-valued n-ary functions, for instance.
Synopsis: Bind LOOP to a macro wrapped around the procedure LUP with Synopsis: Bind LOOP to a macro wrapped around the procedure LUP with
parameter list FORMALS and body FORM0 ... so that parameter list FORMALS and body FORM0 ... so that
* (LOOP multi-valued-expression) calls LUP with the values of * (LOOP multi-valued-expression) calls LUP with the values of
multi-valued-expression , and multi-valued-expression , and
* (LOOP exp0 ...) becomes (LUP exp0 ...) * (LOOP exp0 ...) becomes (LUP exp0 ...)
@ -60,7 +59,7 @@ Semantics: (A special case is good enough.)
Assuming the LOOP tag isn't shadowed in the context `...' Assuming the LOOP tag isn't shadowed in the context `...'
(receive/name loop (x y) exp0 (receive/name loop (x y) exp0
... (loop exp1) ...) ... (loop exp1) ...)
is eqv to is eqv to
(receive (x y) exp0 (receive (x y) exp0
(let lup ((x x) (y y)) (let lup ((x x) (y y))
@ -69,7 +68,7 @@ is eqv to
and (receive/name loop (x y) exp0 and (receive/name loop (x y) exp0
... (loop exp1 exp1) ...) ... (loop exp1 exp1) ...)
is eqv to is eqv to
(receive (x y) exp0 (receive (x y) exp0
(let lup ((x x) (y y)) (let lup ((x x) (y y))
... (lup exp1 exp2) ...)) ... (lup exp1 exp2) ...))
@ -77,7 +76,7 @@ is eqv to
Example: Example:
(define (shove n xs) (values (- n 1) (cons n xs))) (define (shove n xs) (values (- n 1) (cons n xs)))
(receive/name loop (n xs) (values 7 '()) (receive/name loop (n xs) (values 7 '())
(if (= n 0) (if (= n 0)
(display xs) (display xs)
(loop (shove n xs)))) (loop (shove n xs))))
@ -86,8 +85,8 @@ Example:
(gen-dispatch ((predicate action) ...) e0 e1 ... en) SYNTAX (gen-dispatch ((predicate action) ...) e0 e1 ... en) SYNTAX
Dispatch action on type of first argument E0: feed E0 ... EN to the Dispatch action on type of first argument E0: feed E0 ... EN to the
first action such that the PREDICATE holds for E0. Signal an error first action such that the PREDICATE holds for E0. Signal an error
if nothing goes. if nothing goes.
Example: Example:

View File

@ -4,11 +4,8 @@
(define-syntax assert (define-syntax assert
(syntax-rules () (syntax-rules ()
((assert ?x) ((assert ?x ?y0 ...)
(if (not ?x) (error "Assertion failed" '?x))) (if (not ?x) (error "Assertion failed" '?x ?y0 ...))) ))
((assert ?tag ?x)
(if (not ?x) (error (format #f "~a -- assertion failed" ?tag)
'?x)))))
;; RECEIVE/NAME is a multiple values analogue of named LET. ;; RECEIVE/NAME is a multiple values analogue of named LET.