← Back to context

Comment by ramses0

7 hours ago

I keep wishing for "regex for prolog", ie: being able to (in an arbitrary language) express some functional bits in "prolog-ish", and then be able to ask/query against it.

    let prologBlob = new ProLog()
    prologBlob.add( "a => b" ).add( "b => c" )
    prologBlob.query( "a == c?" ) == True

(not exactly that, but hopefully you get the gist)

There's so much stuff regarding constraints, access control, relationship queries that could be expressed "simply" in prolog and being able to extract out those interior buts for further use in your more traditional programming language would be really helpful! (...at least in my imagination ;-)

There are a bunch of libraries that will do this - here's one example of a python one: https://github.com/yuce/pyswip - and a ruby one: https://github.com/preston/ruby-prolog

While usually using native syntax rather than strings, somethign like that exists for most languages of any popularity (and many obscure ones), in the form of miniKanren implementations.

https://minikanren.org/

  • If you really want something that takes Prolog strings instead (and want the full power of prolog), then there are bindings to prolog interpreters from many languages, and also SWI-Prolog specifically provides a fairly straightforward JSON-based server mode "Machine Query Interface" that should be fairly simple to interface with any language.

    https://www.swi-prolog.org/pldoc/man?section=mqi-overview

What you mean is not "regex for Prolog" but an embedded PROLOG interpreter, which exists.

Ironically, the most common way I have seen people do this is use an embedded LISP interpreter, in which a small PROLOG is easily implemented.

https://www.metalevel.at/lisprolog/ suggests Lisprolog (Here are some embedded LISPs: ECL, PicoLisp, tulisp)

SWI-Prolog can also be linked against C/C++ code: https://stackoverflow.com/questions/65118493/is-there-any-re... https://sourceforge.net/p/gprolog/code/ci/457f7b447c2b9e90a0...

Racklog is an embedded PROLOG for Racket (Scheme): https://docs.racket-lang.org/racklog/

I've wished for the same kind of 'embed prolog in my ruby' for enumerating all possible cases, all invalid cases, etc in test suites. Interesting to know it's not just me!