| 1 |
#!r6rs |
| 2 |
;; Copyright 2010 Derick Eddington. My MIT-style license is in the file named |
| 3 |
;; LICENSE from the original collection this file is distributed with. |
| 4 |
|
| 5 |
(library (srfi :23 error tricks) |
| 6 |
(export |
| 7 |
SRFI-23-error->R6RS) |
| 8 |
(import |
| 9 |
(rnrs)) |
| 10 |
|
| 11 |
(define-syntax error-wrap |
| 12 |
(lambda (stx) |
| 13 |
(syntax-case stx () |
| 14 |
((_ ctxt signal . forms) |
| 15 |
(with-syntax ((e (datum->syntax #'ctxt 'error))) |
| 16 |
#'(let-syntax ((e (identifier-syntax signal))) |
| 17 |
. forms)))))) |
| 18 |
|
| 19 |
(define (AV who) |
| 20 |
(lambda args (apply assertion-violation who args))) |
| 21 |
|
| 22 |
(define-syntax SRFI-23-error->R6RS |
| 23 |
(lambda (stx) |
| 24 |
(syntax-case stx () |
| 25 |
((ctxt ewho . forms) |
| 26 |
(with-syntax ((e (datum->syntax #'ctxt 'error)) |
| 27 |
(d (datum->syntax #'ctxt 'define))) |
| 28 |
#'(let-syntax ((e (identifier-syntax (AV 'ewho))) |
| 29 |
(d (lambda (stx) |
| 30 |
(syntax-case stx () |
| 31 |
((kw (id . formals) . body) |
| 32 |
(identifier? #'id) |
| 33 |
#'(error-wrap kw (AV 'id) |
| 34 |
(d (id . formals) . body))) |
| 35 |
((kw id . r) |
| 36 |
(identifier? #'id) |
| 37 |
#'(error-wrap kw (AV 'id) |
| 38 |
(d id . r))))))) |
| 39 |
. forms)))))) |
| 40 |
) |