Make LET-MATCH/IF-MATCH conform to documentation & comments.

In the process, rewrite LET-MATCH as a SYNTAX-RULES macro.
This commit is contained in:
sperber 2002-12-17 13:33:33 +00:00
parent 465e012cf8
commit aa1481450d
1 changed files with 11 additions and 27 deletions

View File

@ -11,34 +11,18 @@
;;; of blowing up, we execute the ALT form instead.
(define-syntax let-match
(lambda (exp r c)
(if (< (length exp) 3)
(error "No match-vars list in LET-MATCH" exp))
(let ((m (cadr exp)) ; The match expression
(mvars (caddr exp)) ; The match vars
(body (cdddr exp)) ; The expression's body forms
(syntax-rules ()
((let-match ?match-exp (?mvars ...) ?body0 ?body ...)
(let ((?match-var ?match-exp))
(let-match-aux ?match-var 0 (?mvars ...) ?body0 ?body ...)))))
(%begin (r 'begin))
(%match:substring (r 'match:substring))
(%let* (r 'let*)))
(cond ((null? mvars) `(,%begin ,@body))
((pair? mvars)
(let* ((msv (or (car mvars) (r 'match-val))) ; "match-struct var"
(sm-bindings (let recur ((i 0) (vars (cdr mvars)))
(if (pair? vars)
(let ((var (car vars))
(bindings (recur (+ i 1) (cdr vars))))
(if var
(cons `(,var (,%match:substring ,msv ,i))
bindings)
bindings))
'()))))
`(,%let* ((,msv ,m) ,@sm-bindings) ,@body)))
(else (error "Illegal match-vars list in LET-MATCH" mvars exp))))))
(define-syntax let-match-aux
(syntax-rules ()
((let-match-aux ?match-var ?i0 (?mvar0 ?mvars ...) ?body0 ?body ...)
(let ((?mvar0 (match:substring ?match-var ?i0)))
(let-match-aux ?match-var (+ 1 ?i0) (?mvars ...) ?body0 ?body ...)))
((let-match-aux ?match-var ?i0 () ?body0 ?body ...)
(begin ?body0 ?body ...))))
(define-syntax if-match
(syntax-rules ()