2008年1月6日日曜日

Chapter 11 Collections

前説

Ontogeny recapitulates phylogeny.

固体発生は系統発生を繰り返す、例えば受精から出産までの胎児の成長過程(単純な細胞から人間として形成される過程)は、原始の細胞からシンプルな生物を経て人間にいたる系統進化の過程と同じということ。科学的な話ではなかったはずです。

ここでは、Lispの系統発生的過程を、個々のLisp教育過程でくりかえす、ということかな。


Vectors

"the effects of modifying literal objects aren't defined." がわからない。
#(1 2 3)などでベクターObjectを生成したときは、それを変更するとどうなるかは定義されていないのか?

CL-USER> (let ((x #(1 2 3)))
(setf (elt x 0) 10)
x)
#(10 2 3)
CL-USER>

aclでは問題ないようだ。ま、深掘りすることじゃないか。


Subtypes of Vector

fill-pointerを試す。

CL-USER> (make-array 5 :fill-pointer 0)
#()
CL-USER> (make-array 5 :fill-pointer 1)
#(NIL)
CL-USER> (make-array 5 :fill-pointer 2)
#(NIL NIL)
CL-USER> (make-array 2 :fill-pointer 2)
#(NIL NIL)
CL-USER> (make-array 2 :fill-pointer 3)
; Evaluation aborted.
CL-USER> (make-array 0)
#()
CL-USER> (make-array 0 :fill-pointer 0)
#()

なる。"it's the index of the next position"

:adjustableについて。

CL-USER> (defparameter *v* (make-array 2 :fill-pointer 0 :adjustable t))
*V*
CL-USER> (vector-push 1 *v*)
0
CL-USER> (vector-push 2 *v*)
1
CL-USER> (vector-push 3 *v*)
NIL
CL-USER> (length *v*)
2
CL-USER> (vector-push-extend 3 *v*)
2
CL-USER> (length *v*)
3
CL-USER> *v*
#(1 2 3)
CL-USER> (vector-pop *v*)
3
CL-USER> *v*
#(1 2)
CL-USER> (vector-push 3 *v*)
2
CL-USER> *v*
#(1 2 3)
CL-USER> (defparameter *v* (make-array 1 :fill-pointer 0 :adjustable t))
*V*
CL-USER> *v*
#()
CL-USER> (vector-push-extend 1 *v*)
0
CL-USER> *v*
#(1)
CL-USER> (vector-push 2 *v*)
NIL
CL-USER> *v*
#(1)
CL-USER>

なる。


Vectors As Sequences
Sequence Iterating Functions
Higher-Order Function Variants
Whole Sequence Manipulations

特になし。


Sorting and Merging

うーん。なぜdestructiveなのに、

(setf my-sequence (sort my-sequence #'string<))

とsetfする方がよいと言うのだ。納得いかない。


Subsequence Manipulations
Sequence Predicates
Sequence Mapping Functions
Hash Tables
Hash Table Iteration

特になし。

0 件のコメント: