带闭包的电话/抄送 [英] call/CC with closures

查看:88
本文介绍了带闭包的电话/抄送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wikipedia 提到在任何支持闭包和正确尾调用的语言中,都有可能以连续传递样式编写程序并手动实现call/cc."

Wikipedia mentions that "In any language which supports closures and proper tail calls, it is possible to write programs in continuation-passing style and manually implement call/cc."

例如在javascript中如何实现此功能?我知道javascript不会执行tco,但是假设堆栈空间不会用完

How would one implement this function in for example in javascript? I know that javascript doesn't do tco, but assuming that stack space doesn't run out

推荐答案

无法在JavaScript中编写call/cc实现:

It is not possible to write a call/cc implementation in JavaScript:

JavaScript不符合正确的尾部调用"的要求(不创建其他堆栈).但是,我认为可以使用例外来形成延续的 form ,例如在Jetty中找到的延续. "CPS"就像传递函数对象一样容易,尽管最终它也会遇到堆栈问题,除非偶尔退出.

JavaScript does not meet the requirement of "proper tail calls" (no additional stack creation). However, I believe that a form of continuations, such as that found in Jetty, using exceptions is possible. "CPS" is as easy as passing a function-object, although ultimately it runs into stack issues as well unless backed out occasionally.

快乐的编码.

这篇关于带闭包的电话/抄送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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