LISP - 数据类型

LISP - 数据类型 首页 / LISP入门教程 / LISP - 数据类型

LISP数据类型可以分类为。

  • Scalar type          -  如数字类型,字符,符号等。

  • Data structures   -  如列表,向量,位向量和字符串。

尽管不必为LISP变量指定数据类型,但是,它有助于某些循环扩展,方法声明以及我们将在后面的章节中讨论的其他情况。

typep       -  断言用于查找对象是否属于特定类型。

type-of     -  函数返回给定对象的数据类型。

类型说明

类型说明符是系统定义的数据类型符号。

array fixnumpackagesimple-string
atom floatpathnamesimple-vector
bignumfunctionrandom-statesimgle-float
bithash-tableratio standard-char
bit-vectorintegerrationalstream
characterkeyword readtable string
[common]listsequence [string-char]
compiled-functionlong-floatshort-floatsymbol
complex nillsigned-byte t
cons nullsimple-arrayunsigned-byte
double-floatnumbersimple-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)

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Nginx核心知识150讲 -〔陶辉〕

研发效率破局之道 -〔葛俊〕

Serverless入门课 -〔蒲松洋(秦粤)〕

分布式系统案例课 -〔杨波〕

Django快速开发实战 -〔吕召刚〕

乔新亮的CTO成长复盘 -〔乔新亮〕

程序员的个人财富课 -〔王喆〕

快手 · 移动端音视频开发实战 -〔展晓凯〕

PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕

好记忆不如烂笔头。留下您的足迹吧 :)