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
;; aif | |
(define-syntax aif | |
(syntax-rules () | |
((_ var pred then else) | |
(let ((var pred)) | |
(if var then else))) | |
((_ var pred then) | |
(let ((var pred)) | |
(if var pred then))))) | |
(define-syntax aif | |
(syntax-rules () | |
((_ var pred then else) | |
(let ((var pred)) | |
(if var then else))) | |
((_ var pred then) | |
(aif var pred then (undefined))))) | |
(define-syntax aif | |
(syntax-rules () | |
((_ var pred then . else) | |
(let ((var pred)) | |
(if var then . else))))) | |
(define (test n) | |
(aif it (even? n) | |
it | |
'false)) | |
(test 0) | |
;; #t | |
(test 1) | |
;; false | |
(aif it (even? 0) it) | |
;; #t | |
(aif it (even? 1) it) | |
;; #<undef> | |
(define-macro (aif pred then . else) | |
`(let ((it ,pred)) | |
(if it ,then ,@else))) | |
(aif #t it it) | |
;; #t | |
(aif #f it it) | |
;; #f |
acond は scheme だと必要なさそうですね。
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
;; anaphora | |
(define-macro (aif pred then . else) | |
`(let ((it ,pred)) | |
(if it ,then ,@else))) | |
(define-macro (awhen pred . body) | |
`(aif ,pred | |
(begin ,@body))) | |
(define-macro (awhile expr . body) | |
`(do ((it ,expr ,expr)) | |
((not it)) | |
,@body)) | |
(define-macro (aand . args) | |
(cond ((null? args) #t) | |
((null? (cdr args))(car args)) | |
(else `(aif ,(car args)(aand ,@(cdr args)))))) | |
(define-macro (alambda params . body) | |
`(letrec ((self (lambda ,params ,@body))) | |
self)) |
0 件のコメント:
コメントを投稿