反引号在LISP中是什么意思? [英] What does backtick mean in LISP?

查看:115
本文介绍了反引号在LISP中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个宏,它重写定义.如果删除`"反引号,它将不起作用.有什么解释?

I have this macro, which rewrites define. If I remove the " ` " backtick it won't work. What is the explanation?

(defmacro define ((name &rest r) body) 
  `(defun ,name ,r ,body))

推荐答案

单引号后跟值的书面表示形式 将产生该值:

A single quote followed by the written representation of a value will produce that value:

示例: '(1 x"foo") 将产生一个打印为(1 x "foo")的值.

Example: '(1 x "foo") will produce a value that prints as (1 x "foo").

现在假设我不想在列表中使用文字符号x. 我的程序中有一个变量x,我想插入 x绑定的值.

Suppose now that I don't want a literal symbol x in the list. I have a variable x in my program, and I want to insert the value to which x is bound.

要标记我想要的是x的值而不是符号x, 我在x之前插入逗号:

To mark that I want the value of x rather than the symbol x, I insert a comma before x:

'(1 ,x "foo")

它不能按原样工作-我现在得到一个带有文字逗号和符号x的值.问题是quote不了解逗号约定.

It won't work as-is though - I now get a value that has a literal comma as well as a symbol x. The problem is that quote does not know about the comma convention.

Backtick或backquote知道逗号约定,因此将给出正确的结果:

Backtick or backquote knows about the comma-convention, so that will give the correct result:

> `(1 ,x "foo")
(1 3 "foo")          ; if the value of x is 3

在此处了解更多信息: http://www.lispworks.com/documentation /HyperSpec/Body/02_df.htm

Read more here: http://www.lispworks.com/documentation/HyperSpec/Body/02_df.htm

这篇关于反引号在LISP中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆