gensymはgenerate symbolでしょうか。
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
;; or | |
;; http://www.sampou.org/scheme/t-y-scheme/t-y-scheme-Z-H-10.html#node_chap_8 | |
(define-macro (my-or x y) | |
`(if ,x ,x ,y)) | |
(my-or 1 2) | |
; -> 1 | |
(my-or #f 2) | |
; -> 2 | |
(macroexpand '(my-or 1 2)) | |
; -> (if 1 1 2) | |
(macroexpand '(my-or #f 2)) | |
; -> (if #f #f 2) | |
(my-or (begin | |
(display "doing first argument") | |
(newline) | |
#t) | |
2) | |
;; doing first argument | |
;; doing first argument | |
;; #t | |
(macroexpand '(my-or (begin | |
(display "doing first argument") | |
(newline) | |
#t) | |
2)) | |
; -> (if #0=(begin (display "doing first argument") (newline) #t) #0# 2) | |
(define-macro (my-or x y) | |
`(let ((temp ,x)) | |
(if temp temp ,y))) | |
(my-or (begin | |
(display "doing first argument") | |
(newline) | |
#t) | |
2) | |
;; doing first argument | |
;; #t | |
(macroexpand '(my-or (begin | |
(display "doing first argument") | |
(newline) | |
#t) | |
2)) | |
;; (let ((temp (begin (display "doing first argument") (newline) #t))) (if temp temp 2)) | |
(define temp 3) | |
(my-or #f temp) | |
; -> #f | |
(my-or #t temp) | |
; -> #t | |
(macroexpand '(my-or #f temp)) | |
; -> (let ((temp #f)) (if temp temp temp)) | |
(define-macro (my-or x y) | |
`(let ((+temp ,x)) | |
(if +temp +temp ,y))) | |
(my-or #f temp) | |
; -> 3 | |
(macroexpand '(my-or #f temp)) | |
; -> (let ((|+temp| #f)) (if |+temp| |+temp| temp)) | |
(define-macro (my-or x y) | |
(let ((temp (gensym))) | |
`(let ((,temp ,x)) | |
(if ,temp ,temp ,y)))) | |
(my-or #f temp) | |
; -> 3 | |
(macroexpand `(my-or #f temp)) | |
; -> (let ((#0=#:G3 #f)) (if #0# #0# temp)) | |
0 件のコメント:
コメントを投稿