LISP数据类型可以分类为。
Scalar type - 如数字类型,字符,符号等。
Data structures - 如列表,向量,位向量和字符串。
尽管不必为LISP变量指定数据类型,但是,它有助于某些循环扩展,方法声明以及我们将在后面的章节中讨论的其他情况。
typep - 断言用于查找对象是否属于特定类型。
type-of - 函数返回给定对象的数据类型。
类型说明符是系统定义的数据类型符号。
array | fixnum | package | simple-string |
atom | float | pathname | simple-vector |
bignum | function | random-state | simgle-float |
bit | hash-table | ratio | standard-char |
bit-vector | integer | rational | stream |
character | keyword | readtable | string |
[common] | list | sequence | [string-char] |
compiled-function | long-float | short-float | symbol |
complex | nill | signed-byte | t |
cons | null | simple-array | unsigned-byte |
double-float | number | simple-bit-vector | vector |
除了这些系统定义的类型之外,您还可以创建自己的数据类型,使用 defstruct 函数定义结构类型时,该结构类型的名称将成为有效的类型符号。
链接:https://www.learnfk.comhttps://www.learnfk.com/lisp/lisp-data-types.html
来源:LearnFk无涯教程网
创建名为main.lisp的新源代码文件,并在其中键入以下代码。
(setq x 10) (setq y 34.567) (setq ch nil) (setq n 123.78) (setq bg 11.0e+4) (setq r 124/2) (print x) (print y) (print n) (print ch) (print bg) (print r)
当您单击执行按钮或键入Ctrl + E时,LISP立即执行它,返回的输出是-
10 34.567 123.78 NIL 110000.0 62
接下来,让我们检查上一个示例中使用的变量的类型,创建名为main的新源代码文件, lisp并在其中键入以下代码。
(defvar x 10) (defvar y 34.567) (defvar ch nil) (defvar n 123.78) (defvar bg 11.0e+4) (defvar r 124/2) (print (type-of x)) (print (type-of y)) (print (type-of n)) (print (type-of ch)) (print (type-of bg)) (print (type-of r))
当您单击执行按钮或键入Ctrl + E时,LISP立即执行它,返回的输出是-
(INTEGER 0 281474976710655) SINGLE-FLOAT SINGLE-FLOAT NULL SINGLE-FLOAT (INTEGER 0 281474976710655)
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕