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

babyyellow發表於2013-06-19
我們經常在宏定義中看到這個 ,@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部落格 ” ,連結:http://blog.itpub.net/133735/viewspace-764268/,如需轉載,請註明出處,否則將追究法律責任。

相關文章