Search code examples
elixircontinuations

Elixir and continuation-passing style


Does Elixir have anything like Scheme's call-with-current-continuation? Is there a way to capture the waiting stack frames and store it in a variable for later use?


Solution

  • Erlang/Elixir does not have the classical call/cc you would find in Scheme-like languages.

    You can just write CPS-style code in Elixir, though. You can capture the current closure in a function and pass that around and manually slice your computations that way.

    Edit: I have just implemented an ANF transformation[1] in CPS style. It might serve as inspiration.

    [1] https://gist.github.com/m1dnight/053494cdc35b89af6fe0b3b63283abd0