Created
July 1, 2016 19:54
-
-
Save yorickpeterse/506b0ac29711a03b599dfdfb737bcd05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# __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