データ型
type: Function
arguments: alpha-char-p CHAR
package: lisp
file: builtin.l
文字が英字[A-Za-z]かどうかを判定します。
CHAR : 判定する文字
seealso: both-case-p
seealso: alphanumericp
seealso: characterp
type: Function
arguments: alphanumericp CHAR
package: lisp
file: builtin.l
文字が英数字[A-Za-z0-9]かどうかを判定します。
CHAR : 判定する文字
seealso: alpha-char-p
seealso: characterp
type: Function
arguments: arrayp OBJECT
package: lisp
file: builtin.l
OBJECT が array なら t 、それ以外なら nil を返します。
type: Function
arguments: atom OBJECT
package: lisp
file: builtin.l
OBJECTがconsでなければt、それ以外ならnilを返します。
(atom x) == (typep x 'atom) == (not (typep x 'cons))
注意:(atom '()) は '() == nilなのでt
seealso: consp
type: Function
arguments: characterp OBJECT
package: lisp
file: builtin.l
OBJECT が character なら t 、それ以外なら nil を返します。
seealso: alpha-char-p
seealso: alphanumericp
seealso: digit-char-p
seealso: kana-char-p
seealso: kanji-char-p
seealso: standard-char-p
seealso: extended-alphabet-char-p
seealso: word-char-p
type: Macro
arguments: check-type PLACE TYPESPEC &optional STRING
package: lisp
file: condition.l
(詳細不明)
使用例:
;;; nの型チェックをしてみる。
(check-type n integer)
type: Function
arguments: coerce OBJECT TYPE
package: lisp
file: typespec.l
OBJECT を TYPE 型に変換します。
TYPE はシンボルまたはリストで、それぞれ以下の型に変換されます。
'list ──→ リスト
'array ─┬→ 配列
'simple-array ─┘
'character ──→ 文字
'float ─┬→ 単精度浮動小数点数
'short-float ─┤
'single-float ─┘
'double-float ─┬→ 倍精度浮動小数点数
'long-float ─┘
'complex ──→ 複素数
'function ──→ 関数
リストの場合、その最初の要素で型が決まります。
2番目以降の要素は、最初の要素が array、simple-array、complex の場合のみ
意味を持ち、それぞれ以下のように動作します。
'(array ...) ─┬→ make-sequence の TYPE と同じ
'(simple-array ...) ─┘
'(complex ...) ──→ 実部、虚部を二番目の要素の型に変換
使用例:
(coerce "abc" 'list) ; 文字列を文字のリストに
=> (#\a #\b #\c)
(coerce #(1 2 3) 'list) ; 配列をリストに
=> (1 2 3)
(coerce '(a b c) '(array t 1)) ; リストを配列に
=> #(a b c)
(coerce "abc" '(array t 1)) ; 文字列を文字の配列に
=> #(#\a #\b #\c)
(coerce '(#\a #\b #\c) '(array character 1)) ; 文字のリストを文字列に
=> "abc"
(coerce "abc" '(array character 1)) ; 意味なし
=> "abc"
(coerce "a" 'character) ; 文字列を文字に
=> #\a
(coerce 1 'float)
=> 1.0
(coerce 1 'double-float)
=> 1.0d0
(coerce 1.0 'complex)
=> #C(1.0 0.0)
(coerce #C(1 2) '(complex float)) ; 単精度の複素数に
=> #C(1.0 2.0)
(coerce 'let 'function) ; シンボル名の関数を返す
=> #<function: let>
(coerce '(lambda (x) (* x 2)) 'function) ; 関数を作ることも
=> #<lexical-closure: (anonymous)>
(funcall (coerce '(lambda (x) (* x 2)) 'function) 12)
=> 24
seealso: type-of
type: Function
arguments: compiled-function-p OBJECT
package: lisp
file: builtin.l
OBJECTがcompiled code objectならt、それ以外ならnilを返します。
使用例:
;;; carの型を調べてみる。
(type-of #'car)
=> compiled-function
(compiled-function-p #'car)
=> t
type: Function
arguments: complexp OBJECT
package: lisp
file: builtin.l
OBJECT が complex number なら t 、それ以外なら nil を返します。
type: Function
arguments: consp OBJECT
package: lisp
file: builtin.l
OBJECTがconsならt、それ以外ならnilを返します。
(consp x) == (typep x 'cons) == (not (typep x 'atom))
注意: (consp '()) は '() == nilなのでnil。
seealso: atom
type: Macro
arguments: deftype NAME (&rest LAMBDA-LIST) &rest BODY
package: lisp
file: typespec.l
NAME と言う名前のデータ型を定義します。
定義したデータ型は typep や subtypep などで使うことができます。
ただし typep で使う場合には、使用前に si:canonicalize-type で
処理することが必要なようです。
使用例:
;; lisp/typespec.l より
;; mod という型を定義
(deftype mod (n)
`(integer 0 ,(1- n))) ; 0 以上 n 未満の整数
(typep 3 (si:canonicalize-type '(mod 5)))
=> t
;; 奇数型を作ってみる
(deftype odd ()
`(and integer
(satisfies oddp)))
(typep 3 (si:canonicalize-type 'odd))
=> t
(subtypep 'odd 'integer)
=> t
=> t
seealso: si:canonicalize-type
seealso: subtypep
seealso: typep
seealso: 型一覧
type: Function
arguments: double-float-p OBJECT
package: lisp
file: builtin.l
OBJECT が double-float なら t 、それ以外なら nil を返します。
type: Function
arguments: eq X Y
package: lisp
file: builtin.l
X と Y が同一オブジェクトならt、そうでないならnilを返します。数値や文字
列に対しては見かけ上同じでもtとなる保証はありません。xyzzyでは、数値はt
となるが文字列ではnilとなるように実装されているようです。
使用例:
;;; eqで比較してみる。
(eq 'foo 'foo) => t ; 仕様
(eq 2 2) => t ; 処理系依存
(eq "foo" "foo") => nil ; 処理系依存
(eq '(1 2) '(1 2)) => nil ; 処理系依存
seealso: eql
seealso: equal
seealso: equalp
type: Function
arguments: eql X Y
package: lisp
file: builtin.l
X と Y が同一オブジェクトか、同じ型の数値または文字型で値が等しいかを返
します。等しければtを、そうでなければnilを返します。eqとは異なり、値とし
て等しいかを判断します。ただし、中身までは見ないので文字列は対象外となり
ます。
使用例:
;;; eqlで比較してみる。
(eql 'foo 'foo) => t ; 仕様
(eql 2 2) => t ; 仕様
(eql "foo" "foo") => nil ; 処理系依存
(eql '(1 2) '(1 2)) => nil ; 処理系依存
seealso: eq
seealso: equal
seealso: equalp
seealso: char=
type: Function
arguments: equal X Y
package: lisp
file: builtin.l
X と Y が同じ構造を持っていればtを、そうでなければnilを返します。
使用例:
;;; equalで比較してみる。
(equal 'foo 'foo) => t ; 仕様
(equal 2 2) => t ; 仕様
(equal "foo" "foo") => t ; 仕様
(equal '(1 2) '(1 2)) => t ; 仕様
seealso: eq
seealso: eql
seealso: equalp
seealso: =
seealso: char=
seealso: string=
type: Function
arguments: equalp X Y
package: lisp
file: builtin.l
equalと同じように X と Y を比較します。
ただし、一部の差異を許容します。
例えば文字・文字列の比較では大文字と小文字を区別しません。
使用例:
;;; equalpで比較してみる。
(equalp "Foo" "foo") => t
seealso: eq
seealso: eql
seealso: equal
seealso: =
seealso: char-equal
seealso: string-equal
type: Function
arguments: extended-alphabet-char-p CHAR
package: editor
CHAR が欧文(ISO8859)の単語構成文字かを判定します。
seealso: characterp
type: Function
arguments: floatp OBJECT
package: lisp
file: builtin.l
OBJECTがfloatならt、それ以外ならnilを返します。
seealso: numberp
type: Function
arguments: functionp OBJECT
package: lisp
file: builtin.l
OBJECTが関数ならt、それ以外ならnilを返します。
type: Function
arguments: graphic-char-p CHAR
package: lisp
file: builtin.l
CHAR が印字文字かどうかを判定します。
(graphic-char-p #\A)
=>t
(graphic-char-p #\SPC)
=>t
(graphic-char-p #\TAB)
=>nil
type: Function
arguments: integerp OBJECT
package: lisp
file: builtin.l
OBJECTがintegerならt、それ以外ならnilを返します。
(integerp x) == (typep x 'integer)
seealso: numberp
type: Function
arguments: kana-char-p CHAR
package: editor
file: builtin.l
文字が半角カナ文字かを返します。
t 半角カナ文字である。
nil 半角カナ文字でない。
カナ文字は以下の範囲です。
Code Char
---- ----
0xa1 .. 0xb0 #\。 .. #\ー
0xb1 .. 0xdd #\ア .. #\ン
0xde #\゙
0xdf #\゚
seealso: kanji-char-p
seealso: characterp
type: Function
arguments: kanji-char-p CHAR
package: editor
file: builtin.l
文字CHARが漢字かを返します。
(詳細不明)
seealso: kana-char-p
seealso: characterp
type: Function
arguments: keymapp OBJECT
package: editor
file: builtin.l
指定されたOBJECTがキーマップかを返します。
non-nil OBJECTはキーマップ
nil OBJECTはキーマップではない
seealso: make-keymap
type: Function
arguments: keywordp OBJECT
package: lisp
file: builtin.l
与えられたオブジェクト OBJECT がキーワードか否かを返します。 OBJECT がシ
ンボルであり、かつ keyword パッケージに所属するときに t を返しているよう
です。
(symbol-package 'a)
=>#<package: user>
(symbol-package :a)
=>#<package: keyword>
(symbolp 'a)
=>t
(keywordp 'a)
=>nil
(symbolp :a)
=>t
(keywordp :a)
=>t
type: Function
arguments: listp OBJECT
package: lisp
file: builtin.l
OBJECTがconsか空リスト()ならt、それ以外ならnilを返します。
(listp x) == (typep x 'list) == (typep x '(or cons null))
type: Function
arguments: local-variable-p SYMBOL &optional BUFFER
package: editor
file: builtin.l
指定されたシンボルがバッファローカル変数かどうかを判定します。
使用例:
;;; buffer: foo
(local-variable-p 'abc)
=> nil
(make-local-variable 'abc)
=> t
(local-variable-p 'abc)
=> t
;;; buffer: bar
(local-variable-p 'abc)
=> nil
seealso: make-local-variable
seealso: defvar-local
type: Function
arguments: long-float-p OBJECT
package: lisp
file: builtin.l
OBJECTがlong-floatならt、それ以外ならnilを返します。
type: Function
arguments: markerp OBJECT
package: editor
file: builtin.l
指定されたOBJECTがマーカーかを返します。
t OBJECTはマーカー
nil OBJECTはマーカーではない
seealso: make-marker
type: Function
arguments: null OBJECT
package: lisp
file: builtin.l
OBJECTが()ならば t 、それ以外なら nil を返します。
(null x) == (typep x 'null) == (eq x '())
seealso: not
seealso: endp
type: Function
arguments: numberp OBJECT
package: lisp
file: builtin.l
OBJECTが数値ならばt、それ以外ならnilを返します。
(numberp x) == (typep x 'number)
seealso: integerp
seealso: floatp
type: Function
arguments: oledatap OBJECT
package: lisp
file: builtin.l
OBJECTがOLEオブジェクトならばt、それ以外ならnilを返します。
(oledatap x) == (typep x 'oledata)
seealso: OLEオートメーションの使用例
type: Function
arguments: packagep OBJECT
package: lisp
file: builtin.l
OBJECTがpackageならt、それ以外ならnilを返します。
使用例:
;;; 指定された文字列のパッケージがあるかを調べる。
(setq pkg (find-package "win32")) => nil
(packagep pkg) => nil
(setq pkg (find-package "winapi")) => #<package: winapi>
(packagep pkg) => t
type: Function
arguments: processp OBJECT
package: editor
file: builtin.l
指定されたOBJECTがプロセスかを返します。
t OBJECTはプロセス
nil OBJECTはプロセスではない
type: Function
arguments: rationalp OBJECT
package: lisp
file: builtin.l
OBJECTがratioかintegerならt、それ以外ならnilを返します。
(rationalp x) == (typep x 'rational)
type: Function
arguments: realp OBJECT
package: lisp
file: builtin.l
OBJECT が real number なら t 、それ以外なら nil を返します。
type: Function
arguments: regexpp OBJECT
package: editor
file: builtin.l
指定されたOBJECTがコンパイル済み正規表現かを返します。
t OBJECTはコンパイル済み正規表現
nil OBJECTはコンパイル済み正規表現ではない
seealso: compile-regexp
type: Function
arguments: sequencep OBJECT
package: lisp
file: builtin.l
OBJECT が sequence なら t 、そうでなければnilを返します。
type: Function
arguments: short-float-p OBJECT
package: lisp
file: builtin.l
OBJECTがshort-floatならt、それ以外ならnilを返します。
type: Function
arguments: *builtin-function-p OBJECT
package: system
file: builtin.l
オブジェクトがビルトイン関数かどうかを調べます。
使用例:
;;; carを調べてみる。
(si:*builtin-function-p #'car)
=> t
type: Function
arguments: *builtin-package-p OBJECT
package: system
file: package.l
オブジェクトがビルトイン・パッケージかどうかを調べます。
使用例:
;;; lisp パッケージを調べてみる。
(si:*builtin-package-p :lisp)
=> t
(si:*builtin-package-p "editor")
=> t
(si:*builtin-package-p (find-package :user))
=> t
備考:
xyzzy 0.2.2.239 から利用可能です。
seealso: si:list-builtin-packages
type: Function
arguments: canonicalize-type TYPE
package: system
file: typespec.l
deftype で宣言されたデータ型 TYPE を展開し、標準の型に直します。
たとえば typep は標準の型しか処理しないため、
deftype で宣言された型を使いたい場合にはこの関数で処理する必要があります。
使用例:
(si:canonicalize-type '(mod 5))
=> (integer 0 4)
seealso: deftype
seealso: typep
type: Misc
package: lisp
simple-string とはシンプルな文字列のことを指します。
共有可能でなく、フィルポインタを持たず、サイズ変更不可能な文字列のことで
す。formatやconcatを使って文字列を操作する場合にはsimple-stringのままです。
使用例:
;;; simple-stringの場合
(type-of "abc")
=> simple-string
seealso: simple-string-p
seealso: schar
type: Function
arguments: simple-string-p OBJECT
package: lisp
file: builtin.l
OBJECTがsimple-stringならt、それ以外ならnilを返します。
使用例:
;;; make-vectorを使ってsimple-stringでないstringを作ります。
(setq var1 (make-vector 10 :element-type 'character)
var2 (make-vector 10 :element-type 'character :fill-pointer 0))
=> ""
(type-of var1) => simple-string
(type-of var2) => string
(simple-string-p var1) => t
(simple-string-p var2) => nil
seealso: simple-string
type: Function
arguments: simple-vector-p OBJECT
package: lisp
file: builtin.l
OBJECTがsimple-vectorならt、それ以外ならnilを返します。
seealso: vectorp
type: Function
arguments: single-float-p OBJECT
package: lisp
file: builtin.l
OBJECTがsingle-floatならt、それ以外ならnilを返します。
type: Function
arguments: standard-char-p CHAR
package: lisp
file: builtin.l
文字が、改行文字もしくは [ -~] かどうかを判定します。
表示可能な文字は SJIS 文字コードで 10, 32-126 です。
CHAR : 判定する文字
戻り値:
t standard-char である
nil standard-char でない
補足:
;;; 改行文字(SJIS 10) 以外の standard-char 文字一覧出力 (SJIS 32-126)
(do ((i (char-code #\SPC) (1+ i)))
((= i (char-code #\DEL)))
(format t "~A" (code-char i)))
seealso: characterp
type: Function
arguments: stringp OBJECT
package: lisp
file: builtin.l
OBJECTがstringならt、それ以外ならnilを返します。
type: Function
arguments: subtypep TYPE1 TYPE2
package: lisp
file: typespec.l
ある型が他の型の副型かどうか調べて多値で返します。
(詳細不明)
TYPE1 : 副型を指定します。
TYPE2 : 型を指定します。
t t TYPE1は明確にTYPE2の副型
nil t TYPE1は明確にTYPE1の副型ではない
nil nil 関係を判断できない
使用例:
;;; サブタイプかどうかを調べる。
(subtypep 'single-float 'number)
=> (single-float double-float long-float)
(subtypep 'cons 'number)
=> nil
seealso: deftype
seealso: typep
seealso: 型一覧
type: Function
arguments: symbolp OBJECT
package: lisp
file: builtin.l
OBJECTがsymbolならt、それ以外ならnilを返します。
(symbolp x) == (typep x 'symbol)
type: Function
arguments: type-of OBJECT
package: lisp
file: builtin.l
与えられたオブジェクトの型を返します。
(typep OBJECT (type-of OBJECT))は必ずtになります。
使用例:
;;; それぞれの型を調べてみる。
(type-of 1)
=> integer
(type-of 2.2)
=> single-float
(type-of #'car)
=> compiled-function
seealso: 型一覧
type: Function
arguments: typep OBJECT TYPE
package: lisp
file: typespec.l
OBJECT が TYPE の型であれば、non-nil な値を返します。
TYPE に与えることのできる引数には以下のようなものがあります。
1. 一般の型
builtin 関数(characterp、listp など)で判定します。
'atom 'null 'ed:buffer
'base-character 'number 'ed:marker
'bignum 'package 'ed:process
'character 'random-state 'ed:regexp
'compiled-function 'ratio 'ed:syntax-table
'cons 'real 'ed:menu
'fixnum 'readtable 'ed:dde-handle
'function 'sequence 'ed:window
'hash-table 'stream 'ed:oledata
'keyword 'symbol
'list
2. 条件式・複合型
条件を満たす場合に non-nil な値を返します。
'(satisfies FUNC) OBJECT を引数に FUNC を funcall した結果を返す
'(member ELEMENTS) OBJECT が ELEMENTS に含まれる
'(eql OBJ) OBJECT が OBJ に等しい
'(not TYPE1) OBJECT が TYPE2 の型でない
'(and TYPE1 TYPE2 ...) OBJECT が TYPE1, TYPE2, ... すべての型である
'(or TYPE1 TYPE2 ...) OBJECT が TYPE1, TYPE2, ... いずれかの型である
't 常に真
'nil 常に偽
3. 文字
'standard-char 文字のうち standard-char-p なもの
'extended-char (*) 常に nil を返す(extended-char は存在しない?)
4. 数値
範囲を指定できます。省略することも可能。
MIN および MAX に、数値の代わりに * を与えると、
下限(上限)を指定しなかったとみなされます。
'(integer MIN MAX)
'(float MIN MAX)
'(rational MIN MAX)
'(short-float MIN MAX)
'(single-float MIN MAX)
'(double-float MIN MAX)
'(long-float MIN MAX)
'(complex TYPE1) integer 型、float 型などで区別可能。範囲指定はできない。
5. 一次元配列
長さを指定できます。
長さには整数値か * を指定します。省略も可能。
'(simple-vector LENGTH)
'(simple-string LENGTH)
'(string LENGTH)
'(vector TYPE1 LENGTH) TYPE1 は t(普通のベクタ)または character(文字列)
6. 一次元以上の配列
'(simple-array TYPE1 DIM) TYPE1 は t(普通のベクタ)または character(文字列)
'(array TYPE1 DIM) DIM は次元
'(simple-array TYPE1 (DIMS)) TYPE1 は t(普通のベクタ)または character(文字列)
'(array TYPE1 (DIMS)) DIMS は各次元のサイズ(たとえば 2x3 なら (2 3) )
7. defstruct で定義された構造体
使用例:
;; 一般の型
(typep #\a 'character)
=> t
(typep (selected-buffer) 'buffer)
=> t
;; 複合型
(typep 3 '(satisfies oddp)) ; 奇数(関数 oddp による判定)
=> t
(typep 'b '(member a b c)) ; a b c がリストとしてまとめられる
=> (b c)
(typep 3 '(and atom number)) ; atom かつ number
=> t
(typep 3 '(and atom number list)) ; atom かつ number かつ list
=> nil
(typep 3 '(or atom number list)) ; atom または number または list
=> t
;; 数値
(typep 3 'integer) ; 範囲指定しないならリストにする必要なし
=> t
(typep 3 '(integer 1 5))
=> t
(typep x '(integer * 5))
=> t
(typep x '(integer 5 *))
=> nil
(typep #C(1 2) 'complex)
=> t
(typep #C(1 2) '(complex float))
=> nil
;; 一次元配列
(typep #(1 2 3) '(simple-vector 3))
=> t
(typep #(1 2 3) '(vector t 3))
=> t
(typep "abc" '(vector character 3))
=> t
;; 一次元以上の配列
(setf a (make-array '(3 4)))
=> #2A((nil nil nil nil) (nil nil nil nil) (nil nil nil nil))
(typep a '(array t *)) ; 次元を指定しない
=> t
(typep a '(array t 2)) ; 2 次元配列
=> t
(typep a '(array t (3 4))) ; サイズも一致
=> t
(typep a '(array t (* 4))) ; サイズの一部だけを指定することも可能
=> t
;; 構造体
(typep (selected-pseudo-frame) 'ed::pseudo-frame)
=> t
seealso: si:canonicalize-type
seealso: type-of
seealso: subtypep
seealso: deftype
seealso: 型一覧
type: Function
arguments: vectorp OBJECT
package: lisp
file: builtin.l
OBJECTがvectorならt、それ以外ならnilを返します。
seealso: simple-vector-p
seealso: vector
type: Function
arguments: windowp OBJECT
package: editor
file: builtin.l
指定されたOBJECTがウィンドウかを返します。
t OBJECTがウィンドウ
nil OBJECTはウィンドウではない
type: Function
arguments: word-char-p CHAR
package: editor
file: builtin.l
CHAR が単語構成文字かどうかを判定します。
seealso: syntax-word-p
seealso: characterp