CSP (communicating sequential process) aka channel semantics for Scryer Prolog #3047
jjtolton
started this conversation in
Show and tell
Replies: 1 comment
-
Actors will need some sort of "Actor System" container, so rather than store these in the blackboard, it might make more sense to manage these with the actor system. That way they could be channels(Channels) :- empty_assoc(Channels).
processes(Processes) :- empty_assoc(Processes). % erlang-style processes/actors, not library(process) processes
:- meta_predicate(actor_system(2)).
actor_system(Goal) :-
channels(Channels),
processes(Processes),
async(actor_system_(Channels, Processes, Goal)),
run_event_loop.
:- meta_predicate(actor_system_(+,+,2)).
actor_system_(Channels, Processes, Goal) :-
yield(call(Goal, Channels, Processes)),
yield(actor_system_(Channels, Processes, Goal)). This would be better life-cycle management of the mailboxes than in the blackboard. 🤔 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
+This picture from Torbjorn's book really stuck in my head from his talk at the last meetup:
We have most of the ingredients we need now to make Erlang-style actors a reality in Scryer.
Torbjorn's book demonstrates the following snippet of code:
We could imagine that being rewritten/expanded or meta-interpreted to be something like:
All we would need is some mailbox semantics! CSP is one method I know of to achieve this. There is probably a cleaner way to do it, but I implemented this as a dirty hack on top of queues.
Taking advantage of the fact that queues create "holes" to be filled in later:
I put together the following semantics:
which are mostly a dirty hack on top of queues using the blackboard. (we shall see if this turns out to be a memory leak and needs to be implemented differently...)
Why not just use queues? The reason is a bit nuanced but an example will highlight:
The fact that a
take
does not fail but waits for aput
allows for this pattern:However, in the meantime, we only have one puzzle piece left to achieve Erlang-style actors and open up a huge world of possibility in terms of possible applications for Scryer (web servers, testing frameworks, parallel computing, distributed computing, infrastructure management).
These things ARE possible in synchronous Prolog, but Erlang semantics were built from the ground up for distributed computing, and it would be great to bring those back home to Prolog!
CSP Draft Implementation
Beta Was this translation helpful? Give feedback.
All reactions