Intro to Web Prolog for Erlangers

Intro to Web Prolog for Erlangers

Intro to Web Prolog for Erlangers Torbjörn Lager Department of Philosophy, Linguistics and Theory of Science University of Gothenburg Sweden [email protected] Abstract logic-based knowledge representation and reasoning, and We describe a programming language called Web Prolog. We support for meta-programming, user-defined operators, a think of it as a web programming language, or, more specifi- term-expansion mechanism and grammars is also provided. cally, as a web logic programming language. The language is These are the features that underlie Prolog’s reputation as a based on Prolog, with a good pinch of Erlang added. We stay symbolic AI programming language. Also, they are features close to traditional Prolog, so close that the vast majority of that Erlang does not support. In this paper, we present Web programs in Prolog textbooks will run without modification. Prolog – a language which combines the most important Towards Erlang we are less faithful, picking only features features of Prolog with those of Erlang. we regard as useful in a web programming language, e.g. The structure of the paper is as follows. The rest of this features that support concurrency, distribution and intra- section justifies the introduction of yet another dialect of process communication. In particular, we borrow features Prolog. Section2 presents an IDE for Web Prolog, introduces that make Erlang into an actor programming language, and the notion of a node, and describes the interaction between on top of these we define the concept ofa pengine – a pro- the IDE and a node over a WebSocket sub-protocol. Section3 gramming abstraction in the form of a special kind of actor introduces the language of Web Prolog as such and compares which closely mirrors the behaviour of a Prolog top-level. it with Erlang. Section4 looks closer at the combination of On top of the pengine abstraction we develop a notion of the actor model and the logic programming model, placing a non-deterministic RPC and the concept of the Prolog Web. particular focus on non-determinism and backtracking. The notion of a pengine is described in detail, and a notion of non- CCS Concepts • Software and its engineering → Con- deterministic RPC is developed. Section5 describes some current programming languages. earlier work, Section6 provides a discussion, and Section7 Keywords Prolog, Erlang, web programming summarises and suggests avenues for further work. The paper is written with an audience of Erlangers in ACM Reference Format: mind but some basic knowledge of Prolog is assumed. Torbjörn Lager. 2019. Intro to Web Prolog for Erlangers. In Proceed- ings of the 18th ACM SIGPLAN International Workshop on Erlang 1.1 Web Prolog is a Hybrid Programming Language (Erlang ’19), August 18, 2019, Berlin, Germany. ACM, New York, NY, Web Prolog is not only a logic programming language but USA, 12 pages. https://doi.org/10.1145/3331542.3342569 also an actor programming language as it extends Prolog with primitives for spawning processes and sending and 1 Introduction receiving messages in the style of Erlang, i.e. constructs As a logic programming language, Prolog represents a pro- that made Erlang such a great language for programming gramming paradigm which at its core is unique and very message-passing concurrency and distribution. Provided we different from imperative or functional programming lan- can accept using a syntax which is relational rather than guages. Features such as built-in backtracking search, uni- functional it turns out that the surface syntax of Prolog can fication and a built-in clause database form the basisfor easily be adapted to express them. Since Prolog and Erlang also share many other properties such as dynamic typing, Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies the use of immutable variables, and a reliance on pattern are not made or distributed for profit or commercial advantage and that matching and recursion, creating a hybrid between them copies bear this notice and the full citation on the first page. Copyrights seems reasonable. Indeed, it allows us to regard Web Prolog for components of this work owned by others than the author(s) must either as a new dialect of Prolog, or as a new dialect of Erlang. be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific 1.2 Web Prolog is a Web Programming Language permission and/or a fee. Request permissions from [email protected]. There are more than a dozen Prolog systems around, and Erlang ’19, August 18, 2019, Berlin, Germany we do not intend to compete with them, or with Erlang for © 2019 Copyright held by the owner/author(s). Publication rights licensed to ACM. that matter. Although the proposed hybrid between Prolog ACM ISBN 978-1-4503-6810-0/19/08...$15.00 and Erlang would likely work as a general-purpose language, https://doi.org/10.1145/3331542.3342569 this is not what we aim for. Instead, as suggested by the first Erlang ’19, August 18, 2019, Berlin, Germany Torbjörn Lager part of its name and in an effort to find new uses for Prolog, we think of Web Prolog as a special-purpose programming language – as an embedded, sandboxed scripting language for programming the Web with logic and for implementing web-based communication protocols in the style of Erlang. Web Prolog is an embedded language, designed to be im- plemented in a host language running in a host environment. We have embedded our Web Prolog proof-of-concept imple- mentation in SWI-Prolog [6] but we are convinced it can also Figure 2. The shell offers mediated communication between be embedded in other Prolog systems, in systems supporting a programmer and a pengine hosted by a node. non-Prolog programming languages or knowledge represen- tation languages, and in web browsers through transpilation into JavaScript or compilation into WebAssembly. Despite what Figure2 may suggest, the programmer may not Web Prolog is furthermore a sandboxed language, open to be alone in interacting with this particular node. Other pro- the execution of untested or untrusted source code, possibly grammers may be talking to other pengines running there. from unverified or untrusted clients without risking harmto They are completely shielded from each other, unless the the host machine or operating system. Therefore, Web Prolog programs they are running have been written to allow them does not include predicates for file I/O, socket programming to communicate. In any case, pengines do not share mem- or persistent storage, but must rely on the host environment ory, so in order to share information, they must exchange in which it is embedded for such features. messages. A node is equipped with comprehensive web APIs using 2 Running Web Prolog from a Browser WebSocket and HTTP as transport protocols, over which a A proof-of-concept web-based IDE for Web Prolog has been client can run Web Prolog programs defined by the owner of implemented in a combination of HTML, CSS and JavaScript. the client, the owner of the node, or by contributions from The IDE is equipped with an editor and a shell. Figure1 both. The IDE must be run over the WebSocket protocol. shows them as they appear in a browser window, with the The task of the node’s actor manager is to handle the editor to the left and the shell to the right. reception of messages sent by clients and arriving over Web- Socket connections. They may be messages requesting the spawning of a pengine or termination of a pengine, or mes- sages to be forwarded to the pengine addressed by a pid. The actor manager is also responsible for the registration and deregistration of pengines. Crucially, a node may host a Web Prolog program – a de- ductive database, an expert system, a digital assistant, a home control system, or another kind of application – perhaps re- lated to AI and in need of knowledge representation and reasoning. If it does, any pengine running on the node has access to the predicates defined by this program in addition to Web Prolog built-in predicates. The program – which we Figure 1. The proof-of-concept IDE. shall refer to as the node-resident program – is typically main- tained by the owner of the node. Unless programmers are The tiny program shown in the editor can be assumed to have authorised to do so, they are not able to make any changes been written by a programmer who has then entered a query to it, only the owner is allowed to do so. However, by means in the shell in order to inspect the results produced one-at- of code injection in the workspace of the pengine, program- a-time in the usual lazy fashion typical of interactions with mers are allowed to complement the node-resident program a Prolog top-level. The scenario, depicted in Figure2, also with source code that they themselves have written. involves a node, identified by the URI http://local.org, When the programmer enters the URI of the node in the to which the IDE has established a connection. browser’s address field, a WebSocket connection is first es- A node is an executing Web Prolog runtime environment. tablished between the IDE and the node, and then used to Its purpose is to host pengines and other actors. A pengine ask the node to spawn a pengine. Messages sent to a node are is an actor and a programming abstraction modelled on the strings, couched in the syntax of JSON, whereas messages interactive top-level of Prolog.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us