可以仅使用lambda和闭包来实现“以当前方式继续调用"吗? [英] Can call-with-current-continuation be implemented only with lambdas and closures?

查看:68
本文介绍了可以仅使用lambda和闭包来实现“以当前方式继续调用"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道call/cc是否可以仅用lambda和闭包实现吗?

Does anyone know if call/cc can be implemented with just lambdas and closures?

似乎call/cc中断了程序的流程(就像一个异常),但是lambda和闭包无法做到这一点.因此,我认为call/cc不能通过lambda和闭包实现.

It seems that call/cc interrupts the program's flow (like an exception) but lambdas and closures can't do that. Therefore I think call/cc can't be implemented via lambdas and closures.

还有其他想法吗?

推荐答案

这个问题不是特别清楚,因为仅用lambda和闭包实现"到底是什么意思?

The question is not particularly clear, since what exactly does "implemented with just lambdas and closures" mean?

在任何情况下,都可以通过以连续传递样式.然后,可以通过扩展编译器来实现自动转换为这种形式,Lisps通常允许在用户级别通过宏进行编译.例如,请参见 cl-cont ,该库实现了Common Lisp的延续,这是一个没有内置这些​​语言的语言.

In any case, continuations can be used in any language with closures by manually writing in continuation passing style. Then automatic translation into this form can be implemented by extending the compiler, which Lisps typically allow on user level through macros. For example see cl-cont, a library implementing continuations for Common Lisp, which is a language that doesn't have them built in.

像Scheme中一样,有效的普适性延续很可能直接在较低层次上实现,直接处理程序堆栈,但这不是必需的,而只是优化.

Efficient pervasive continuations like in Scheme are likely to be implemented on a lower level directly dealing with the program stack, but this is not a requirement, just an optimization.

这篇关于可以仅使用lambda和闭包来实现“以当前方式继续调用"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆