Re: Pengine - the Prolog engine running SWISH

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 08/16/2013 04:53 PM, Michael Hendricks wrote:
> On 08/16/2013 01:50 AM, Richard A. O'Keefe wrote:
>> My first reaction was "that's crazy".
>> My second reaction was, "you know, given emscripten and Asm.js,
>  > that 'good Prolog engine written in Javascript' could *be* SWI Prolog".
>
> That's an intriguing idea.  Our next quarterly roadmap at work requires
> us to run Prolog in the browser.  We need solutions in well under 100ms,
> so network latency prevents server-side code.  We had planned to write a

Well, on fairly well connected networks 100ms should be easy.  Using
websockets, it should be possible in most settings.  They are not
supported yet.  Shouldn't be too hard though.  The stuff to switch
protocols is already around in the HTTP server.  It basically asks
for defining a specialised stream (there are already some in the
HTTP library, for example to deal with chunked and compressed
encodings) that implements the websocket protocol.  Then the
Prolog server picks the JavaScript request to open a websocket,
uses the protocol switch to keep the connection open and stick
a websocket stream between the Prolog server thread and the
network socket.

[ using a longer keep-alive setting will already help a lot in the
   current server.
]

> dodgy Prolog interpreter in JavaScript (as we did with Go a few months
> back: https://github.com/mndrix/golog).  However, if we could get a
> stripped down SWI-Prolog in the browser, we'd be very happy indeed.
>
> On Fri, Aug 16, 2013 at 1:34 AM, Jan Wielemaker <[email protected]
> <mailto:[email protected]>> wrote:
>
>     How do you see that?  The code base is unusable as JS asks for a
>     quite different design than C.  A lot of the fun of SWI-Prolog comes
>     from its extensive libraries, many of which have C components.  Of
>     course you can copy goodies from SWI-Prolog.  There are more systems
>     with goodies to copy from though.
>
>
> Once Emscripten has done it's work, it's fairly easy to call C functions
> from Javascript:
> https://github.com/kripken/emscripten/wiki/Interacting-with-code So at
> the lowest level, JS can call PL_open_query(), PL_next_solution(), etc.
>   Eventually someone would wrap that in a pleasant JS API something like:
>
>      // run callback for each solution to goal
>      pl_query("foo(one, X)", function (solution) {
>          if (solution["X"] == "two") { ... }
>      });

That is embedding SWI-Prolog in JavaScript if I understand you 
correctly.  If that is possible, it might be a quite nice platform
for some scripting tasks.  Its not `just open your browser' though ...

	Cheers --- Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.