ANSI Common Lisp 笔记四(结构)
来源:互联网 发布:网络黄金通缉人名单 编辑:程序博客网 时间:2024/06/05 20:56
摘自 《ANSI Common Lisp》
一、结构
要定义一个结构,我们使用defstruct。在最简单的情况下,我们只要给出结构及字段的名字就可以了:
CL-USER> (defstruct point
x
y
)
POINT
这定义了一个 point 具有两个字段 x 与 y。它也隐性地定义了 make-point , point-p, copy-point, point-x 及 point-y 函数。
每一个 make-point 的调用,会返回一个新的 point 。我们可以藉由给予对应的关键字参数,来指定单一字段的值:
CL-USER> (setf p (make-point :x 0 :y 0))
#S(POINT :X 0 :Y 0)
我们可以藉由在本来的定义中,附上一个含有字段名及一个预设表达式的列表,来指定结构字段的缺省值。如果 make-polemic 调用没有替这些字段指定初始值,他们会被设成对应表达式的值:
CL-USER> (defstruct polemic
(type (progn
(format t "What kind of polemic was it?")
(read)))
(effect nil))
POLEMIC
0 0
- ANSI Common Lisp 笔记四(结构)
- ANSI Common Lisp 笔记一
- 《ANSI Common Lisp》学习笔记
- ansi common lisp 第二章 笔记
- ANSI Common Lisp 笔记二(列表)
- ANSI Common Lisp 笔记三(数组)
- ANSI Common Lisp 笔记五(哈希表)
- ANSI Common Lisp 笔记六(控制流)
- ANSI Common Lisp译本笔记1
- ANSI Common Lisp译本笔记2
- ANSI Common Lisp译本笔记3
- ANSI Common Lisp译本笔记4
- ANSI Common Lisp译本笔记5
- ANSI Common Lisp译本笔记6
- ANSI Common Lisp译本笔记7
- ANSI Common Lisp译本笔记8
- ANSI Common Lisp译本笔记9
- ANSI Common Lisp 笔记三(字符与字串)
- vjudge 4965.Sum the Square | 使用map
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- Hadoop回顾--MapReduce工作原理(一)
- TabLayout与RecyclerView的联合使用(不使用ViewPager)
- Android StringEntity() 和 UrlEncodedFormEntity() 的区别
- ANSI Common Lisp 笔记四(结构)
- 【机房收费系统】代码、连接数据库等问题
- Linux Shell编程入门
- STL入门
- Servelet获取properties的几种方法
- 同步,异步,阻塞,非阻塞 摘抄
- Same Tree
- 第一篇博客吧
- 【C++】google gflags库