Improve run-time error reporting in (ice-9 match).
authorMark H Weaver <mhw@netris.org>
Thu, 15 Aug 2013 07:59:15 +0000 (03:59 -0400)
committerMark H Weaver <mhw@netris.org>
Thu, 15 Aug 2013 08:07:55 +0000 (04:07 -0400)
* module/Makefile.am: match.go depends on match.upstream.scm.

* module/ice-9/match.scm (error): Accept any number of arguments.

* module/ice-9/match.upstream.scm (match-next): Call 'error' in non-tail
  context, and include the value that failed to match in the call.

module/Makefile.am
module/ice-9/match.scm
module/ice-9/match.upstream.scm

index d43be04..e8dcd4a 100644 (file)
@@ -33,6 +33,7 @@ EXTRA_DIST += ice-9/eval.scm
 ETAGS_ARGS += ice-9/eval.scm
 
 ice-9/boot-9.go: ice-9/boot-9.scm ice-9/quasisyntax.scm ice-9/r6rs-libraries.scm
+ice-9/match.go: ice-9/match.scm ice-9/match.upstream.scm
 
 # We can compile these in any order, but it's fastest if we compile
 # psyntax and boot-9 first, then the compiler itself, then the rest of
index 7fd191a..099afb5 100644 (file)
@@ -24,9 +24,9 @@
             match-let*
             match-letrec))
 
-(define (error _ msg)
+(define (error _ . args)
   ;; Error procedure for run-time "no matching pattern" errors.
-  (throw 'match-error "match" msg))
+  (apply throw 'match-error "match" args))
 
 ;; Support for record matching.
 
index 29f9dbe..4609883 100644 (file)
   (syntax-rules (=>)
     ;; no more clauses, the match failed
     ((match-next v g+s)
-     (error 'match "no matching pattern"))
+     ;; Here we wrap error within a double set of parentheses, so that
+     ;; the call to 'error' won't be in tail position.  This allows the
+     ;; backtrace to show the source location of the failing match form.
+     ((error 'match "no matching pattern" v)))
     ;; named failure continuation
     ((match-next v g+s (pat (=> failure) . body) . rest)
      (let ((failure (lambda () (match-next v g+s . rest))))