【问题标题】:Enforce strurct-constructor evaluation in Racket在 Racket 中强制执行结构构造函数评估
【发布时间】:2017-05-24 19:21:01
【问题描述】:

通过以下代码:

(struct int (num) #transparent)

(list (int 3) (int 5)) ;; case-1
'((int 3) (int 5))     ;; case-2

case-1 打印 (#(struct:int 3) #(struct:int 5)), 但是 case-2 打印出((int 3) (int 5))

我如何处理第二个struct:int list

【问题讨论】:

标签: structure racket lazy-evaluation


【解决方案1】:

表达式:

'((int 3) (int 5))

或多或少等同于:

(list (list 'int 3)  (list 'int 5))

所以如果你想创建一个以结构为元素的列表,要么直接使用list,要么......你可以使用quasiquote:

`(,(int 3) ,(int 5))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    • 2011-03-21
    • 2021-12-13
    • 2010-10-19
    • 2015-08-02
    • 2022-08-17
    • 1970-01-01
    相关资源
    最近更新 更多