20 ms·
Prolog at Work
- LAC-Tech 4y agoProlog feels like one of those things I definitely couldn't write a whole app in, but I often wish it was just there in other languages the same way regex is.
- SanjayMehta 4y agoI went through a struggle trying to implement an MMI for a telecom product using Prolog, it was just not performant enough. Around the same time, Joe Armstrong of Ericsson was experimenting with Prolog to build a switching system. Erlang came out of that effort, essentially stripping out the backtracking - wish I had thought of that. Elixir is built on Erlang and is definitely a production language. You might find both Erlang and Elixir viable.
- dmitriid 4y agoNothing is left in Erlang/Elixir from Prolog. Except some of the Erlang syntax.
- hosh 4y agoThere are several attempts to put it back: https://9to5tutorial.com/the-story-of-how-to-make-a-prolog-compiler-with-elixir https://9to5tutorial.com/the-story-of-how-to-make-a-prolog-c... https://github.com/k1complete/exprolog https://github.com/k1complete/exprolog
- knewter 4y agoRobert Virding's erlog as well: https://github.com/rvirding/erlog https://github.com/rvirding/erlog (rvirding GOAT)
- SanjayMehta 4y agoPattern matching remains and is my favourite feature.
- moffkalast 4y agoNone of this should be its own language, I'm not sure why people are still working in that direction when it's been clear for nearly decades that it's barely possible to use as a standalone language. Like if somebody implemented Tensorflow in its own separate weird language and insisted that's the best and only way to use it. I think people are far too constrained by adhering to what Prolog is standardized as, making sure there's literally no advancement whatsoever. We just need a more practical formal logic library or type or something for your average language without any stupid string definitions or passing literal prolog in for execution. I mean is that too much to ask?
- usgroup 4y agoWell usually it’s the datalog subset people wish was just there —- and it typically is :-)
- grose 4y agoI agree that embedding Prolog is a compelling use case. I ported Trealla Prolog to WASM to help the cause. It's super cool being able to store some business rules as a chunk of Prolog text and run them on both the backend and the frontend as-is. Want to explore your code, maybe test out some quick changes? Prolog comes with a nice REPL. Want to modify the knowledgebase? Add some clauses with assertz/1 and dump out the full program code with listing/0; no need to wrangle the text yourself. Want to make a previously static relationship more dynamic? Just throw in a new rule: as far as Prolog is concerned rules and facts are equal citizens. It's like a database that lets you intermix static and dynamic row definitions anywhere you want. Testing it is easy: Prolog will happily give you every possible result for a general query. Want to generate error messages from chunks of code, or run your queries backwards? Just throw in a little metainterpreter[1]. I think Prolog is the perfect companion language to static and difficult-to-extend languages like Go. I think that if we want Prolog to become more popular, we should focus on a great embedding experience for developers. That's my current goal :) [1]: https://www.metalevel.at/acomip/ https://www.metalevel.at/acomip/
- nurettin 4y agoI'd like a spec language which takes constraints and compiles code them into target language. This way, we can design features at a higher level and don't have to get lost in forests of ifs, tree searches, caching mechanisms and multi layer state machines.
- runevault 4y agoHaving a compiler that supports multiple full languages with required consistent ABI at those boundaries is something we really could use. Then you could have a prolog layer for things where it makes sense mixed with an Algol or ML or whatever based language for the rest of the logic. Similar to what .NET has done-ish, but wider ranging is what I'd love to see.
- mmatants 4y agoOne clever hack I've seen is Yield Prolog (https://yieldprolog.sourceforge.net/ https://yieldprolog.sourceforge.net/) which basically translates the querying/backtracking execution model into mainstream language syntax - such as JS, Python or C# - using the `yield` keyword and loops. Supports things like variable unification, too.
- Spooky23 4y agoTotally. I wrote a network management system with a prolog rules engine years ago. It was amazing when my colleague and I figured out how to integrate that system with our Oracle database in real-time. Having a prolog engine embedded that way made it incredibly powerful to manage and alert on pretty complex relationships.
- olgsb 4y agoI agree, that's why I made this : https://github.com/smallbard/SharpLogic https://github.com/smallbard/SharpLogic to embed it in c# (in order to use it as easily as Linq). It's a work in progress (a very fun one!)
- Blackthorn 4y agoI so wish there was a complete prolog implementation exactly like this in pretty much any language I use. Unfortunately they always end up being woefully incomplete.
- dragonwriter 4y ago> Prolog feels like one of those things I definitely couldn’t write a whole app in, but I often wish it was just there in other languages the same way regex is. Embedding prolog (or limited versions, like Datalog, or versions of Prolog or Datalog extended with probabilistic, temporal, or other features), or other logic sublanguages like MiniKanren, in other languages isn’t particularly uncommon.
- usgroup 4y agoI don’t think prolog does itself any favours by advertising as a general purpose programming language. I tried to learn it and it really screams “I’m not a general purpose programming language”. If you take away the use cases more suitable for datalog or MiniZinc the only remaining strong use case I see is recursive parsers. It’d be good to hear about how others see it.
- ausudhz 4y agoWell, luckily what prolog screams is irrelevant. Most programming language are Turing complete and if so they're also general purpose by definition. You can use them to build anything. That said of course our definition might be different and if you don't have plenty of layers of abstraction that speed your development you won't consider that programming language compared to another. After all, we are running JavaScript in the servers now and you can find an npm module for nearly everything. Probably someone 20 years ago would've said that "JavaScript is not a general purpose language" Don't get me wrong, prolog may never be the next JavaScript, but is just fun how people would define something is "general purpose" or not (no hate, just a pure comment seeing things from a different angle)
- xupybd 4y agoI think many people understand general purpose to mean it's a good language choice for many different and common uses. It has little to do with how Turing complete the language is. Just how well it suits a variety of problem domains.
- Jedd 4y agoIn the late 1980's, when I was at college in Sydney, we had a visit from a chap (I think from somewhere in the north of Europe) who'd previously won a tender for, IIRC, a booking / tracking system for a relatively small airline, all to be written in Turbo Prolog. I recall two key things from his presentation of his final product. First, he claimed he'd quoted a half the cost/time of a COBOL-based, and a quarter of a C-based, competing tenders -- and that he'd met his deadlines. Second, the UI was just beautiful - for both aesthetics and performance. I didn't have much experience in enterprisey software at the time, but what little I had seen was archetypal terminal-style, monochrome, sluggish, far from user-friendly etc. I have some (no doubt unreliable) memories of this thing looking like a 'modern' (say Amiga) GUI app. Another item in that large category of 'I wish they'd drop these things into the public domain once they retired it from production' as it would probably still make a great demo (though most free Prolog implementations these days wouldn't support (m)any of the pretty Turbo extensions, I'm sure).
- agumonkey 4y agoDo you think there are traces of this booking app ? even the name ?
- YeGoblynQueenne 4y agoIt could be the flight booking system described in Sictus Prolog's old homepage: SICStus Prolog is a workhorse in the transport and logistics industries, running systems that handle a third of all airline tickets, and helping railways to operate their trains better. “Most people probably have used SICStus Prolog without knowing it,” says Mats Carlsson, its lead developer. “One of our customers runs a flight booking system on SICStus which handles nearly a third of all airline tickets in the world.” https://web.archive.org/web/20190203010151/https://www.sics.se/projects/sicstus-prolog-leading-prolog-technology https://web.archive.org/web/20190203010151/https://www.sics.... The new homepage doesn't say anything about flight bookings and I can't find anything about it in the "Customers" page either: https://sicstus.sics.se/customers.html https://sicstus.sics.se/customers.html I have a sneaking suspicion that might mean the customer replaced Prolog with something else, possibly some kind of machine learning :P
- triska 4y agoA recent article from the Austrian Federal Computing Centre, using Prolog to analyze eligibility criteria for grants: https://www.brz.gv.at/en/BRZ-Tech-Blog/Tech-Blog-7-Symbolic-Analysis-of-Grants.html https://www.brz.gv.at/en/BRZ-Tech-Blog/Tech-Blog-7-Symbolic-... In this way, several interesting questions can be answered, such as: Are there grants that have the same prerequisites? How many companies are not eligible for any grant? Are there grants where eligibility also implies other grants? etc. Prolog is becoming more interesting now that several conforming and free implementations with comprehensive features arise, notably Scryer, Tau and Trealla Prolog as the most recent systems, and interesting bindings for other languages such as ichiban/prolog for Go. On the Datalog side, Google have recently published a Datalog system called Mangle, which supports the Datalog subset of Prolog as a proper subset.
- pmarin 4y ago> Prolog is becoming more interesting now that several conforming and free implementations with comprehensive features arise What's wrong with SWI-Prolog?
- triska 4y agoAs of version 7, SWI-Prolog is consciously no longer conforming to the Prolog ISO standard in critical aspects, so it is not usable in organizations where standards are of great importance for procurement, warranty and interoperability reasons, and where long-term maintenance and guarantees are required: https://www.complang.tuwien.ac.at/ulrich/iso-prolog/SWI7_and_ISO https://www.complang.tuwien.ac.at/ulrich/iso-prolog/SWI7_and...
- nurettin 4y agoRelevant docs https://www.swi-prolog.org/man/syntax.html https://www.swi-prolog.org/man/syntax.html
- YeGoblynQueenne 4y agoHm, I wouldn't say that conformance to ISO makes a Prolog more "interesting". More useful in certain kinds of applications like the ones you point out, sure. In my experience, there are two Prolog worlds, and that has been true right from the beginning of Prolog with Kowalski coming from the world of pure mathematical formalisms, and Colmerauer coming from the world of pragmatic, practical programmers. The power of Prolog (no pun intended :) comes from the tension between these two worlds. If Kowalski had his way, Prolog would probably be a perfect jewel encased in golden amber, completely unusable but a wonder to behold. If Colmerauer had his way, Prolog would be a quick and dirty programming language fit to replace javascript or C. But they worked together, hand-in-hand, and made something bigger and better and more wonderful than either could have imagined [1]. This duality is also a curse, of course, because its critics can attack it from two sides: it's not pure enough for the purists, not dirty enough for the programmers. Half of its critics complain that it's not 100% declarative, the other half complain that it is not "general purpose" (see elsewhere in this thread). Well, it's not 100% declarative because it's got side-effects, but then what use is a programming language without side-effects? One simply ends up with twisted abominations like monads [2]. And I still don't understand what "general puprose" means, if it doesn't describe Prolog. I think Jan Wielemaker [maintainer of SWI-Prolog] is firmly in the Colmerauer camp, striving to create a language that everybody can use, not just musty academics in their (our!) ivory towers. I have to say I don't always agree with his choices, but I, personally, am infinitely grateful for his oeuvre and I have often considered how little I could have done, for example in my PhD research, without his work. _________________ [1] To hear the French say it of course, it was Colmerauer and Philippe Roussel who created Prolog and Kowalski was probably only visiting Marseilles for unrelated reasons. See the Prolog article on French wikipedia: https://fr.wikipedia.org/wiki/Prolog https://fr.wikipedia.org/wiki/Prolog [2] On the other hand, I think we can both agree that the dynamic database is evil.
- ramraj07 4y agoAt least for designing APIs, I find pydantic + FastAPI (and now SQLAlchemy 2) to be an excellent platform to do the initial spec, and the beauty of it is that it automatically produces the swagger docs as well as a fully functioning API interface as well!
- sgt101 4y agoProlog is deeply unsuited for work, use Clingo instead. Try this on https://swish.swi-prolog.org/ https://swish.swi-prolog.org/. on(a,b). on(b,c). above(X,Y) :- on(X,Y). above(X,Y) :- on(X,Z), above(Z,Y). Query above(a,c) Ok, true - it works! no probs. now try on(a,b). on(b,c). above(X,Y) :- above(X,Z), on(Z,Y). above(X,Y) :- on(X,Y). and query... and it explodes. So - this kind of bug is very hard to find and extremely easy to introduce. The good news is that answer set programming is not prone to it. So instead of prolog use Clingo ! https://potassco.org/clingo/ https://potassco.org/clingo/
- triska 4y agoIn your second example, I get an exception (it does not "explode"), and this is also not a "bug". In your second example, the default search strategy is unable to derive whether above(a,c) is a logical consequence of the program. The existence of such cases is expected when using the default execution strategy (SLD resolution), which sacrifices completeness for efficiency. A key advantage of using a declarative programming language such as Prolog is that we can change the execution strategy. For example, I tried your code in Scryer Prolog and added 2 directives as the first two lines to enable an execution strategy called SLG resolution instead of the default strategy: :- use_module(library(tabling)). :- table above/2. on(a,b). on(b,c). above(X,Y) :- above(X,Z), on(Z,Y). above(X,Y) :- on(X,Y). Now I get: ?- above(a,c). true ; ... . So, with a different search strategy, the Prolog system is also able to derive that above(a,c) holds, like Clingo. Note that answer set programming cannot help in any way when I need a program to perform side effects such as initiating a network connection, hosting a web page, parsing a file etc., whereas Prolog is extremely useful and appropriate for such applications. So, the fact that the default execution strategy of Prolog is not adequate to solve this specific example is not a sensible argument for or against Prolog.
- rscho 4y agoProlog and ASP look similar, and have some amount of intersection in their use case. But their sets of use cases are certainly not identical.
- naasking 4y agoI am completely mystified by what the "ASP Language Standard" is. The clingo page references it and the link it cites provides literally no contextual information about it.
- neilv 4y agoIn the early 1990s, I knew one team was using Prolog as the rich database report language for a greenfield complex new workstation platform that was otherwise written in C. I was surprised, because Prolog already seemed like one of those exotic things that you learned in school was used in AI research, or had been, but hadn't heard of it being used commercially at the time.
- JTBooth 4y agoI interviewed with a company named Gaussy recently who use it for warehouse operations.
- Al-Khwarizmi 4y agoI was rather disappointed when I learned Prolog 20 years ago, because of the unfulfilled expectations. You could program in a totally declarative way, with logic formulas, and the system would take care evaluating the formulas! As a person who likes the math/theory side of CS, that sounded absolutely amazing! Except that it wasn't really like that, because IIRC (20 years have passed so there may be some inaccuracies here, but this is the gist of what I remember) logical operators like "and" or "or" weren't even commutative, "a and b" vs "b and a" could be the difference between running normally and an infinite loop, you had to insert "!" (which were totally non-declarative and non-logic) to make things work as you wanted, and at that point you were thinking about what order things would be run in, so why not use an imperative language instead, where at least the order of execution is clear in the first place. To each their own, though.
- triska 4y agoThese are valid concerns, arising mostly from inadequate implementations and a lack of modern features in early (and also current) Prolog systems. In the past 20 years, many new language constructs and implementation improvements were introduced and have become widely available in newer Prolog systems to address precisely these problems among others. For example, inspired by pioneering systems such as XSB Prolog, modern Prolog systems such as Scryer Prolog support alternative execution strategies, internally implemented via delimited continuations as described by Desouter et al., and thus prevent many infinite loops that arise with the default execution strategy: https://www.ijcai.org/Proceedings/16/Papers/619.pdf https://www.ijcai.org/Proceedings/16/Papers/619.pdf As another example, in 2016, Neumerkel and Kral introduced if_/3 and related predicates, which are now available as library(reif) in Scryer Prolog, and also available for SICStus with advanced compile-time expansions: https://arxiv.org/abs/1607.01590 https://arxiv.org/abs/1607.01590 As yet further examples, better indexing techniques such as JIT indexing and Scryer Prolog's first instantiated argument indexing help to improve determinism and efficiency automatically, and much improved internal string representations allow efficient parsing of large amounts of data with Prolog's built-in grammar mechanism that is now being drafted for standardisation. Constraints such as dif/2 are now also becoming more widely available after decades of being largely ignored by implementors. As long as we keep to the pure monotonic core of Prolog, conjunction and disjunction are indeed semantically commutative, and different execution strategies are applicable. Of course, using !/0 and other constructs that rely on specific execution strategies forfeits this advantage.
- Karrot_Kream 4y agoHas anyone used Mercury? The language seems quite interesting and has C and C++ FFI. I see bower (https://github.com/wangp/bower/ https://github.com/wangp/bower/) a notmuch client is written in it.
- knewter 4y agoI just installed and use bower yesterday and also learned of Mercury yesterday. Bower was quite nice and compiling it in a language I'd never known existed was trivial.
- marcosdumay 4y agoIt also has explicit determinism declarations, that avoid what is IMO the largest Prolog problem, that your program unexpectedly gets some exponential slowdown. Added to that it has an explicit and srtict type system, and much saner numeric arithmetics (mostly because of the strict types). It also has explicit side-effects declarations, so you know if your code is pure or not. I have never used on anything non-trivial. So I don't know how it copes on the real world. But the language looks very nice.
- pabloski79 4y agoI quietly wonder within myself, could it be somehow used together with AI/NN? An old dream od marrying NN with rule based systems.
- rscho 4y agohttp://mcs.unife.it/~friguzzi/plp-book.html http://mcs.unife.it/~friguzzi/plp-book.html
- usgroup 4y agoI think software like alpha zero are an example of that —- tree search with policy learning which governs what gets searched.
- Manfred 4y agoYeah, there is the classic Bratko: https://www.amazon.com/Programming-Artificial-Intelligence-International-Computer-dp-0321417461/dp/0321417461 https://www.amazon.com/Programming-Artificial-Intelligence-I...
- ausbah 4y agotangentially, it's possible to convert any neural network into an equivalent decision tree. technically rule based, but incomprehensible due to the sheer number of layers
- slekker 4y agoAny resources you’d recommend for learning Prolog?
- bmitc 4y agoI have several books on Prolog that I still need to get through, but the one I have read (and need to finish) is Thinking as Computation. It’s a great book.
- hagendaasalpine 4y agoMy dad's job for a while was configuring telecoms in a DSL built atop of prolog. The worst thing - the development enviroment was MS Word.
- trenchgun 4y ago> The worst thing - the development enviroment was MS Word. I hope you are joking.
- mark_l_watson 4y agoGood comments here and the original Reddit thread. I just wrote Prolog material for a book I am writing: Prolog embedded in Python. I also have an embedded MiniZinc example. I have infrequently used Prolog over a 40 year period. Most interesting work project was rewriting a Common Lisp IR&D planning system in ExperProlog that supported nice graphics. The personal Prolog projects that most influenced me were using the semantic web library for SWI-Prolog in the early days of the semantic web: the best environment for learning about the SW that I found at the time.
- ggzor 4y agoThe Power of Prolog [0] is a fantastic blog/video series covering everything from basic syntax, theoretical basis, modern features and idiomatic constructs. I highly recommend it if you want to get the gist of Prolog and its modern features. If you want a tour of Prolog, you can watch the video with the same name [1]. [0]: https://www.metalevel.at/prolog https://www.metalevel.at/prolog [1]: https://youtu.be/8XUutFBbUrg https://youtu.be/8XUutFBbUrg
- gneray 4y agoI hear the comments that Prolog isn’t a “general purpose programming language” but indeed you can use it for a lot of use cases. Eg Authorization is one such use case. Polar is a logic programming language (like Prolog) specifically designed for authorization: https://www.osohq.com/docs/reference/polar-syntax https://www.osohq.com/docs/reference/polar-syntax
- deleted 4y ago[deleted]