前回
リスト遊び 2-1 アトムとセル - by shigemk2
セルのポインタは2つに構成されており、
左側のポインタをCAR(the Contents of the Address part of a Register)
右側のポインタをCDR(the Contents of the Decrement part of a Register)
と呼ぶ。
そして、セルが纏まったものがリストである。
CARはリストデータ、CDRは次のセルを指す。
セルの集合体がリストであり、リストの終端はnilとなる。
リストの作りかた
consを使う。
(cons 1 nil) => (1) (cons 1 ()) => (1) (cons 1 (cons 2 (cons 3 nil))) => (1 2 3) (atom 1) => t (setq zoo (cons 1 nil)) => (1) ;; アトム判定 (atom zoo) => nil (atom nil) => t ;; セル判定 (consp nil) ;; リスト判定 ;; 空リストでもtが返る (listp nil) => t ;; アトムはもちろん (listp 1) => nil (setq zoo (cons 1 nil)) => (1) (listp zoo) => t (setq zoo (cons 1 (cons 2 (cons 3 nil)))) => (1 2 3) ;; セルのCARが参照しているデータを取得する (car zoo) => 1 ;; セルのCDRが参照しているデータを取得する (cdr zoo) => (2 3)

リスト遊び―Emacsで学ぶLispの世界 (ASCII SOFTWARE SCIENCE Language)
- 作者: 山本和彦
- 出版社/メーカー: アスキー
- 発売日: 2000/05
- メディア: 単行本
- 購入: 2人 クリック: 76回
- この商品を含むブログ (44件) を見る