Look for Materials of CPS

学术版

迟暮天复明 @ 2025-07-03 22:43:04

In my nowadays classes, I learned CPS(continuation passing style). The professor used an example of factorial to explain it:

function fac(n, c) {
  return n === 1
           ? c(n)
           : fac(n - 1, x => c(n * x));
}
function factorial_iter(n) {
  return fac(n, x => x);
}

disp(factorial(3));

I thought that I may have understood how this code actually runs, but it's still very hard for me to try to write such code using CPS.

I'm looking for some useful learning material in Chinese so that I can have a better understanding of such complicated stuff.

Thank you.

Oh, I is a english men.


by 迟暮天复明 @ 2025-07-03 22:44:26

Maybe it's not such related to OI so if the admins think this discussion forum is not proper then just delete it


by M1rai @ 2025-07-03 23:14:59

downvoted


by Sublimity @ 2025-07-03 23:26:18

why would you use english? downvoted.


by GavinCQTD @ 2025-07-03 23:29:09

https://zhuanlan.zhihu.com/p/387239708

That's a useful one.


by Igallta @ 2025-07-04 10:15:23

翻译(


by lijingshu_304775 @ 2025-07-04 12:19:44

You are a English man.


by lucasincyber @ 2025-07-04 13:10:50

qp


by mysterys @ 2025-07-04 13:49:50

说好普通话,写好规范字。


by litjohn @ 2025-07-04 19:46:19

@迟暮天复明 我知道有个人(王垠)有一个40行代码的自动CPS变换。你可以去github上搜一下。


by 蒟蒻whker @ 2025-07-18 13:49:15

Oh, I is a english men.

难绷


|