ITPub博客

首页 > Linux操作系统 > Linux操作系统 > lisp 中的 【,@】 与 【·】 以及【‘】 以及【 。,】

lisp 中的 【,@】 与 【·】 以及【‘】 以及【 。,】

原创 Linux操作系统 作者:babyyellow 时间:2013-06-19 11:44:10 0 删除 编辑
我们经常在宏定义中看到这个 ,@body 
[`] back quator   (大键盘 数字键 1 左边的那个键)
以及
【‘】 单引号
以及
【。,body】  (句号后面跟个逗号, cons  返回的那个格式)

示例:

(setf test1 '(a test))

(A TEST)

CL-USER> `(this is ,test1)
(THIS IS (A TEST))
CL-USER> `(this is ,@test1)
(THIS IS A TEST)
CL-USER> `(this is . ,test1)
(THIS IS A TEST)
CL-USER> `(this is ,@test1 -- this is only .,test1)
(THIS IS A TEST -- THIS IS ONLY A TEST)


英文原文记录如下:

The need to build up code (and noncode data) from components is so frequent that
there is a special notation for it, the backquote notation. The backquote character
" ' " is similar to the quote character " ' ". A backquote indicates that what follows is
mostly a literal expression but may contain some components that are to be evaluated.
Anything marked by a leading comma " , " is evaluated and inserted into the structure,
and anything marked with a leading " , @" must evaluate to a list that is spliced into
the structure: each element of the list is inserted, without the top-level parentheses.
The notation is covered in more detail in section 23.5. Here we use the combination
of backquote and comma to rewrite whi 1 e:
(defmacro while ( t e s t &rest body)
"Repeat body while t e s t i s t r u e ."
'(loop (unless , t e s t ( r e t u r n n i l ) )
,@body)
Here are some more examples of backquote. Note that at the end of a list, " , @ " has the
same effect as " . " followed by " , " . In the middle of a list, only " , @" is a possibility.






来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/133735/viewspace-764268/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: IBM vs 浪潮
请登录后发表评论 登录
全部评论
oracle MySQL Postgresql 专职数据库dba。 系统架构师。 mysql 官方认知dba 。 15年专职dba 经验。 潜意识沟通实证者 心理咨询师。 禅修布道者, 禅修指导员。 禅定实证者。

注册时间:2010-12-02

  • 博文量
    367
  • 访问量
    1908877