Rewritten OPTIONALS macro with SYNTAX-RULES.

This commit is contained in:
interp 2003-07-08 23:07:37 +00:00
parent 3384fdd920
commit e43b8bb2fc
1 changed files with 5 additions and 28 deletions

View File

@ -33,32 +33,9 @@
(cdr pred-list)
args)))))
(define-syntax optionals
(lambda (exp rename compare)
(let ((%receive (rename 'receive))
(%typed-optionals (rename 'typed-optionals))
(%list (rename 'list))
(%if (rename 'if))
(%pair? (rename 'pair?))
(%error (rename 'error))
(%let (rename 'let))
(%list-ref (rename 'list-ref))
(args (cadr exp))
(var-list (caddr exp))
(body (cadddr exp)))
`(,%receive (params rest-args)
(,%typed-optionals (,%list ,@(map cadr var-list)) ,args)
(,%if (pair? rest-args)
(,%error "optionals: too many arguments and/or argument type mismatch"
rest-args)
(,%let (,@(let loop ((counter 0)
(var-list var-list))
(if (null? var-list)
'()
(cons (cons (caar var-list) `((,%list-ref params ,counter)))
(loop (+ 1 counter)
(cdr var-list))))))
,body))))))
(syntax-rules ()
((optionals args ((name pred) ...) body)
(receive (params must-be-empty)
(typed-optionals (list pred ...) args)
(apply (lambda (name ...) body) params)))))