Created
October 7, 2022 20:30
-
-
Save eschen42/4961245346be6aa4151d8123f9217346 to your computer and use it in GitHub Desktop.
simple "co-expressions as objects" prototype
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
procedure co_foo(state, args[]) | |
return .(state[args[1]] +:= args[2]) | |
end | |
procedure co_new() | |
local state, foo, msg | |
state := table() | |
state["something"] := 1 | |
@( | |
foo := create ( | |
msg := &null, | |
repeat ( | |
msg := (msg @ &source), | |
msg := pop(msg) ! ([state] ||| msg) | |
) | |
) | |
) | |
return foo | |
end | |
procedure main() | |
local co | |
#&trace := -1 | |
co := co_new() | |
write([co_foo, "something", 2] @ co) | |
write([co_foo, "something", 1] @ co) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment