Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created July 1, 2016 19:54
Show Gist options
  • Save yorickpeterse/506b0ac29711a03b599dfdfb737bcd05 to your computer and use it in GitHub Desktop.
Save yorickpeterse/506b0ac29711a03b599dfdfb737bcd05 to your computer and use it in GitHub Desktop.
# __get_binding_of_caller and __run_code is a compiler hack to invoke VM
# instructions directly.
class Closure:
def construct(code):
let @code = code
let @binding = __get_binding_of_caller(_)
pub def call(args...):
__run_code(_, @code, args, @binding)
# Once the full namespace ("core::closure::Closure") exists this can be
# converted to just:
#
# let closure = ->: STDOUT.puts("yay closure")
#
# Right now the namespace doesn't exist so the below syntax has to be used.
let closure = Closure.new: STDOUT.puts("yay closures")
closure.call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment