Hey @bitbloxhub, so happy to read you trying out this stuff. Just a quick headsup: Zen modules are very very experimental.
Regarding actors, yes I think your agent (not you) is doing something wrong if the ned-based code uses genericClosure that means it is not using effectful streams properly, there should not be need of any use of genericClosure if everything happens within streams.
So, for a Ned based actor system we could have the following considerations for your agent:
- Nix is single-threaded (the pure-language interpreter has no way to express concurrency)
- This basically reduces Actors to be independent message processing stream-transformers that can keep their own independent state.
- Ned (fx-streams) have scanl and fold to have stateful stream reduction.
- A Driver is basically stream->stream: A stream transformer that would be the basis for actors.
- An important part of Actors is they have Inbox / Behaviour / Identity.
- Inbox is basically an messages flowing on an stream.
- Behaviour is a
receivestream functionbehaviour :: ST msg -> ST { reply, behaviour }where new-behaviour replaces the current behaviour (a fold), and reply gets flatMapped on the response stream. - Identity is only needed if you want being able to pass actor refs, and you’d have a top-level (or nested) routing behaviour that distributes messages. An alternative is using Ned cycles where you have named-sinks and named-sources and these names act as the “channel” where to communicate, on this second approach a routing top-cycle can use
{ to: "foo/bar/baz", from, msg }to specify the location of the nested baz cycle where to deliver the message, probably also want to distinguish between ask and tell. - Streams are themselves values, so you can create an stream that flows streams. You could be using this to create 1-1 private channels between actors.
Explore these ideas with your agent. Tell it that it must not force stream evaluations (keep everything inside streams) and force only at the edges of the app. To take a look at Ned cycle nesting tests.
I’d also be interested in having an actor lib built on Ned streams, feel free to join #denful:matrix.org if you’d want to iterate/collaborate with us on it.