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
(define-macro (aif test-form then-form . else-form) | |
`(let ((it ,test-form)) | |
(if it ,then-form ,@else-form))) | |
(define-macro (aand . args) | |
(cond ((null? args) #t) | |
((null? (cdr args))(car args)) | |
(else `(aif ,(car args) (aand ,@(cdr args)))))) | |
(aand (string-scan "aaa.el" ".elc" 'after) | |
(string=? it "")) | |
;; #<undef> | |
(macroexpand '(aand (string-scan "aaa.el" ".elc" 'after) | |
(string=? it "") "not found")) | |
(let ((it (string-scan "aaa.el" ".elc" 'after))) | |
(if it | |
(let ((it (string=? it ""))) | |
(if it | |
"not found")))) |
まともに使うにはこうでしょうか。。
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
(define-macro (aand . args) | |
(cond ((null? args)) | |
((null? (cdr args))(car args)) | |
(else `(if-let1 it ,(car args) | |
(aand ,@(cdr args)) | |
#f)))) | |
(aand (string-scan "aaa.el" ".elc" 'after) | |
(string=? it "")) | |
;; #f |
というか、gauche を使っているので、and-let* を使った方が無難なようです。。
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
(and-let* ((it (string-scan "aaa.el" ".elc" 'after)) | |
(it (string=? it ""))) | |
it) |
0 件のコメント:
コメントを投稿