标签: backquote

在JavaScript中使用反引号字符(`)?

在JavaScript中,反引用似乎与单引号相同.例如,我可以使用反引号来定义这样的字符串:

var s = `abc`;
Run Code Online (Sandbox Code Playgroud)

有什么方法可以使反引号的行为实际上与单引号的行为不同?


†请注意,在程序员中,"反引号"是更常被称为重音符号的名称.程序员有时也使用替代名称 "反引号"和"反向".此外,在Stack Overflow和其他地方,"反击"的其他常见拼写是"后退"和"后退".

javascript backticks template-strings single-quotes backquote

229
推荐指数
7
解决办法
12万
查看次数

写宏的宏 - 编译错误

当我编译下面的代码时,SBCL抱怨g!-unit-value和g!-unit是未定义的.我不知道如何调试这个.据我所知,flatten失败了.

当展平到达defunits的未引用部分时,似乎整个部分被视为原子.这听起来不对吗?

以下使用Let over Lambda一书中的代码:

保罗格雷厄姆公用事业

(defun symb (&rest args)
  (values (intern (apply #'mkstr args))))

(defun mkstr (&rest args)
  (with-output-to-string (s)
    (dolist (a args) (princ a s))))

(defun group (source n)
  (if (zerop n) (error "zero length"))
  (labels ((rec (source acc)
             (let ((rest (nthcdr n source)))
               (if (consp rest)
                   (rec rest (cons (subseq source 0 n) acc))
                   (nreverse (cons source acc))))))
    (if source (rec source nil) nil)))

(defun flatten (x)
  (labels ((rec (x acc)
             (cond ((null x) acc) …
Run Code Online (Sandbox Code Playgroud)

macros common-lisp backquote let-over-lambda

9
推荐指数
1
解决办法
340
查看次数

',(引号)在普通 lisp 中

',lisp 中反引号表达式的作用和用途是什么?它有名字吗?它是否记录在某处?它有多普遍和有用?

例如:

(defmacro test-exp (exp)
  `(format t "~&~S => ~S~%" ',exp ,exp))
Run Code Online (Sandbox Code Playgroud)

我的猜测是exp,在宏扩展时,它将采用字面上的任何内容,并',exp用它替换。(与评估exp和替换,exp它相反)。

escaping common-lisp quoting backquote

3
推荐指数
1
解决办法
541
查看次数

正常函数中的反引号,无引号和非引号拼接

我仍然在理解宏,虽然我认为我理解"反引号""unquote"和"unquote splicing"的基础知识,但我认为它们只在宏中使用/有用.

但是我从Rosetta代码(日历任务)中看到了这个Common Lisp代码,

(defun month-strings (year month)
  "Collect all of the strings that make up a calendar for a given
    MONTH and YEAR."
  `(,(date-calc:center (month-to-word month) (length *day-row*))
    ,*day-row*
     ;; We can assume that a month calendar will always fit into a 7 by 6 block
     ;; of values. This makes it easy to format the resulting strings.
      ,@ (let ((days (make-array (* 7 6) :initial-element nil)))
           (loop :for i :from (date-calc:day-of-week year month 1)
                 :for day …
Run Code Online (Sandbox Code Playgroud)

scheme list common-lisp backquote

2
推荐指数
1
解决办法
712
查看次数