Skip to content

Instantly share code, notes, and snippets.

@kevsmith
Created November 25, 2015 14:44
Show Gist options
  • Save kevsmith/2af37b3fde5eb6bd7763 to your computer and use it in GitHub Desktop.
Save kevsmith/2af37b3fde5eb6bd7763 to your computer and use it in GitHub Desktop.
Hacked up call/cc in Elixir
iex(1)> f = Contex.Target.compute(10, 20)
# c is 30
iex(2)> f.(100)
3000
defmodule Contex.Target do
use Contex.Scanner
defcc compute(a, b) do
c = a + b
# Wraps the remainder of the function in a arity 1 function
# which allows the caller to rebind b
cc! b
c * b
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment