是否可以动态生成 (quote (quote var)) 或 ''var? [英] Is it possible to generate (quote (quote var)) or ''var dynamically?

查看:51
本文介绍了是否可以动态生成 (quote (quote var)) 或 ''var?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有问题 在应用程序中使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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