call/cc in Lua - Possible?

前端 未结 6 531
小鲜肉
小鲜肉 2020-12-13 19:46

The Wikipedia article on Continuation says:
\"In any language which supports closures, it is possible to write programs in continuation passing style an

6条回答
  •  余生分开走
    2020-12-13 20:16

    The key phrase is

    It is possible to implement programs in continuation-passing style

    (Emphasis mine.) You do this by taking regular "direct-style" programs and converting them to continuation-passing style (CPS) by a program transformation called the CPS transform. The key is that the CPS transform of call/cc is a simple function.

    This is not practical for programmers. The CPS transform has two uses:

    • As a theoretical idea for studying language features, especially control operators
    • As a pass in a compiler that uses CPS as an intermediate language

    You don't want to go anywhere near doing CPS transforms on Lua code, especially not by hand.

提交回复
热议问题