Skip to content

Instantly share code, notes, and snippets.

@eschen42
Created October 7, 2022 20:30
Show Gist options
  • Save eschen42/4961245346be6aa4151d8123f9217346 to your computer and use it in GitHub Desktop.
Save eschen42/4961245346be6aa4151d8123f9217346 to your computer and use it in GitHub Desktop.
simple "co-expressions as objects" prototype
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