Intro to Web Prolog for Erlangers Erlang ’19, August 18, 2019, Berlin, Germany
nodes to make a comeback. With this paper we are making
an attempt to show how this idea might be realised.
6.1 A Hierarchy of Useful Abstractions
In Web Prolog, just like in Erlang, the actor is regarded as
the fundamental unit of computation and as the single ab-
straction that solves the two problems of concurrency and
distribution and provides a form of network transparency. In
Web Prolog, just like in Erlang, other network-transparent
programming abstractions can be built on top of the actor. In
Web Prolog, the most prominent and universally useful such
abstraction is the pengine, followed closely by the abstrac-
tion for making non-deterministic remote procedure calls.
These are both abstractions that would not t easily into
Erlang, but which are natural in Web Prolog. Abstractions
such as these can be compared to Erlang behaviours. They
are not always easy to build, but once they are built they can
easily be instantiated and tailored to specic tasks.
We note that these three abstractions – the actor, the
pengine and the remote procedure call – form a hierarchy
where predicates on the higher levels inherit some of their
options from predicates on the lower levels.
rpc/3
inherits
options from
pengine_spawn/2
and
pengine_ask/3
, and
pengine_spawn/2 inherits options from spawn/3 in turn.
6.2 Web Prolog and the Programmable Prolog Web
A node has a dual identity. It can be seen not only as a Web
Prolog runtime system but also as a node in the network
forming what we will refer to as the Prolog Web. The tradi-
tional Web is distributed, decentralised and open, and these
are traits we want the Prolog Web to share. Whereas dis-
tribution is nicely conceptualised in the actor model, and
nicely handled by an actor programming language such as
Erlang or Web Prolog, decentralisation and openness require
features we choose to rely on the Web as such to contribute.
Here, the humble URI is a key concept, as it allows us to
link a Web Prolog program to another Web Prolog program,
a running actor to another running actor, or a Prolog query
to its answers, in much the same way as HTML documents
are linked to other HTML documents.
Another key feature of the Prolog Web is that communica-
tion among nodes relies only on HTTP and the WebSocket
protocol. This allows it to pass through rewalls, and pro-
vides security-related features such as methods for authenti-
cation, HTTPS and CORS (Cross-Origin Request Sharing).
6
Distributed programming in Erlang typically involves a
number of nodes connected into a cluster. Erlang nodes usu-
ally rely on TCP/IP for transport and are, for reasons of
security, assumed to be operating in a closed, trusted envi-
ronment where we directly control the machines involved.
In other words, when Erlang runs on a cluster, it is a cluster
that is closed. In comparison, the Prolog Web might be seen
as a cluster as well, but one that is as open as the Web itself.
6
hps://en.wikipedia.org/wiki/Cross-origin_resource_sharing
6.3 Would the Prolog Web Scale?
By adopting a computational model capable of scaling out
not only to multiple cores on one machine but also to mul-
tiple nodes running on multiple machines, by introducing
an option allowing clients to limit the number of network
roundtrips it takes to run a query to completion, by embrac-
ing the WebSocket transport protocol with its low overhead
per message, by oering also a stateless HTTP API, and by
leaving ample room for old as well as new forms of caching
on both clients, nodes and intermediaries, we have made our
best to ensure our high hopes for the scalability of the Prolog
Web are not unfounded.
For the Prolog Web to be able to scale really well, nodes
must also be able to spawn very many actors, creating and de-
stroying actors must be fast, and the communication among
them ecient. Since actors created by the Erlang virtual ma-
chine are famous for having exactly those properties, this is
certainly yet another reason for us to look closely at Erlang.
An implementation of a Web Prolog node in Erlang might
be interesting since it would most probably have a perfor-
mance prole dierent from our implementation in SWI-
Prolog. Interestingly, there is already Erlog – a fairly com-
plete Prolog implementation in Erlang written by Robert
Virding – which might serve as a point of departure.
7
Erlog
is an interpreter so the basic Prolog machinery (e.g. uni-
cation and backtracking) is likely to be slower in Erlog
compared to (say) SWI-Prolog, whereas the super-fast light-
weight processes of Erlang have other advantages, probably
allowing it to scale better to very many simultaneous clients
on a network. For the networking part, we note that Erlang is
particularly famous for extremely ecient implementations
of web-related technologies such as web servers (e.g. Yaws
and Cowboy) and this could also be a distinctive advantage
for an Erlang implementation of Web Prolog.
The holy grail for a Web Prolog runtime system is a com-
piler targeting a virtual machine with BEAM-like properties,
capable of producing code which when run will create pro-
cesses as small and ecient as Erlang processes, yet with
the useful capabilities that Prolog oers. We do not dare to
guess whether building such a virtual machine is feasible.
6.4 Rebranding Prolog
Rebranding is a marketing strategy in which a
new name, term, symbol, design, or combination
thereof is created for an established brand with
the intention of developing a new, dierentiated
identity in the minds of consumers, investors,
competitors, and other stakeholders. Wikipedia
While the paradigms of imperative, functional and object-
oriented programming have a vigorous following, the para-
digm of logic programming with its agship Prolog has fallen
7
hps://github.com/rvirding/erlog