问题描述
有问题 在应用程序中使用 AND方案 ,我提出了一个解决方案,将和"应用到 PLT-Scheme 372 中的原子列表(即 s-exp,它既不是空的,也不是对的.).
In question Using AND with the apply function in Scheme , I proposed an solution to apply "and" onto a list of atoms (i.e. s-exp which is neither null, nor pair.) in PLT-Scheme 372.
Welcome to DrScheme, version 372 [3m].
Language: Textual (MzScheme, includes R5RS).
> (eval (cons 'and (list ''#f ''#f ''#t)))
#f
> (eval (cons 'and (list ''a ''b ''c)))
c
但在那之后我意识到:动态生成 (quote (quote var))
或 ''var
并不容易.具体来说,以下代码将不起作用:
But right after that I realized that: it's not easy to generate (quote (quote var))
or ''var
dynamically. To be specific, the following code will not work:
(define (my-quote lst)
(cond
((null? lst) '())
(else
(cons (quote (car lst))
(my-quote (cdr lst)))
)))
Welcome to DrScheme, version 372 [3m].
Language: Textual (MzScheme, includes R5RS).
> (my-quote (list 'a 'b 'c))
((car lst) (car lst) (car lst))
as (car lst)
不会首先被评估;即使我 (let ((var (car list))) (quote var))
,它也不会工作,因为 var 不会被评估.
as (car lst)
will not be evaluated in the first place; And even if I (let ((var (car list))) (quote var))
, it will not work, either, as var will not be evaluated.
我的问题是,在我尝试这样做时是否存在某种思维陷阱?
My question is, is there some sort of mind trap in my attempting to do this?
推荐答案
其实很简单:
(list 'quote (list 'quote var))
这篇关于是否可以动态生成 (quote (quote var)) 或 ''var?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!