Lisp:引用符号值列表 [英] Lisp: quoting a list of symbols' values

查看:157
本文介绍了Lisp:引用符号值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I create a quoted list in Lisp that uses the symbols' values in the list, rather than the symbols themselves? For example, take two variables foo and bar, foo = "hello" and bar = "world". How do I get a list that contains "hello" "world" from these two variables. The best thing I can think of is this:

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

但这是错误的.什么是正确的方法?

But this is wrong. What's the right way to do this?

推荐答案

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

Never mind, further experimentation revealed that the answer is (list foo bar).

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

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

EDIT: Another way of achieving this is using `(,foo ,bar)

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

这篇关于Lisp:引用符号值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆