4 ms·
I've seen a few contalks about logic programming, read a few articles, and aside from the intellectual curiosity in itself I can see that it is very elegant in
by vanderZwan 9y ago
I've seen a few contalks about logic programming, read a few articles, and aside from the intellectual curiosity in itself I can see that it is very elegant in certain circumstances (although I lack the hands-on experience to feel what those circumstances are).
Since doing a whole program in prolog isn't really practical for me, is there any way to use the logic programming paradigm in mainstream programming languages to deal with specific problems that fit it?
- ninjamayo 9y agoNot 100% sure I answer your question but I have used Prolog mixed with Java a while ago and as a high level layer for problem representation. It's not brilliant but at that time it did help me implement quite complex agent behavior within a multi-agent environment.
- markhollis 9y agoI can come up with the following possibilities, although I have no experience with either: - Using OWL in Java (with OWL API). So you use Java in combination with XML - Use a Prolog embedding in Haskell.
- Vosporos 9y agoCheck out https://github.com/rvirding/erlog https://github.com/rvirding/erlog with Erlang/Elixir
- lou1306 9y agoIt seems we have come full circle (the Erlang VM was originally written in Prolog)
- cblop 9y agoMiniKanren is an embeddable language for logic programming, with implementations in a wide variety of languages: http://minikanren.org/ http://minikanren.org/
- erikj 9y agoYou can use embedded Prolog to implement type inference in your compiler. AFAIK that's how it's done in the Rust compiler.
- tannhaeuser 9y agoThe point of Prolog as a practical logic programming language really is that it is portable accross Prolog implementations based on ISO Prolog (and maybe prolog-commons API compatibility). If you're using a Prologish tool (a Java framework, say) that is not quite Prolog, then you're loosing the compatibility for very little gain IMHO. Applications domains I've used Prolog for: discrete planning, game logic, limited/rule-based NLP such as postal address checking, combinatorial test case generation, decision problems in formal language theory used for eg. deciding properties of business processes, other small problems in software engineering such as code generation from domain models with roundtripping, or O/R mapping.
- vanderZwan 9y ago> The point of Prolog as a practical logic programming language really is that it is portable accross Prolog implementations based on ISO Prolog (and maybe prolog-commons API compatibility). If you're using a Prologish tool (a Java framework, say) that is not quite Prolog, then you're loosing the compatibility for very little gain IMHO. I feel like I might be missing something obvious, but I'm not getting what the "compatibility" you refer to would give me in my specific situations? It looks like you're saying "if you write a Prolog program, it's compatible across Prolog platforms." Well, sure, but how is that fundamentally more portable situation than (for example) "if I have a logic programming framework in ES16, it works in all browsers that run modern JavaScript"? If I'm specifically trying to do something in the browser (again, for example) and have a problem within that context where logic programming might be useful, having a way to use logic programming in JS makes more sense, doesn't it?
- tannhaeuser 9y agoI'm not disagreeing that if you're developing a Web app, embedding logical or constraint programming techniques into a JavaScript API could make sense. OTOH, there's an obvious way for data exchange between JavaScript and Prolog, in that JSON can be be parsed by using Prolog's embedded `op/2` predicate and operator-precedence parser for defining custom DSLs.
- 9y ago
- flavio81 9y ago>Since doing a whole program in prolog isn't really practical for me, is there any way to use the logic programming paradigm in mainstream programming languages to deal with specific problems that fit it? Yes, for example is easy to embed Prolog code in Common Lisp by using a suitable library. For example the LispWorks implementation includes a full Prolog package. Example: https://news.ycombinator.com/item?id=12251046 https://news.ycombinator.com/item?id=12251046 With this, you can use the logic paradigm within the same project, along with the other paradigms supported by Common Lisp: Procedural, functional, meta, imperative, dsl-based and OOP. Racket should also allow very easy mixing of Prolog source with the rest of the project, since Racket was designed to support different languages at once.
- brodo 9y agoSWI Prolog has a Java API. You can also use Datalog to get started. It's the non turing-complete version of Prolog. (You can not create facts in rules for example.) The best know Datalog Database is Datomic which you can use in the Java ecosystem but there is also pyDatalog for Python, which is really quite nice.
- gekkonier 9y agoRacket has a Datalog too: https://docs.racket-lang.org/datalog/index.html https://docs.racket-lang.org/datalog/index.html You can mix languages in your Racket Programs as you like, very powerful.
- xntrk 9y agoIf clojure is your thing there is core-logic https://github.com/clojure/core.logic https://github.com/clojure/core.logic