Lisp-characters

提供:Dev Guides
移動先:案内検索

LISP-キャラクター

LISPでは、文字は* character。*型のデータオブジェクトとして表されます。

文字自体の前に#\の前にある文字オブジェクトを示すことができます。 たとえば、#\ aは文字aを意味します。

スペースおよびその他の特殊文字は、文字の名前の前に#\を付けることで示すことができます。 たとえば、#\ SPACEはスペース文字を表します。

次の例はこれを示しています-

main.lispという名前の新しいソースコードファイルを作成し、次のコードを入力します。

(write 'a)
(terpri)
(write #\a)
(terpri)
(write-char #\a)
(terpri)
(write-char 'a)

あなたがコードを実行すると、それは次の結果を返します-

A
#\a
a
*** - WRITE-CHAR: argument A is not a character

特殊文字

Common LISPでは、コードで次の特殊文字を使用できます。 それらは準標準文字と呼ばれます。

  • #\ Backspace
  • #\タブ
  • #\改行
  • #\ページ
  • #\ Return
  • #\ Rubout

文字比較関数

<および>などの数値比較関数および演算子は、文字に対して機能しません。 Common LISPは、コード内の文字を比較するための他の2つの関数セットを提供します。

1つのセットは大文字と小文字を区別し、もう1つのセットは大文字と小文字を区別しません。

次の表は、機能を提供します-

Case Sensitive Functions Case-insensitive Functions Description
char= char-equal Checks if the values of the operands are all equal or not, if yes then condition becomes true.
char/= char-not-equal Checks if the values of the operands are all different or not, if values are not equal then condition becomes true.
char< char-lessp Checks if the values of the operands are monotonically decreasing.
char> char-greaterp Checks if the values of the operands are monotonically increasing.
char⇐ char-not-greaterp Checks if the value of any left operand is greater than or equal to the value of next right operand, if yes then condition becomes true.
char>= char-not-lessp Checks if the value of any left operand is less than or equal to the value of its right operand, if yes then condition becomes true.

main.lispという名前の新しいソースコードファイルを作成し、次のコードを入力します。

; case-sensitive comparison
(write (char= #\a #\b))
(terpri)
(write (char= #\a #\a))
(terpri)
(write (char= #\a #\A))
(terpri)

;case-insensitive comparision
(write (char-equal #\a #\A))
(terpri)
(write (char-equal #\a #\b))
(terpri)
(write (char-lessp #\a #\b #\c))
(terpri)
(write (char-greaterp #\a #\b #\c))

あなたがコードを実行すると、それは次の結果を返します-

NIL
T
NIL
T
NIL
T
NIL