开发者

Some Macro terms in Racket

开发者 https://www.devze.com 2023-02-23 00:56 出处:网络
I am confused by the terms for a long time, thinking it is good to ask out what exactly do they mean:

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开发者_如何学Python) from s-expression?
  • Code examples for explanation will be appreciated.


"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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号