集合 (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)的更多相关文章

  1. common lisp里的几个操作符

    setf  赋值操作符,定义一个全局变量.返回值是最后一个赋值的结果. let 局部变量操作符.let表达式有两部分组成.第一部分是任意多的变量赋值,他们被包裹在一个()中,第二部分是任意数量的表示式 ...

  2. common lisp和scheme的区别

    1. 在Common Lisp 眼中,一个符号的symbol-value 和symbol-function 是不一样的,而Scheme对两者不作区分.在Scheme 里面,变量只有唯一对应的值,它可以 ...

  3. ANSI Common Lisp Practice - My Answers - Chatper - 3

    Ok, Go ahead. 1 (a) (b) (c) (d) 2 注:union 在 Common Lisp 中的作用就是求两个集合的并集.但是这有一个前提,即给的两个列表已经满足集合的属性了.具体 ...

  4. Common Lisp编译程序的小技巧

    这几天开始玩Common Lisp,遇上了一个有意思的问题,CL一般是解释运行,也有实现可以编译生成字节码(fas文件).我正在用的两种CL实现是SBCL和CLISP,前者是我从<实用Commo ...

  5. Common Lisp

    [Common Lisp] 1.操作符是什么? 2.quote. 3.单引号是quote的缩写. 4.car与cdr方法. 5.古怪的if语句. 6.and语句. 7.判断是真假. null 与 no ...

  6. 搭建fedora开发环境 common lisp, c++, go

    第三方软件库: http://download1.rpmfusion.org/free/fedora/releases/25/Everything/x86_64/os/repoview/index.h ...

  7. Difference between LET and LET* in Common LISP

    Difference between LET and LET* in Common LISP   LET   Parallel binding which means the bindings com ...

  8. scheme和common lisp 区别

    Scheme and Common Lisp use different names for some of the basic system functions. Many Lisp program ...

  9. slime+sbcl for common lisp

    sudo apt-get install slime audo apt-get install sbcl ;;sbcl+slime for common lisp ;;sudo apt-get ins ...

随机推荐

  1. android面试题总结加强再加强版(一)

    在加强版的基础上又再加强的android应用面试题集 有些补充略显臃肿,只为学习 1.activity的生命周期. 方法 描述 可被杀死 下一个 onCreate() 在activity第一次被创建的 ...

  2. 在图像上增加文字 C#

    using (Image i = Image.FromFile(inputPath)) { using (Graphics g = Graphics.FromImage(i)) { g.DrawStr ...

  3. iOS10 11跳转系统设置等的URL收集

    Settings App-Prefs:root Settings -> About App-Prefs:root=General&path=About Settings -> Ac ...

  4. shell编程学习笔记(九):Shell中的case条件判断

    除了可以使用if条件判断,还可以使用case 以下蓝色字体部分为Linux命令,红色字体的内容为输出的内容: # cd /opt/scripts # vim script08.sh 开始编写scrip ...

  5. 《闲聊 ASP.NET Core》系列直播清单

    [闲聊 ASP.NET Core]第一期:项目与应用结构 [闲聊 ASP.NET Core]第二期:Web Host 初始化与生命周期事件 [闲聊ASP.NET Core]第三期:应用程序配置 [闲聊 ...

  6. 机器学习中Batch Size、Iteration和Epoch的概念

    Batch Size:批尺寸.机器学习中参数更新的方法有三种: (1)Batch Gradient Descent,批梯度下降,遍历全部数据集计算一次损失函数,进行一次参数更新,这样得到的方向能够更加 ...

  7. fiddle扩展

    扩展地址:http://www.telerik.com/fiddler/add-ons 证书选择 ios设置证书生成 (CertMaker for iOS and Android) 证书查看 (Fid ...

  8. jquery中选择器input:hidden和input[type=hidden]的区别

    关于选择器:hidden的说明,在jquery说明文档中是这样说的:匹配所有不可见元素,或者type为hidden的元素.而[type=hidden]是查找所有type属性等于hidden的元素.两者 ...

  9. Emacs 不将M-Del删除的单词加入粘贴板

    原文:https://jblevins.org/log/clipboard I use a clipboard manager called Copied that syncs previously ...

  10. Atitit 华为基本法 attilax读后感

    Atitit 华为基本法 attilax读后感 “精神对物质的比重是三比一” 认可拿破仑的这句格言 在20多年中国商业和企业史上,一个最基本.也是最大的现象就是,为什么"中国制造" ...