8 ms·
50 Years of Prolog and Beyond
- sirwhinesalot 5y agoI'm not a big fan of Prolog, but its descendents like Datalog or Answer-Set Programming are excellent. Datalog in particular I find much nicer than SQL as a database language. All the "normal forms" are basically how you'd model things in Datalog anyway.
- melissalobos 5y agoOne of the most transformative parts of Prolog is the DCG(Definite Clause Grammars), you can specify a parser as regular Prolog code out of the box. Combine that with strings just being lists of chars, and it becomes super easy to write parsers, which simplifies a lot of issues.
- tkot 5y agoCould you point me to some resources about this sort of thing? I remember hearing about someone implementing transpilation of some subset of C++ to some subset of Java using Prolog but I couldn't find the actual code.
- pjmlp 5y agoYou can have a look at my mini-Pascal parser, it was a toy exercise for the university almost 30 years ago, and some day I decided to uploaded into github. https://github.com/pjmlp/Analyzer https://github.com/pjmlp/Analyzer
- emmanueloga_ 5y agoLearn Prolog Now! [1] has a chapter on DCGs [1]. 1: http://www.let.rug.nl/bos/lpn//lpnpage.php?pagetype=html&pageid=lpn-htmlse29 http://www.let.rug.nl/bos/lpn//lpnpage.php?pagetype=html&pag...
- YeGoblynQueenne 5y agoNot a tutorial resource, but the following is an example from my degree project, that I wrote back in 2011 (don't judge me, OK? I've improved since then!). My project was a Magic: the Gaterhing expert system that included a rules engine, an AI player and an interpreter for the language on M:tG cards. The interpreter was written using Prolog's DCGs. The project was written in a proprietary Prolog (Win LPA Prolog) and I've had a lot of trouble porting it over to the free SWI-Prolog - you can't run the entire project. But the DCG rules in links I give below more or less work for any Prolog with a DCG module. Anyway, just looking at the grammars in them should help get an idea of DCGs in an application that is a step above trivial. First, this is the main M:tG game language interpreter (the "MGL" interpreter; "MGL" is my own terminology, since the langauge on M:tG cards doesn't have an official name): https://github.com/stassa/Gleemin/blob/master/mgl_interpreter_delivered.pl https://github.com/stassa/Gleemin/blob/master/mgl_interprete... The first two-thirds of the source in the linked file is a grammar of a subset of the M:tG game language as a set of production rules in DCG form. That's already a parser for that subset of the M:tG language, right there in the DCG rules themselves (DCGs are just syntactic sugar for ordinary Prolog clauses so a grammar in DCG form is a Prolog program that can be executed as any Prolog program). The rest of the file implements rule engine functions some of which are called by the grammar, while others act as an interface with the rest of the rules engine. Probably. I don't remember what everything does... The next file is a DCG for M:tG mana costs: https://github.com/stassa/Gleemin/blob/master/mana_grammar.pl https://github.com/stassa/Gleemin/blob/master/mana_grammar.p... This grammar is referenced from the previous source file where the "mana" nonterminal appears. So that's just an example of how you can modularise your code to avoid having all the rules in one big endless file. On the other hand, nothing stops you from making a big ball of mess by interleaving your grammar with the rest of your code. Like all Prolog programs, DCG grammars can be "run backwards" so that a grammar that acts as a recogniser when given an input string, can act as a generator when given no input (Prolog doesn't have clear input and outputs, just variables to be instantiated as the program runs). So with my M:tG grammar above I could generate text for new M:tG cards. To facilitate this I set up the "MGL parser interface" below: https://github.com/stassa/Gleemin/blob/master/mgl_parser_interface.pl https://github.com/stassa/Gleemin/blob/master/mgl_parser_int... The first defined predicate in there, identify_MGL/0 is used to identify the type of an M:tG language expression (given or generated), such as "activated ability", "triggered ability", "static ability" etc. So that's one example how to use a DCG for semantic analysis of a bit of text. As a for instance, you could use my identify_MGL/0 to search for abilities of a certain type (alongside a keyword search) which most search engines don't really let you do. My "parser interface" used it to generate abilities of a given type. Anyway, that's an example of DCGs "in the wild" (though from someone who had no clue what she was doing when she wrote it). I hope it's instructive and I didn't just toot my own horn for no reason!
- tannhaeuser 5y ago> The great initiatives consisting of a small group of experts, such as the ISO working group or the Prolog Commons project, with some tweaks that we hope to have covered, can be re-invigorated to make stronger progress in the future. However, they may not be enough to bring together a user community that contributes to the language and its growth. Not wanting to take away from that Festschrift and the wealth of authors covering generations of Prolog programming, but realistically, Prolog Commons contributed very little, was almost entirely ignored, had its last update almost ten years ago, can't be contributed towards, and those things it did add feel distinctly un-Prolog-ish and procedural, such as get_ and put_ primitives for maps. Also, ISO/IEC 13211-1:1995/Cor.2:2012(E) feels kindof rushed (eg specifying false/0 thereby trivially breaking existing Prolog code such as ILP packages for no reason, insufficient description for subsumes_term/2, introducing call/N and the concept of closures without sufficient precedent, etc.)
- YeGoblynQueenne 5y agoHi, can you please explain how false/0 breaks ILP packages? I'm asking agnostically: I neither disagree nor agree with you. I study ILP, but I can't think of how false/0 would break Aleph, for instance (although truth be told I'm not as experienced with pre-2000 systems). And thanks in advance!
- tannhaeuser 5y agoAleph uses rules of the form false :- whatever(x) to represent negative examples, and will load those from a file derived from the project name with ".n" suffix and then assert these clauses dynamically. But this will be rejected (or at least warned against) by eg SWI beginning with version 6 (I believe) introducing ISO 2012 corrigenda, since false/0 is a static procedure ie. SWI's bootstrap file contains a definition false :- fail but doesn't declare false/0 to be dynamic.
- YeGoblynQueenne 5y agoThanks, I didn't know that. I haven't worked with Aleph much and when I used it I didn't have any negative examples so I missed the problems with false/0. Yes, SWI will probably complain of an attempt to redefine a static procedure if false/0 is redefined. It's actually defined in the system module (or a module imported therein) so I guess that an error will be raised even if the negative examples are declared in a module. I wonder then, how does Aleph work around that? Or does it?
- guessbest 5y agoI always wondered how this compared to something like CLIPS[1] [1] http://www.clipsrules.net/index.html http://www.clipsrules.net/index.html
- aarroyoc 5y agoThe main difference is that CLIPS is a forward chaining rule system, while Prolog is backward chaining. This is a big difference in how rules are defined and how do you use them (in Prolog you start with a query always and you try to prove it, in CLIPS you just run it to get some rules dispatched). However, Prolog is also a valid general purpose programming language, so you can actually implement forward chaining rule systems in them (see for example CHR[1] and Heiseneye [2]). CLIPS is not a general purpose programming language. [1] https://www.swi-prolog.org/man/chr.html https://www.swi-prolog.org/man/chr.html [2] https://github.com/IDLabResearch/Heiseneye https://github.com/IDLabResearch/Heiseneye
- elcapitan 5y agoAre there real world use cases of Prolog outside of purely theoretical or academic areas? Logic programming is often named together with the other major programming paradigms like functional, object-oriented or imperative, but I have never seen the use of Prolog in any actual project. Introductions rarely go beyond some primitive examples of filling a Prolog interpreter with data and running some deductions on it.
- WJW 5y agoThere is apparently a web framework (http://eu.swi-prolog.org/ http://eu.swi-prolog.org/), and they do mention commercial sponsors both as users and as contributors. It's no PHP or Javascript to be sure, but there are some users.
- exdsq 5y agoI read about a use for it in printing factories in Germany, using it to deduce the optimal number at to print different shapes on set sized paper.
- tpoacher 5y agoApparently there was a massive prolog-based component in the Windows NT kernel, to do with hardware monitoring or something. I can't remember details, although last time I mentioned this here, I remember some guy replied to my comment and confirmed with details, so ... Angola Search is your friend :)
- elcapitan 5y agoI guess it was this article? http://web.archive.org/web/20040603192757/research.microsoft.com/research/dtg/davidhov/pap.htm http://web.archive.org/web/20040603192757/research.microsoft...
- Contexti 5y agoIBM Watson was using Prolog when it won in a Jeopardy! game: "We required a language in which we could conveniently express pattern matching rules over the parse trees and other annotations (such as named entity recognition results), and a technology that could execute these rules very efficiently. We found that Prolog was the ideal choice for the language due to its simplicity and expressiveness."[0] [0] https://www.cs.nmsu.edu/ALP/2011/03/natural-language-processing-with-prolog-in-the-ibm-watson-system/ https://www.cs.nmsu.edu/ALP/2011/03/natural-language-process...
- tpoacher 5y agoProlog is beautiful. I don't necessarily use it much these days, but it completely transformed the way I see coding since.
- pjmlp 5y agoIt is one of my favourite programming languages, pity that after university logic programming competitions I never found a use case where I could profit from it. Happy birthday Prolog.
- emmanueloga_ 5y agoSometime ago I came across Flix [1] which supports "First-class Datalog Constraints". I feel like this is the "right way" to implement Prolog: provide syntax/semantics for supporting logic programming, but don't force everything to be a Prolog predicate. Would be nice if more languages provided syntax and support for unification of data types and Prolog style searches. 1: https://flix.dev/ https://flix.dev/
- r00tanon 5y agoI loved Turbo Prolog. Creating many cool things: graphical chess problem solver, watching the search process on a VGA screen on a 386 CPU, expert systems, logic analyzers. But it's been a long time. C became my next new love (Turbo C first), and many years later a plethora of OO languages. But Prolog still holds a special place. Too bad it really didn't catch on in my professional career.
- badsectoracula 5y agoShould be noted that Turbo Prolog is/was kind of a special thing on its own - unlike "regular" Prolog, TP is statically typed and has a more "rigid" form with its explicit "domains" (basically type declarations), "predicates", "clauses", etc sections. It isn't a huge difference in practice (and you can declare multiple versions of predicates - sort of like overloaded functions) aside from having to declare upfront of what you intend to do, but writing Turbo Prolog's dialect does feel quite different from other dialects. AFAIK nowadays the compiler is still being developed as Visual Prolog.
- r00tanon 5y agoI had no idea Visual Prolog existed! Thanks for that mention.