読者です 読者をやめる 読者になる 読者になる

by shigemk2

当面は技術的なことしか書かない

loop1

Emacs Lisp
;; 1-5のリストを得る
(loop for i from 1 to 5
      collect i)			; => (1 2 3 4 5)
;; 1-5の二乗のリストを得る
(loop for i from 1 to 5
      collect (* i i))			; => (1 4 9 16 25)
;; リストの各要素をエコーエリアに表示する
(loop for x in '(3 9 6)
      do (princ x))			; 396nil
;; dolist+mapcar+destructuring-bind
(loop for (x . y) in '((1 . 2) (3 . 4) (5 . 6))
      collect (+ x y))			; => (3 7 11)
;; 全バッファのバッファ名を得る
(loop for buf in (buffer-list)
      collect (buffer-name buf))	; バッファ名がずらり

(loop for i from 1 to 5 collect i)	; => (1 2 3 4 5)
(loop for i from 1 below 5 collect i)	; => (1 2 3 4)
(loop for i from 1 to 5 by 2 collect i)	; => (1 3 5)
(loop for i from 1 below 5 by 2 collect i) ; => (1 3)
(loop for i from 1 downto -3 collect i)	   ; => (1 0 -1 -2 -3)
(loop for i from 1 above -3 collect i)	   ; => (1 0 -1 -2)
(loop for i from 1 downto -3 by 2 collect i) ; => (1 -1 -3)
(loop for i from 1 above -3 by 2 collect i)  ; => (1 -1)

P213

Emacs Lispテクニックバイブル

Emacs Lispテクニックバイブル