common lisp 里的几个操作符(2)
集合 (Set)
member 函数
默认使用 eql比较对象,可传入关键字参数 :test,作为比较的函数。关键字参数 :key,指定在每个元素上应用这个函数。
> (member 2 '((1) (2)) :test #'equal :key #'car)
((2))
直接找出满足条件的元素
> (member-if #'oddp '(2 3 4))
(3 4)
函数 adjoin 像是条件式的 cons 。它接受一个对象及一个列表,如果对象还不是列表的成员,才构造对象至列表上。
> (adjoin 'b '(a b c))
(A B C)
> (adjoin 'z '(a b c))
(Z A B C)
并集、交集 以及差集。 union 、 intersection 以及 set-difference 。
> (union '(a b c) '(c b s))
(A C B S)
> (intersection '(a b c) '(b b c))
(B C)
> (set-difference '(a b c d e) '(b e))
(A C D)
序列 (Sequence)
一系列有特定顺序的对象。在 cl 中序列包括列表与向量 (vectors)
length 返回元素数目
> (length '(a b c))
3
subseq 接受3个参数
> (subseq '(a b c d) 1 2)
(B)
reverse 反转
> (reverse '(a b c))
(C B A)
排序 sort 。接受一个比较函数。注意sort 会修改原序列,可以先使用 copy-list 复制。
> (sort '(0 2 1 3 8) #'>)
(8 3 2 1 0)
every 与 some
> (every #'oddp '(1 3 5))
T
> (some #'evenp '(1 2 3))
T
> (every #'> '(1 3 5) '(0 2 4))
T
栈 (Stack)
Cons 来实现 pushdown stack 很简单。cl 提供了两个宏 push 与 pop
(push obj lst) 等同于
(setf lst (cons obj lst))
(pop lst) 等同于
(let ((x (car lst)))
(setf lst (cdr lst))
x)
pushnew 宏是 push 的变种,使用了 adjoin 而不是 cons
> (let ((x '(a b)))
(pushnew 'c x)
(pushnew 'a x)
x)
(C A B)
列表的 点状表示法,只有两个元素(括号算一个整体)之间可以使用点符号。
'(a . (b . nil))
'(a . (b))
'(a b . nil)
'(a b)
end
common lisp 里的几个操作符(2)的更多相关文章
- common lisp里的几个操作符
setf 赋值操作符,定义一个全局变量.返回值是最后一个赋值的结果. let 局部变量操作符.let表达式有两部分组成.第一部分是任意多的变量赋值,他们被包裹在一个()中,第二部分是任意数量的表示式 ...
- common lisp和scheme的区别
1. 在Common Lisp 眼中,一个符号的symbol-value 和symbol-function 是不一样的,而Scheme对两者不作区分.在Scheme 里面,变量只有唯一对应的值,它可以 ...
- ANSI Common Lisp Practice - My Answers - Chatper - 3
Ok, Go ahead. 1 (a) (b) (c) (d) 2 注:union 在 Common Lisp 中的作用就是求两个集合的并集.但是这有一个前提,即给的两个列表已经满足集合的属性了.具体 ...
- Common Lisp编译程序的小技巧
这几天开始玩Common Lisp,遇上了一个有意思的问题,CL一般是解释运行,也有实现可以编译生成字节码(fas文件).我正在用的两种CL实现是SBCL和CLISP,前者是我从<实用Commo ...
- Common Lisp
[Common Lisp] 1.操作符是什么? 2.quote. 3.单引号是quote的缩写. 4.car与cdr方法. 5.古怪的if语句. 6.and语句. 7.判断是真假. null 与 no ...
- 搭建fedora开发环境 common lisp, c++, go
第三方软件库: http://download1.rpmfusion.org/free/fedora/releases/25/Everything/x86_64/os/repoview/index.h ...
- Difference between LET and LET* in Common LISP
Difference between LET and LET* in Common LISP LET Parallel binding which means the bindings com ...
- scheme和common lisp 区别
Scheme and Common Lisp use different names for some of the basic system functions. Many Lisp program ...
- slime+sbcl for common lisp
sudo apt-get install slime audo apt-get install sbcl ;;sbcl+slime for common lisp ;;sudo apt-get ins ...
随机推荐
- nginx的http_sub_module模块使用之替换字符串
Nginx可以实现很多功能,提供了许多插件,其中一个比较冷门的http_sub_module,是用来替换指定字符串的,它的原理是Nginx解析到文件后,执行这个插件进行拦截后返回. 昨天碰到一个场景, ...
- Css3实现波浪线效果1
一.波浪线 ,常用 .info::before { content: ''; position: absolute; top: 30px; width: 100%; height: 0.25em; b ...
- FPGA基础之逻辑单元(LE or LC)的基本结构
原帖地址: https://blog.csdn.net/a8039974/article/details/51706906/ 逻辑单元在FPGA器件内部,是完成用户逻辑的最小单元.逻辑单元在ALTER ...
- vs 2017 community中文版下载地址
https://my.visualstudio.com/Downloads?pid=2190 SHA1: 109C6646A79844D8116DADB293A0B64754363C69 File n ...
- css-animate制作列表鼠标移动覆盖透明层
效果 比列使用bootcdn加速 html <!DOCTYPE html> <!-- saved from url=(0065)javascript:; --> <htm ...
- 每天一个linux命令:du
1.命令简介 du (Disk usage) 用来计算每个文件的磁盘用量,目录则取总用量. 2.用法 用法:du [选项]... [文件]... 或:du [选项]... --files0-from= ...
- redis 4.0.8 源码包安装集群
系统:centos 6.9软件版本:redis-4.0.8,rubygems-2.7.7,gcc version 4.4.7 20120313,openssl-1.1.0h,zlib-1.2.11 y ...
- IDEA使用笔记(十一)——好玩的类图结构
今天使用 IntelliJ IDEA 发现一个好玩的操作,尤其对于研究源码了解类的层级关系有非常大的帮助! 1:先看效果 1-1:HashSet的类图结构——继承什么类.实现什么接口一目了然 1-2: ...
- opcache分享
opcache的技术分享ppt,独家唯一经过自己实验的分享 https://pan.baidu.com/s/1-73-QHOSeet7tcR81gto6Q
- linux下python3调用c代码或者python3调用c++代码
前几篇的blog都是为了这个实验做基础,先说 原因是python调用数据库150w条数据22s,然后处理数据,其实就2个简单的for循环,65s 需求: 1. python调用c++函数 2. c++ ...