Created
January 27, 2014 15:56
-
-
Save SaitoAtsushi/8651148 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
#!r6rs | |
;; petite chez scheme と ypsilon で挙動が異なる | |
(library (bound) | |
(export if-bound bound?) | |
(import (rnrs)) | |
(define-syntax if-bound | |
(lambda(stx) | |
(syntax-case stx () | |
((_ id consequent) | |
#'(if-bound id consequent (begin))) | |
((_ id consequent alternate) | |
(not | |
(free-identifier=? | |
(datum->syntax #'k (syntax->datum #'id)) | |
#'id)) | |
#'consequent) | |
((_ id consequent alternate) | |
#'alternate)))) | |
(define-syntax bound? | |
(syntax-rules () | |
((_ id) | |
(if-bound id #t #f)))) | |
) |
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
#!r6rs | |
(import (rnrs) (bound)) | |
(display (bound? sin)) | |
(display (bound? lambda)) | |
(display (bound? syntax)) | |
(display (bound? hoge)) | |
(newline) | |
;; この定義の有無で以降の場合分け処理が分岐する | |
;; (define hige "This is hige.\n") | |
(if-bound hige | |
(display "hige was bound.\n") | |
(begin | |
(display "hige was not bound.\n") | |
(define hige "This is alternate hige.\n"))) | |
(display hige) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment