如果 Lisp 中的宏是一元的,这意味着什么?
What does it mean if macros in a Lisp are monadic?
在 Lux Language introduction 中我们读到:
Unlike in most other lisps, Lux macros are monadic. The (Lux a)
type is the one responsibly for the magic by threading Compiler
instances through macros. Macros must have the Macro
type and then be declared as macros.
现在我假设这意味着额外的类型检查信息在编译时可用,为您提供有关代码正确性的一些反馈。
但是您可以在编译时发现的宏有什么不正确的地方?
我的问题是:如果 Lisp 中的宏是一元的,这意味着什么?
粗略看来,"normal" 宏和 reader 宏在 Lux 中似乎都是一元的。
对于普通宏,它们正在线程化 Compiler
类型的状态。各种宏操作(我想 gensym
ing 将是一个明显的例子)需要更改此内部状态,因为它们依赖于有状态的效果,例如维护下一个可用的新原子。线程状态(即看起来像 s -> (a, s)
的函数,获取初始状态作为参数并返回更新后的状态和结果)表现出明显的单子结构,即给定第一步 s -> (a, s)
,选择下一步步骤 s -> (b, s)
可能取决于查看中间结果 a
。
对于reader宏,情况类似,只是所讨论的效果是输入的消耗。 monadic 解析器允许先前使用的输入影响后续输入的解析方式。
在 Lux Language introduction 中我们读到:
Unlike in most other lisps, Lux macros are monadic. The
(Lux a)
type is the one responsibly for the magic by threadingCompiler
instances through macros. Macros must have theMacro
type and then be declared as macros.
现在我假设这意味着额外的类型检查信息在编译时可用,为您提供有关代码正确性的一些反馈。
但是您可以在编译时发现的宏有什么不正确的地方?
我的问题是:如果 Lisp 中的宏是一元的,这意味着什么?
粗略看来,"normal" 宏和 reader 宏在 Lux 中似乎都是一元的。
对于普通宏,它们正在线程化 Compiler
类型的状态。各种宏操作(我想 gensym
ing 将是一个明显的例子)需要更改此内部状态,因为它们依赖于有状态的效果,例如维护下一个可用的新原子。线程状态(即看起来像 s -> (a, s)
的函数,获取初始状态作为参数并返回更新后的状态和结果)表现出明显的单子结构,即给定第一步 s -> (a, s)
,选择下一步步骤 s -> (b, s)
可能取决于查看中间结果 a
。
对于reader宏,情况类似,只是所讨论的效果是输入的消耗。 monadic 解析器允许先前使用的输入影响后续输入的解析方式。