Created
February 17, 2011 07:56
-
-
Save SaitoAtsushi/831264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax let-optionals | |
(syntax-rules () | |
((_ args ((var default) rest ... . restarg) body ...) | |
(let* ((tmp args) | |
(var (if (null? tmp) default (car tmp)))) | |
(let-optionals (if (null? tmp) '() (cdr tmp)) | |
(rest ... . restarg) | |
body ...))) | |
((_ args () body ...) | |
(begin body ...)) | |
((_ args restarg body ...) | |
(let ((restarg args)) | |
body ...)))) | |
(define-syntax let-optionals* | |
(lambda(stx) | |
(define (add-default spec) | |
(syntax-case spec () | |
((var default) #'(var default)) | |
(var #'(var #f)))) | |
(syntax-case stx () | |
((_ args (spec ... . restarg) body0 body1 ...) | |
#`(let-optionals args (#,@(map add-default #'(spec ...)) . restarg) | |
body0 body1 ...))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment