Skip to content

Instantly share code, notes, and snippets.

@chuntaro
Created March 9, 2020 09:22
Show Gist options
  • Save chuntaro/1062a6be47f8f63432a7df2e353a45d9 to your computer and use it in GitHub Desktop.
Save chuntaro/1062a6be47f8f63432a7df2e353a45d9 to your computer and use it in GitHub Desktop.
dolist マクロの実装内容によって結果が違う例
(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