Racket中的一些宏术语

发布于 2024-10-31 18:14:39 字数 228 浏览 2 评论 0原文

我很长一段时间都对这些术语感到困惑,认为最好问问它们到底是什么意思:

A.语法。 B. 语法值。 C. 语法对象。 Ds-表达式 E.datum(语法->datum)

  • s-表达式和符号有什么区别?
  • s-表达式和数据有什么区别?
  • (语法、语法值和语法对象) 与 s-表达式 有什么区别?
  • 用于解释的代码示例将不胜感激。

I am confused by the terms for a long time, thinking it is good to ask out what exactly do they mean:

A. syntax. B. syntax value. C. syntax object. D.s-expression E.datum (in syntax->datum)

  • What's the difference between s-expression and symbol?
  • What's the difference between s-expression and datum?
  • What's the difference between (syntax, syntax values and syntax object) from s-expression?
  • Code examples for explanation will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟织青萝梦 2024-11-07 18:14:39

“语法”是 Racket 中表示源代码的一种类型,它是 S 表达式的包装器(请参阅 最近的博客文章了解详细信息)。 “语法值”和“语法对象”都是这个的同义词,古代处理语法的 mzscheme 语言函数在名称中使用了 syntax-value 。如今,我们更频繁地使用“语法”,而对于复数形式,我们使用“语法”。

“S-表达式”要么是可以在代码中键入的原始数据片段(符号、数字、字符串、布尔值等——在 Racket 中,您还可以包含其他类型),要么是这些内容的列表。因此,S 表达式是由这些边缘原始类型组成的列表的任何嵌套结构。有时这也包括向量(因为它们可以使用 #(...) 语法输入),但更常见的是它们被忽略。

最后,“datum”是 S 表达式的另一个名称,有时当您想要引用它是具有输入表示形式的数据片段这一事实时。您可以查看 R5RS 如何介绍它: 可以是Scheme 对象的任何外部表示[...]。此表示法用于在方案代码中包含文字常量。

至于你的问题:

  • s-表达式和符号有什么区别?

    符号是S-表达式,S-表达式可以包含符号。

  • s-表达式和数据有什么区别?

    其实没什么。 (尽管可能存在一些微妙的意图差异。)

  • (语法、语法值和语法对象)与 s-表达式之间有什么区别?

    它们是racket中宏使用的程序语法的表示形式——它们包含 S-表达式,但它们添加源位置信息、词汇上下文、语法属性和证书。请参阅该博客文章以获取快速介绍。

"Syntax" is a type for representing source code in Racket, which is a wrapper around S-expression (see a recent blog post for details). "Syntax value" and "syntax object" are all synonyms of this, and ni the ancient days of the mzscheme language functions that deal with syntax used syntax-value in the name. These days we use just "syntax" more often, and for a plural form we use "syntaxes".

An "S-expression" is either a primitive piece of data that can be typed in code (symbols, numbers, strings, booleans, etc -- in Racket you could also include other types), or a list of these things. An S-expression is therefore any nested structure of lists made of these primitive types at the fringe. Sometimes this includes vectors too (since they can be typed in using the #(...) syntax) but more usually they're left out.

Finally, "datum" is another name for an S-expression, sometimes when you want to refer to the fact that it's a piece of data that has an input representation. You can see how R5RS introduces it: <Datum> may be any external representation of a Scheme object [...]. This notation is used to include literal constants in Scheme code.

As for your questions:

  • What's the difference between s-expression and symbol?

    A symbols is an S-expression, an S-expression may contain symbols.

  • What's the difference between s-expression and datum?

    Nothing really. (Although some subtle intentions differences might be there.)

  • What's the difference between (syntax, syntax values and syntax object) from s-expression?

    They are the representation of program syntax used by macros in racket -- they contain the S-expressions, but they add source location information, lexical context, syntax properties, and certificates. See that blog post for a quick introduction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文