Created
March 9, 2020 09:22
-
-
Save chuntaro/1062a6be47f8f63432a7df2e353a45d9 to your computer and use it in GitHub Desktop.
dolist マクロの実装内容によって結果が違う例
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
(let (cs) | |
(dolist (x '(1 2 3 4 5)) | |
(push #'(lambda () x) cs)) | |
(mapcar #'funcall cs)) | |
;;=> (5 4 3 2 1) | |
;; 展開後 (こんな感じになる) | |
(let ((ls '(1 2 3 4 5)) | |
cs) | |
(while ls | |
(let ((x (car ls))) | |
(push (lambda () x) cs) | |
(setq ls (cdr ls)))) | |
(mapcar #'funcall cs)) | |
;; => (5 4 3 2 1) | |
;; 処理系によっては以下のように展開される場合がある | |
(let ((ls '(1 2 3 4 5)) | |
x | |
cs) | |
(while ls | |
(setq x (car ls)) | |
(push (lambda () x) cs) | |
(setq ls (cdr ls))) | |
(mapcar #'funcall cs)) | |
;; => (5 5 5 5 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment