Created
June 2, 2010 07:22
-
-
Save cametan001/422057 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 bind-variables | |
| (syntax-rules () | |
| ((_ () form ...) | |
| (begin form ...)) | |
| ;; ここはオリジナルの syntax-error がどんな挙動か分からないので割愛 | |
| ;; error で置き換えてみたが、本体に form ... が無い、と怒られた | |
| ;; ((_ ((var val0 val1 ...) ...) form ...) | |
| ;; (error "bind-variables illegal binding" (var val0 val1 ...))) | |
| ((_ ((var val) more-bindings ...) form ...) | |
| (let ((var val)) (bind-variables (more-bindings ...) form ...))) | |
| ((_ ((var) more-bindings ...) form ...) | |
| (let ((var #f)) (bind-variables (more-bindings ...) form ...))) | |
| ((_ (var more-bindings ...) form ...) | |
| ;; ここは、本当は上のパターンに差し替えたほうが綺麗かも | |
| (let ((var #f)) (bind-variables (more-bindings ...) form ...))) | |
| ((_ bindings form ...) | |
| (error "Bindings must be a list." bindings)) | |
| )) | |
| ;; ;; 実行例 | |
| ;; > (bind-variables ((a 1) | |
| ;; (b) | |
| ;; c | |
| ;; e | |
| ;; (d (+ a 3))) | |
| ;; (list a b c d e)) | |
| ;; (1 #f #f 4 #f) | |
| ;; > (let ((a 1)) | |
| ;; (bind-variables ((b) | |
| ;; c | |
| ;; e | |
| ;; (d (+ a 3))) | |
| ;; (list a b c d e))) | |
| ;; (1 #f #f 4 #f) | |
| ;; > (let ((a 1)) | |
| ;; (let ((b #t)) | |
| ;; (bind-variables (c | |
| ;; e | |
| ;; (d (+ a 3))) | |
| ;; (list a b c d e)))) | |
| ;; (1 #t #f 4 #f) | |
| ;; > (bind-variables (a b c d e) | |
| ;; (list a b c d e)) | |
| ;; (#f #f #f #f #f) | |
| ;; > (bind-variables ((a) (b) (c) (d) (e)) | |
| ;; (list a b c d e)) | |
| ;; (#f #f #f #f #f) | |
| ;; > (bind-variables (a (b 1) (c 2) d (e)) | |
| ;; (list a b c d e)) | |
| ;; (#f 1 2 #f #f) | |
| ;; > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment