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
;; when, unless, macroexpand | |
;; http://www.sampou.org/scheme/t-y-scheme/t-y-scheme-Z-H-10.html#node_chap_8 | |
;; when | |
(define-macro my-when | |
(lambda (test . branch) | |
(list 'if test | |
(cons 'begin branch)))) | |
;; quasiquote, unquote, unquote-splicing | |
(define-macro my-when | |
(lambda (test . branch) | |
`(if ,test | |
(begin ,@branch)))) | |
((lambda (x) | |
(my-when (> x 5) | |
(display "ok") | |
(newline) | |
(display x) | |
(newline))) 6) | |
;; ok | |
;; 6 | |
;; #<undef> | |
(macroexpand '((lambda (x) | |
(my-when (> x 5) | |
(display "ok") | |
(newline) | |
(display x) | |
(newline))) 6)) | |
; -> ((lambda (x) (my-when (> x 5) (display "ok") (newline) (display x) (newline))) 6) | |
;; unless | |
(define-macro my-unless | |
(lambda (test . branch) | |
(list 'if (list 'not test) | |
(cons 'begin branch)))) | |
;; quasiquote, unquote, unquote-splicing | |
(define-macro my-unless | |
(lambda (test . branch) | |
`(if (not ,test) | |
(begin ,@branch)))) | |
((lambda (x) | |
(my-unless (> x 5) | |
(display "ok") | |
(newline) | |
(display x) | |
(newline))) 3) | |
;; ok | |
;; 3 | |
;; #<undef> | |
(macroexpand '((lambda (x) | |
(my-unless (> x 5) | |
(display "ok") | |
(newline) | |
(display x) | |
(newline))) 3)) | |
; -> ((lambda (x) (my-unless (> x 5) (display "ok") (newline) (display x) (newline))) 3) |
0 件のコメント:
コメントを投稿