配列
Type: Accessor
Arguments: aref ARRAY &rest SUBSCRIPTS
Package: lisp
File: builtin.l
SUBSCRIPTS で特定される配列の要素にアクセスします。SUBSCRIPTS がなく配列が
ゼロ次元の場合は、配列のただひとつの要素にアクセスします。
具体的な使い方については、以下の例を参照してください。
使用例:
;;; 2x2の初期化された配列を作ります。値の取得・変更を行います。
(setf foo (make-array '(2 2) :initial-contents '((1 2) (3 4))))
=>#2A((1 2) (3 4))
(aref foo 1 1);配列fooの要素(1,1)の値を得る
=>4
(setf (aref foo 1 1) 10);配列fooの要素(1,1)の値を10にする
=>10
foo
=>#2A((1 2) (3 10))
SeeAlso: make-array
SeeAlso: setf
SeeAlso: svref
Type: Function
Arguments: make-array DIMENSIONS &rest REST &key (element-type t) (initial-element () ies-p) (initial-contents () ics-p) fill-pointer adjustable displaced-to (displaced-index-offset 0)
Package: lisp
File: array.l
DIMENSIONS で示される大きさ・次元の配列をつくり、それを値として返します。
もし、DIMENSIONS が nil なら、ゼロ次元配列がつくられます。
たとえば、変数 hoge を4次元の配列(=4次元のベクトル)にするためには、
(setf hoge (make-array 4))
=> #(nil nil nil nil)
変数 foo を2x4次元の配列とするためには、
(setf foo (make-array '(2 4)))
=> #2A((nil nil nil nil) (nil nil nil nil))
とします。
:element-type は、新しい配列の各要素の型を規定します。
:initial-element が与えられている場合、新しい配列の全要素はすべて
:initial-element に初期化されます。これに対して、:initial-contents が与えら
れている場合、新しい配列の各要素が :initial-contents で初期化されます。
たとえば、
(make-array '(2 4) :initial-element 10); 2x4の配列をつくる。:initial-elementで初期化
=> #2A((10 10 10 10) (10 10 10 10))
(make-array '(2 4)
:initial-contents '((0 1 2 3) (3 2 1 0))); 2x4の配列をつくる。:initial-contentsで初期化
=> #2A((0 1 2 3) (3 2 1 0))
なお、配列の要素にアクセスするためには、 aref が使われます。
SeeAlso: aref
SeeAlso: setf
Type: Function
Arguments: make-vector LENGTH &key (element-type t) (initial-element () ies-p) (initial-contents () ics-p) fill-pointer adjustable displaced-to (displaced-index-offset 0)
Package: lisp
File: array.l
指定した長さのベクタを返します。
使用例:
;;; 長さが10のベクタを作ります。
(make-vector 10)
=> #(nil nil nil nil nil nil nil nil nil nil)
;;; :element-typeにcharacterを指定すると文字列が作成できる
(make-vector 10 :element-type 'character)
=> "^@^@^@^@^@^@^@^@^@^@"
Type: Accessor
Arguments: svref SIMPLE-VECTOR INDEX
Package: lisp
File: builtin.l
aref と同じですが、 svref はベクトル(一次元配列)のみにアクセスできます。つ
まり、ベクトル hoge があるとき、 (svref hoge 2) は( aref hoge 2) と同じ意味で
す。ただし、 foo が2x2配列の場合は、 svref でアクセスすることはできません。
SeeAlso: aref
SeeAlso: setf
SeeAlso: vector
Type: Function
Arguments: vector &rest LIST
Package: lisp
File: array.l
要素 LIST からなるベクトルをつくります。
(setf v (vector 1 2 "oop"))
=>#(1 2 "oop")
ベクトルの各要素にアクセスするためには、svref(あるいはaref)が使われます。
SeeAlso: svref
SeeAlso: aref
SeeAlso: setf
SeeAlso: make-array
Type: Function
Arguments: vector-push-extend NEW-ELEMENT VECTOR &optional EXTENSION
Package: lisp
File: builtin.l
ベクタに新しい要素を追加します。長さが足りなければ拡張します。
NEW-ELEMENT:新しい要素
VECTOR :追加するベクタ
EXTENSION :拡張するかどうか
使用例:
;;; 文字を要素とする長さ10のベクタを作成し文字を詰める。
(setq *stream* (make-vector 10 :element-type 'character
:fill-pointer 0 :adjustable t))
=> ""
(vector-push-extend #\a *stream*) => 0
*stream* => "a"
(vector-push-extend #\b *stream*) => 1
*stream* => "ab"
;;; 文字を要素とする長さ10のベクタを作成し文字を詰める。
(setq s (make-vector 10 :element-type 'character
:fill-pointer 0 :adjustable t))
=> ""
(dotimes (i 20)
(vector-push-extend (code-char (+ 64 i)) s)
(vector-push-extend (code-char (+ 64 i)) s)
(vector-push-extend (code-char (+ 64 i)) s))
=> "@@@AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLLLMMMNNNOOOPPPQQQRRRSSS"
SeeAlso: vector