Yes, I know how painful that can be. However, please note that when I wrote “in SWI-Prolog”, that was a mistake – I meant “in Web Prolog”. Having said that, an implementation of Web Prolog in SWI-Prolog will likely be assembled from libraries, and there will likely be one library which implements receive/1-2
so that you can use it as you would use any other library. Of course, you don’t have to use it, you may prefer to stick with the thread_*
predicates, and there could be lots of reasons for why that would be a better choice. Notably, you may want to allow processes to share the dynamic database so that one process can read or retract what another process has asserted. That’s what I’m doing in the implementation of the caching scheme that was discussed a while ago.
When programming in Web Prolog, which is a language rather than a library, you would not have that choice. The thread_*
predicates are simply not available. If you need concurrency, you have to use spawn/2-3
, !/2
, receive/1-2
, etc, and you’d also find that processes can no longer share data since Web Prolog, just like Erlang, adheres to the idea that processes should “communicate to share memory, rather than share memory to communicate”.
Another thing that Web Prolog gives you, and which is not provided by the thread_*
predicates, is a straightforward way to do distributive programming in a fairly network-transparent manner. Network transparency with respect to where a process is running, locally or remotely, is compatible with message-passing concurrency, but not with shared-state concurrency. Adding distributed message-passing to concurrent Erlang did not add any new concepts, and no new concept are added when we add distributed message-passing to concurrent Web Prolog. Pass the node
option to spawn/2-3
or pengine_spawn/1-2
and off you go, or use rpc/2-3
if synchronous communication and sequential processing is good enough for your purpose.
Sure, and you’re writing one, are you not? That’s a great initiative, so thank you for that!