使用语法规则在Scheme中隐式柯里化?
Jeffrey Meunier 在此处有一个隐式 Curry 宏,它使用 defmacro。我想知道是否有人用语法规则写过这个?
Jeffrey Meunier has an implicit Curry macro here, which uses defmacro. I was wondering if someone has ever written this with syntax-rules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Scheme 有许多柯里化实现——没有一个能像 Haskell 那样优雅,因为函数总是一元函数,所以所有东西都可以柯里化。 (但这当然可以在一个足够强大的方案中实现,例如Racket。)
至于你的宏已经挖出来了——这是一个非常糟糕的问题:它不仅使用了不卫生的宏,而且还显式调用了
eval
,并且依赖于环境的实现等。但是使用简单的syntax-rules
宏。 AFAICT,这就是它的实现:但是这里有一个重要的说明。您引用的页面说函数版本的一个问题是它是显式的 - 但它也有一个重要的优点:使用宏实现,您必须使用
clambda
定义函数,而函数版本可以与任何内置函数一起使用。在许多方案实现中,都有检查函数数量的工具,并且使用它可以实现知道何时调用原始函数的柯里化函数版本。There are a number of curry implementations for Scheme -- none can be as elegant as Haskell, since there functions are always unary functions, so everything can be curried. (But this can of course be implemented in a sufficiently powerful Scheme like Racket.)
As for the macro that you've dug up -- it's a pretty bad one: not only does it use an unhygienic macro, it's also calling
eval
explicitly, and relies on an implementation of environments etc. But it's easy to do that with a simplesyntax-rules
macro. AFAICT, this is what it implements:But there's an important note here. The page that you reference says that an problem of the function version is that it's explicit -- but it also has an important advantage: with the macro implementation you must define a function using
clambda
, whereas the functional version can be used with any built in function. In many Scheme implementations there are facilities to inspect a function's arity, and using this it's possible to implement a currying function version that knows when to call the original function.