Lisp:引用符号值列表

标签 lisp elisp quote

我如何在 Lisp 中创建一个引用列表,它使用列表中的符号值,而不是符号本身?例如,取两个变量 foobarfoo = "hello"bar = “世界”。如何从这两个变量中获取包含 "hello""world" 的列表。我能想到的最好的事情是:

;; This is Emacs Lisp
(let ((foo "hello")
      (bar "world"))
  (message (prin1-to-string '(foo bar)))
;; prints "(foo bar)"

但这是错误的。执行此操作的正确方法是什么?

最佳答案

没关系,进一步的实验表明答案是(list foo bar)

(let ((foo "hello")
      (bar "world"))
  (message (prin1-to-string (list foo bar)))
;; prints '("hello" "world")'

编辑:实现此目的的另一种方法是使用 `(,foo ,bar)

(let ((foo "hello")
      (bar "world"))
  (message (prin1-to-string `(,foo ,bar)))
;; prints '("hello" "world")'

关于Lisp:引用符号值列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20728980/

相关文章:

lisp - 定义原子函数

function - 定义一个函数,scheme中调用 ‘CHECK’

lisp - 在循环中使用 Setf 语法

emacs - 如何配置spacemacs使其在启动时执行代码?

php - **更新** 我如何在表 sales_flat_quote_item 中创建新列并使用 $cart->addProduct 添加数据

python - Bloomberg API如何在Python中仅获取用户指定给定时间的最新报价?

struct - 为什么 `sxhash` 会为所有结构返回一个常量?

emacs - 如何在 Emacs Lisp 中复制到剪贴板

emacs - 如何在 emacs 中突出显示 #ifdef <code/> #endif?

functional-programming - Racket 中的 '(撇号)是什么?