あろえの備忘録

移転しました http://blog.vitamin11.org/

Lisp写経 2回目

ベクタの作成
vector, make-arrayで作成できる
(vector 1 2 3) → #(1 2 3)
(make-array 5 :initial-element 1 :fill-pointer 0) -> #(1 1 1 1 1)


vectorで作成したベクタはvector-pop, vector-pushで変更できない。
make-arrayに:fill-pointerオプションを指定するとvector-pop, vector-pushで要素の変更が可能なベクタを作成できる。
#(1 2 3)とリテラル表記でもベクタは作成できるが、リテラルオブジェクトを変更した場合の処理は定義されてないので変更すべきではないらしい。

可変サイズのベクタを作成するにはmake-arrayで:adjustable tを追加する。
vector-push-extendを使用する。vector-pushと違い要素が一杯の場合は自動的に領域を拡張する

fill-pointerが設定されていなくてもeltで要素を指定してsetfすることができる
(defvar *x* #(1 2 3))
(setf (elt *x* 1) 20) → #(1 20 3)



EmacsだからなのかSlime環境だからかはわからないが、ミニバッファに関数の取れる引数が表示されることに今ごろ気づいた
こんな感じ
(make-array arg0 &key adjustable element-type initial-element initial-contents 
       fill-pointer displaced-to displaced-index-offset)

Lisp写経 文字と数字の関数Lisp シーケンス操作関数の続き

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies