我对所有声称以某种方式阻止评估的内置 Mathematica 函数感到困惑:Unevaluated、Defer、Hold,以及超过六种 Hold* 形式.Mathematica 文档只是单独解释了每个函数,而没有解释为什么要选择其中一个.任何人都可以对所有这些功能提供一个连贯的解释吗?整件事对我来说似乎是一团糟.将这一切与 Lisp 宏联系起来可能是一个不错的起点.
I'm bewildered by all the built-in Mathematica functions that purport to prevent evaluation in some way: Unevaluated, Defer, Hold, and over half a dozen of the form Hold*. The Mathematica documentation just explains each function in isolation without explaining why you would choose one or the other. Can anyone offer a coherent explanation of all these functions? The whole thing seems like a convoluted mess to me. Relating it all to Lisp macros might be a good place to start.
Mathematica 语言的大部分设计都非常出色,但 Wolfram 似乎真的在这方面把自己画到了一个角落.或者我可能会遗漏一些东西.
Most of the Mathematica language is amazingly well-designed but it seems like Wolfram really painted himself into a corner on this aspect. Or I could be missing something.
推荐答案这些都是相当棘手的结构,很难给出清晰的解释;它们不像 Lisp 宏那样简单(或者,就此而言,Lisp 的 QUOTE 和 EVAL 之间的关系).然而,在 罗比·维勒加斯 1999 年演讲未评估的表达式"中的笔记中,有一个很好的、冗长的讨论" 在 Wolfram 的网站上.
These are pretty tricky constructs, and it's tough to give clear explanations; they aren't as straightforward as Lisp macros (or, for that matter, the relationship between Lisp's QUOTE and EVAL). However, there's a good, lengthy discussion available in the form of notes from Robby Villegas's 1999 talk "Unevaluated Expressions" on Wolfram's website.
Defer 从那次谈话中省略了,因为它是 Mathematica 6.0 的新内容.它很像 HoldForm,除了当它在前端(但不是裸内核)中输出时,它会被剥离,留下一个可以用作输入的表达式.如果您想以编程方式构建用户可以编辑和评估的表达式,例如在调色板中,这将非常有用.
Defer is omitted from that talk, because it's new as of Mathematica 6.0. It's a lot like HoldForm, except that when it's output in a front-end (but not a bare kernel) it's stripped away, leaving an expression that can be used as input. This is very useful if you want to programmatically construct expressions that a user can edit and evaluate, say in a palette.
更多推荐
Mathematica: Unevaluated vs Defer vs Hold vs HoldForm vs HoldAllComplete vs etc等
发布评论