Common Lisp Double-Backquote, Unquote, Quote, Unquote sequence?

后端 未结 2 704
悲哀的现实
悲哀的现实 2021-02-01 20:04

I\'m reading Let Over Lambda, which deals with some pretty deeply layered macro authoring. It\'s fascinating and I\'m mostly managing to keep up with it.

In Chapter 4 Ho

相关标签:
2条回答
  • 2021-02-01 20:26

    During evaluation of a doubly backquoted form, the inner backquote is handled first, and the result is a singly backquoted form. During evaluation of the inner backquoted form, only elements preceeded by two commas are evaluated. However, the result of evaluating these doubly unquoted elements are still (singly) unquoted, and are thus evaluated again when the resulting singly backquoted form are evaluated. To achieve evaluation only in the inner backquoted form, an ordinary quote has to be inserted, resulting in ,',.

    See how

    (let ((tmp (gensym)))
        ``(lambda (,tmp ,,tmp ,',tmp) ()))
    

    evaluates to

    `(LAMBDA (,TMP ,#:G42 #:G42) nil)
    
    0 讨论(0)
  • 2021-02-01 20:43

    The ,',X trick is used to shield the X from another evaluation.

    See how:

         (setq a 'fn)
         (let ((x 'a)) ``(,,x ,',x)) ==>  `(,a a) ==> (fn a)
    
         ;; ``,',X ==> `,(quote "the value of X") ==> "the value of X"
    
         ;; ``,,X  ==> `,"the value of X" ==> "the value of the value of X"
    
    0 讨论(0)
提交回复
热议问题