Function TYPEP
typep object type-specifier &optional environment => generalized-boolean
object - オブジェクト
type-specifier - 型指定子ですが、 valuesと 最初の要素がfunctionかvaluesの リストは除きます。
environment - 環境オブジェクト。 デフォルトはnilであり、 これはnullのレキシカルな環境の現在のグローバルな環境を示します。
generalized-boolean - generalized-boolean
もしobjectがtype-specifierによって指定された型のときはtrueを、 それ以外はfalseを返却します。
type-specifierが(satisfies fn)フォームのときは、 関数fnをobjectで適用することで返却します。
式(typep object '(array type-specifier))の type-specifierが*ではないときは、 objectがmake-array関数の :element-typeの引数にtype-specifierが指定されて 生成された配列であるときにtrueを返却します。 (array *)は要素の型に関係せず全ての配列を意味し、 (array type-specifier)はただmake-array関数の :element-typeの引数にtype-specifierが指定されて 生成された配列のみを意味します。 似たような解釈として、 (simple-array type-specifier)と(vector type-specifier)にも 適用されます。 詳しくは15.1.2.1. 配列のアップグレードをご確認ください。
式(typep object '(complex type-specifier)は、 complex関数に type-specifier型の数を与えた返却値による複素数か、 加えて同じspecializedの表現の数を持った 複素数のときにtrueを返却します。 そのような複素数は、実部と虚部の両方で次の式が満たされなければなりません。
(typep realpart 'type-specifier)
(typep imagpart 'type-specifier)upgraded-complex-part-type関数をご確認ください。
(typep 12 'integer) => true
(typep (1+ most-positive-fixnum) 'fixnum) => false
(typep nil t) => true
(typep nil nil) => false
(typep 1 '(mod 2)) => true
(typep #c(1 1) '(complex (eql 1))) => true次の例を理解するには12.1.5.3. rational型の複素数の標準的な表現のルールを参照してください。
(typep #c(0 0) '(complex (eql 0))) => falseAxとAyの2つの型指定子は違う型ですが、
(upgraded-array-element-type 'Ax)と
(upgraded-array-element-type 'Ay)はどちらも同じ型を示しているものとします。 このとき、下記のようになることに注意してください。
(typep (make-array 0 :element-type 'Ax) '(array Ax)) => true
(typep (make-array 0 :element-type 'Ay) '(array Ay)) => true
(typep (make-array 0 :element-type 'Ax) '(array Ay)) => true
(typep (make-array 0 :element-type 'Ay) '(array Ax)) => trueなし。
もしtype-specifierがvaluesか、 あるいは最初の要素がfunctionか valuesのリストのときは、 型errorのエラーが発生します。
type-specifierが型指定子ではないときの結果は未定義です。
type-of, upgraded-array-element-type, upgraded-complex-part-type, 4.2.3. 型指定子
実装は、(typep x (the class y))のような式の場合は、 実行時にdeftypeによる展開の実行が必要無いように 最適化を行うよう推奨されます。