📅  最后修改于: 2020-11-03 07:11:30             🧑  作者: Mango
在LISP中,字符表示为字符类型的数据对象。
您可以在字符本身之前在#\之前表示一个字符对象。例如,#\ 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
通用LISP允许在代码中使用以下特殊字符。它们被称为半标准字符。
数值比较函数和运算符(例如<和>)不适用于字符。通用LISP提供了另外两组函数来比较代码中的字符。
一组区分大小写,另一组不区分大小写。
下表提供了功能-
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