What does backtick mean in LISP?

。_饼干妹妹 提交于 2019-12-01 04:16:16

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

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

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.

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

'(1 ,x "foo")

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 or backquote knows about the comma-convention, to that will give the correct result:

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

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

The backtick/backquote disables evaluation for every subexpression not preceded by a comma for the list that follows the operator.

From the common lisp cookbook, explanation and a few examples.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!