4

Just wondering is it possible to run prolog script in a browser? I studied it at university and Id like to add it to my online portfolio?

Conall Curran
  • 61
  • 1
  • 10
  • 4
    A [related question](http://stackoverflow.com/q/15435462/772868) was closed, unfortunately. – false May 18 '15 at 16:53
  • 1
    @false I'm afraid this one's probably going to be closed too. It's essentially a "software recommendation" question, which isn't appropriate for this site. –  May 18 '15 at 18:58
  • @duskwuff Then it should be moved to http://softwarerecs.stackexchange.com/, if possible. – Anderson Green May 16 '16 at 19:30

4 Answers4

6

yes, YieldProlog is a ready-to-use 'transpiler' from a good subset of Prolog to JavaScript.

edit

Now there is a better mantained alternative, ISO compliant: Tau Prolog

edit

A preview of hhprolog, my port to Javascript of Prof.Tarau Hitchhicker Prolog virtual machine.

Hit [ Run code snippet ] to compute 2+2 in Peano notation, i.e. this fragment of pure Prolog

 add(0,X,X).
 add(s(X),Y,s(Z)):-add(X,Y,Z).

 goal(R):-add(s(s(0)),s(s(0)),R).

<script src="https://cdn.jsdelivr.net/gh/CapelliC/hitchhicker-prolog@8424f251246b5f45d5a7ee7046e3e32d29b8282c/hhprolog-es6.js"></script>
<script>
const add = `
add 0 X X .

add _0 Y _1 and
  _0 holds s X and
  _1 holds s Z 
if
  add X Y Z .

goal R 
if
  add _0 _1 R and
  _0 holds s _2 and
  _2 holds s 0 and
  _1 holds s _3 and
  _3 holds s 0 .

`
    const prog = new Prog(add)
    //prog.ppCode()
    const t0 = Date.now()
    prog.run(true)
    console.log('elapsed secs', (Date.now() - t0) / 1000)

</script>
CapelliC
  • 59,646
  • 5
  • 47
  • 90
2

I don't really know what you want to do with Prolog online, but here there are several online "IDEs" and compilers in several languages (Prolog included) so you could execute your prolog script there

If you want to run prolog from scrath in a browser im afraid I don't know how to do it easily

angrykoala
  • 3,774
  • 6
  • 30
  • 55
1

Not sure if swish and/ or pengines might help? http://swish.swi-prolog.org/

http://pengines.swi-prolog.org/apps/scratchpad/index.html

user27815
  • 4,767
  • 14
  • 28
  • SWI-Prolog has also been [compiled to WebAssembly](https://github.com/JanWielemaker/swi-prolog-wasm), so it can run in the browser on the client-side. – Anderson Green Feb 13 '20 at 14:44
-1

I got the following cross compiled system running. It
implements a subset of the ISO core standard, and has
a foreign function interface and a garbage collector.

Dogelog plays Tic-Tac-Toe via Prolog
http://www.dogelog.ch/play.html

enter image description here

The instruction stream for terms is inspired by the Albufeira
compiler below. But we didn't replicate all the tail recursion
yet, and fell back on a "call" and "redo" trampolin:

A portable Prolog compiler
Conference: Logic Programming Workshop - Albufeira, Portugal
William Clocksin - January 1983
https://www.researchgate.net/publication/273888197

First testing showed that it is ca. 10x times faster than
TauProlog and also easier to use, since it implements an
iterator API. So it might get some more care in the future.