问题标签 [continuation-passing]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
scheme - call-with-current-continuation - 状态保存概念
读完《老谋深算》后,我觉得我理解call/cc
正确。但是,在看到一些 WOW 技巧后,call/cc
我发现我错了。
这完全符合我的理解。我想当我call/cc
接到电话时,我只是在保存程序状态。并用函数调用它旁边的函数。如果从某个地方调用该函数 ( ),那么我只是用给它的参数k
替换整个东西。上面的程序似乎也是这样工作的(call/cc ...)
但,
调用next
3 次会产生 0、1 和'done
. 这意味着当state
使用它提供的功能时k
,generator
它并没有恢复程序的状态。我只是向你展示了我试图理解它。
那么,call/cc
实际上是如何工作的呢?
lisp - 宏在 common lisp 中的延续——关于 OnLisp 中的实现
在Lisp中,第 267,Paul Graham 提供了延续传递宏的实现:
下面的代码为一棵树t2
的每个叶子遍历一棵树t1
,使用这个实现,我想知道restart
调用时会发生什么,特别是在叶子t1
从A
(第一个元素)更改为B
(第二个元素)之后。当restart
被调用时,它只是简单地从 中弹出一个 lambda 函数*saved*
,然后该 lambda 函数再次调用dft-node
with (cdr tree)
。但是这个调用是在最外层范围之外=bind
进行的,并且=bind
是负责绑定的*cont*
。*cont*
那么,外部引入的绑定如何=bind
仍在范围内呢?
最后一种形式展开为
这产生(a 1)
. 根据 Graham 的说法,后续调用restart
应该产生(a 2)
,等等,直到(a 5)
,然后后续调用应该产生(b 1)
, (b 2)
,等等,直到 finally (g 5)
:
之后(a 1)
,*cont*
建立的绑定let
应该不再存在。后续如何调用restart
这些值?的范围是否let
仍然适用于单独的调用restart
?这里发生了什么?
clojure - SICP、Continuation Passing Style 和 Clojure 的蹦床
我正在与 SICP 一起工作,练习 2.29-b 让我有机会在穿越移动设备和分支时享受延续传球风格的乐趣。
简而言之,每个手机都有左右分支,由长度和数字重量或另一个手机组成。该问题要求找出给定手机的总重量。
在第一个相互递归的解决方案之后,非常简单,我尝试并成功实现了一个 cps 的解决方案:
在这一点上,我尝试使用蹦床来保存我的堆栈。但它有以下例外:
遵循优秀链接的使用蹦床的代码是:
最后是一些示例数据:
为什么会爆炸?
haskell - Haskell 优化失败
我有以下以延续传递风格编写的haskell函数:
我希望这可以编译成明显的优化代码,但我得到的核心与此等效:
即使启用了优化。谁能解释为什么它会重复如此多,或者如何以 GHC 理解的方式重写它?
编辑:
生成的 ASM 如下所示:
预期的核心是这样的:
f# - How can I Implement my own List.partition using tail-recursion?
I'm trying to write my own List.partition function for F# practice. Here's my first (naive) attempt:
This works, but it's not tail-recursive. I put together a second attempt that uses an accumulator to become tail-recursive:
Strictly speaking, this works: it partitions the list. The problem is that this reverses the order of the lists. I get this:
I think that I can use continuation passing to write a tail-recursive partition function that doesn't reverse the list elements, but I don't really understand continuation passing (and I've read a lot about it). How can I write partition using tail-recursive and keeping the list elements in order?
scheme - call/cc 是堆栈帧的副本还是执行中的实际跳转?
我不明白以下内容如何不设置无限循环:
当我调用 时(return 22)
,我跳回继续,但使用传递的值 22 作为call/cc
表单的新评估结果。这不会导致(return 22)
被评估为下一条语句,从而设置一个无限循环吗?
我知道这不是无限循环,但我不明白为什么不是。
javascript - 如何将 JavaScript 中的以下函数转换为延续传递样式 (CPS)?
假设我有以下功能:
如何将表达式f(g(h()))
转换为延续传递样式?我知道这h
会转化为:
但是,我不知道如何将表达式f(g(h()))
转换为 CPS。
另外,如果f
需要 2 个参数而不是 1 个呢?这在 CPS 中会是什么样子?
f
此外,如果g
根本不接受任何论点怎么办?这在 CPS 中看起来如何?
php - 在laravel 5中将变量传递给电子邮件
我可以硬编码一封电子邮件并让它发送,但对于我来说,我无法获得一个变量来通过电子邮件或让它发送到我在表单中输入的地址。当我尝试将其发送到表单中输入的电子邮件时,我收到此错误Swift_RfcComplianceException in MailboxHeader.php line 348:
Address in mailbox given [] does not comply with RFC 2822, 3.6.2.
这是我的代码很远:首先是表单方法
这就是我的 post 方法中的内容:
我是 laravel 的新手,我知道很多人喜欢它,并且发现它是一个简单的框架,但我不知道为什么大声笑。这在 asp.net 中更容易做到。如果您这样做,请提前帮助并感谢您。
php - 试图让搜索栏在 laravel 5 中工作
我试图让一个搜索栏通过我的数据库并获取包括用户将输入的这两个随机数的所有数字。两个连续的数字可以在字符串中的任何位置,然后它应该抓住整个字符串。我遇到的一个问题是表单在布局中(也许没关系,但我仍然想知道如何将布局放在控制器中并将其包含在其他方法中)所以它不有它自己的方法和表单本身我试图路由到另一个视图并显示搜索结果。截至目前,这是我得到的错误:Missing argument 1 for App\Http\Controllers\SearchController::SearchEngine()
在我的布局中:
在我的路线中:`Route::get('search_engine', 'SearchController@SearchEngine');
在我的控制器中:
我的观点只是另一个搜索栏等。
不幸的是,也许我是个笨蛋,但 laravel 文档并没有详细介绍它们的任何功能,而是选择做一个完整的示例图片样式。我是 laravel 时期的新手,所以对我来说填写点的任务可能非常艰巨。
haskell - Haskell Continuation passing style index of element in list
There's a series of examples I'm trying to do to practice Haskell. I'm currently learning about continuation passing, but I'm a bit confused as to how to implement a function like find index of element in list that works like this:
Examples like factorial made sense since there wasn't really any processing of the data other than multiplication, but in the case of the index function, I need to compare the element I'm looking at with the element I'm looking for, and I just can't seem to figure out how to do that with the function parameter.
Any help would be great.