The Racket Reference阅读笔记。
Macro
12.2 Syntax Object Content
(syntax? v) → boolean?
检查是否是语句对象(identifier? v) → boolean?
检查此语句对象通过(syntax-e stx)
展开后是否是标识符(syntax-source stx) → any/c
,从语句对象中提取source(syntax-line stx) → (or/c exact-positive-integer? #f)
,提取line(syntax-column stx) → (or/c exact-nonnegative-integer? #f)
,提取column(syntax-position stx) → (or/c exact-positive-integer? #f)
,提取position(syntax-span stx) → (or/c exact-nonnegative-integer? #f)
,提取span(syntax-original? stx) → boolean?
,非宏产生可以当作是original(syntax-source-module stx [source?])
,提取源模块,如果有的话(syntax-e stx) → any/c
,从语句对象中解出资讯(syntax->list stx) → (or/c list? #f)
,扁平化语句对象(syntax->datum stx) → any/c
,递归剥离文法信息(datum->syntax ctxt v [srcloc prop ignored]) → syntax?
,若非语句对象,则将其转化为语句对象。解释挺长的
语句绑定集合相关的执行诀:
(syntax-binding-set? v) → boolean?
(syntax-binding-set) → syntax-binding-set?
(syntax-binding-set->syntax binding-set datum) → syntax?
(syntax-binding-set-extend ...)
其他
(datum-intern-literal v) → any/c
,将目标值内具化(syntax-shift-phase-level stx shift) → syntax?
,调整目标语句对象的位阶(generate-temporaries stx-pair) → (listof identifier?)
,生成临时标识符(identifier-prune-lexical-context ...)
,剔除部分上下文(identifier-prune-to-source-module id-stx) → identifier?
,同样是剔除上下文(syntax-debug-info stx [phase all-bindings?])
,打印调试信息
12.3 Syntax Object Bindings
(bound-identifier=? a-id b-id [phase-level])
,判断两个标识符之间能否互相绑定(free-identifier=? ...)
,较复杂,没搞懂(free-transformer-identifier=? ...)
(free-template-identifier=? a-id b-id)
(free-label-identifier=? a-id b-id)
(check-duplicate-identifier ids)
(identifier-binding id-stx ...)
,给出绑定的信息(identifier-transformer-binding ...)
(identifier-template-binding ...)
(identifier-label-binding ...)
(identifier-binding-symbol ...)
,同identifier-binding,但是返回的是一个符号名
12.4 Syntax Transformers
(set!-transformer? v)
,判断是否是set!转换器(make-set!-transformer proc)
,创建set!转换器(set!-transformer-procedure transformer)
,提取转换器对应的执行诀prop:set!-transformer : struct-type-property?
,赋予结构类型set!转换器的含义(rename-transformer? v)
,重命名转换器判定(make-rename-transformer id-stx)
,创建重命名转换器(rename-transformer-target transformer)
,返回重命名转换器的目标prop:rename-transformer : struct-type-property?
,将结构类型作为重命名转换器(local-expand ...)
,本地展开表达式,也就是在内部定义上下文展开(syntax-local-expand-expression ...)
,在表达式上下文展开(local-transformer-expand ...)
,将展开目标作为转换器(local-expand/capture-lifts ...)
,类似local-expand,但是结果是代表begin的语句对象(local-transformer-expand/capture-lifts ...)
,将展开目标作为转换器(internal-definition-context? v)
,判断是否是内部定义上下文(syntax-local-make-definition-context ...)
,创建一个黑箱式的内部定义上下文,可用于local-expand(syntax-local-bind-syntaxes ...)
,为一个内部定义上下文添加绑定(internal-definition-context-binding-identifiers ...)
,返回内部定义上下文的所有绑定(internal-definition-context-introduce ...)
,针对stx进行某种操作(internal-definition-context-seal ...)
,无效果,仅为向后兼容((identifier-remove-from-definition-context ...)
,把内部定义上下文所涉及的作用域从id-stx中抹除prop:expansion-contexts : struct-type-property?
,用于限制macro展开的辖属(syntax-local-value ...)
,当前展开时上下文中返回转换器绑定的值(syntax-local-value/immediate ...)
,跟上一条类似,不过会返回两个值(syntax-local-lift-expression stx)
(syntax-local-lift-values-expression n stx)
(syntax-local-lift-context) → any/c
(syntax-local-lift-module stx) → void?
(syntax-local-lift-module-end-declaration stx)
(syntax-local-lift-values-expression n stx)
(syntax-local-lift-context) → any/c
(syntax-local-lift-module stx) → void?
(syntax-local-lift-module-end-declaration stx) → void?
(syntax-local-lift-require raw-require-spec ...)
(syntax-local-lift-provide raw-provide-spec-stx) → void?
(syntax-local-name) → any/c
,返回推导值的名字(syntax-local-context)
,返回触发展开的上下文(syntax-local-phase-level) → exact-integer?
(syntax-local-module-exports mod-path)
(syntax-local-submodules) → (listof symbol?)
(syntax-local-get-shadower ...)
(syntax-local-make-delta-introducer id-stx)
,已废弃(syntax-local-certifier ...)
,已废弃(syntax-transforming?)
,模块是否处于转换之中(syntax-transforming-with-lifts?)
(syntax-transforming-module-expression?)
(syntax-local-identifier-as-binding id-stx)
(syntax-local-introduce stx)
(make-syntax-introducer [as-use-site?])
(make-interned-syntax-introducer key)
(make-syntax-delta-introducer ...)
(syntax-local-transforming-module-provides?)
(syntax-local-module-defined-identifiers)
(syntax-local-module-required-identifiers ...)
(liberal-define-context? v)
prop:liberal-define-context
12.4.1 require Transformers
(require racket/require-transform)
。
通过结构的prop:require-transformer
来实现。
require转换器被require构造调用,其结果必须时一个import连对,以及一个import-source连对。
12.4.2 provide Transformers
(require racket/provide-transform)
12.4.3 Keyword-Argument Conversion Introspection
(require racket/keyword-transform)
(syntax-procedure-alias-property stx)
(syntax-procedure-converted-arguments-property stx)
(本篇完)