11 ms·
Ask HN: What's Prolog like in 2024?
Hi, i am a compsci student that stumbled upon prolog and logic programming during my studies.
While i have seen the basics of vanilla prolog (atoms, predicates, cuts, lists and all that jazz) and a godawful implementation of an agent communication system that works on SICStus prolog. I would like to know more because i think that this language might be a powerhouse in per se.
Since my studies are quite basic in this regards i would like to expand my knowledge on it and kind of specialize myself both in this world and another world (ontologies :D) that i really enjoy.
What's prolog like in 2024? what are you wonderful people doing with it?
thanks from a dumbass :D
- mtsfz2 2y agoThere are certain (academic) problems for which Prolog is simply the best tool for the job, see e.g., https://github.com/hbrouwer/dfs-tools https://github.com/hbrouwer/dfs-tools
- moffkalast 2y ago> (academic) Ah, for a second I thought someone just found a way to make Prolog useful for something. What a terrifying thought indeed, luckily the crisis has been averted, the natural order is restored and all is well.
- pbronez 2y agoWish there was more discussion of Datalog here. That’s come up in a few interesting places and I’d love to hear about folk’s experience with it. https://en.wikipedia.org/wiki/Datalog https://en.wikipedia.org/wiki/Datalog
- thiagowfx 2y agoGerrit is one of the fewest major OSS I’m aware of that uses it: https://gerrit-review.googlesource.com/Documentation/prolog-change-facts.html https://gerrit-review.googlesource.com/Documentation/prolog-...
- DonHopkins 2y agofalse. https://www.j-paine.org/dobbs/prolog_lightbulb.html https://www.j-paine.org/dobbs/prolog_lightbulb.html
- DamonHD 2y agoNot quite what you asked for, but as someone using it quite a lot back in the late '80s during a CS&AI degree, Prolog has its interesting features and I'm glad I used it, but I haven't missed it since. I do like declarative stuff, eg CSS!, and that remains a good memory.
- overclock351 2y agocould you please expand on it? i would love to read more
- DamonHD 2y agoMany many languages that you will encounter and use in live projects are primarily imperative, eg: C, C++, JavaScript. The describe the "how" and "in what order". While I was an undergrad I was exposed to Standard ML and Prolog, both of which were/are much more about declarative "what", though they could only practically interact with the actual world by side-effects and some imposed ordering (SML's 'ref', Prolog's cut). I am still waiting for some of the amazing stuff that was in SML to materialise in C++ and Java for example, less so anything from Prolog. For example, to search a state space I might use an off-the-shelf solver with good heuristics and an objective function written in something imperative rather than use Prolog. But it it really is over 30Y since I touched Prolog, so life in it may be very different now.
- overclock351 2y agoPretty interesting stuff, thanks for sharing :D
- bux93 2y agoI'm not the commenter you're replying to, but in my case, I really enjoy the promise of "you write down the problem, not the solution". In an introductory prolog course you will soon find that when a prolog program is written to solve some problem like 'whats-the-next-chess-move' it's actually doing a depth first (and if you use the ! cut-operator, it will stop looking for any more solutions). But in principle, it's up to the interpreter/compiler to decide how to find solutions. In the same way that a C compiler might say "ah, you're doing tail-recursion, let me make a loop out of that", a prolog compiler might say "gee, this problem looks like it would be much more efficient to use simulated annealing to find some answers in a shorter time". That's perhaps a bit far-fetched, but a great example is Datalog which has solvers that parallelize the search. You don't write a parallel algorithm, it's just that a parallel algorithm is used to solve your problem. A specific feature I miss in other programming approaches is that if you can find the answer to the question "is A a child of B?", the very same code is also the function to find out all of A's children, or all of B's parents. No need to explicitly code a loop, or to create the inverse function.
- tomstuart 2y agoDefinitive reference: https://www.urbanautomaton.com/blog/2015/08/10/the-pledge-to-put-prolog-in-production/ https://www.urbanautomaton.com/blog/2015/08/10/the-pledge-to...
- overclock351 2y agoLooks fun :D, i think that if i ask my manager to build something out of Prolog i would probably get stab... i mean fired since most of us work in OOP. I would love to be that insane one asking for that :D.
- Avshalom 2y agoYou can use https://logtalk.org https://logtalk.org for oop in Prolog, use it on top of SWI and you have bidirectional bridges to Python an Java https://www.swi-prolog.org/FAQ/Python.md https://www.swi-prolog.org/FAQ/Python.md https://www.swi-prolog.org/pldoc/doc_for?object=section(%27packages/jpl.html%27) https://www.swi-prolog.org/pldoc/doc_for?object=section(%27p...
- chx 2y ago> Prolog is not suitable for any problem domain, although this is more readily apparent for some domains than others. Fuckin' A.
- jjtheblunt 2y agowhat does that mean?
- marcosdumay 2y agoIt's an except from the article. Getting an explanation out of context is worthless.
- jjtheblunt 2y agoExcerpt from what article? (edit: i see you're referring to the indented quote from the article, but i was asking what the "fuckin a." thing meant.)
- hendler 2y agoProlog itself is still developed and used in various settings (mostly swi-prolog?), but other languages and logic engines solve domain specific but similar problems better (rule engines, formal proof verifiers, etc). For exploratory work it can be useful. I have tried to use it in combination will LLMs unsuccessfully, partly because the domain was not specific enough. Otherwise you need a lot of real world knowledge and a large fact database. Logic engines for first order logic in RDF/OWL also have interesting logical inference abilities, like graphdbs. Any programming language can do "logic" and the work at MIT/CSAIL in probabilistic programming may turn out to be a better way to combine fuzzy logic and formal proofs. Not sure this answers your question, but maybe this points towards some interesting directions.
- overclock351 2y agoAny answer here is a good one since the question is soooo unspecific :D. My professor is a staunch advocate for RDF/OWL, inference engines and stuff like that (hence why i also mentioned ontologies :D). The thing is that i think that the language itself has so much untapped potential and the world that i dived into with my studies is so vast, so full of stuff that it left me kind of dazed to be fair! I got some papers in regards to knowledge representation (that to be fair i still have to read... exams and work got in the midst of all :/) but still it seems so... odd: when we were studying OOP in my bachelor we went over the usual examples that made you understand "this is not an imperative paradigm but there are object abstractions" while, in my studies, prolog and logic programming in general was seen as a tool of sorts for reaching an objective like "hey we have a MAS system, let's sprinkle some prolog in it for fun :D" (maybe i am exaggerating but it feels like this lol). I feel it can do much much more
- felixyz 2y agoYou are definitely on to something here. OOP has some common roots with formal ontologies and knowledge representation (not so much the programming languages, but object oriented modeling). OO fails at this for various reasons, whereas logic is tailored for this specific purpose. Check out ErgoAI (formerly Flora-2), it's the most advanced Prolog flavor for representing and reasoning over knowledge. https://github.com/ErgoAI https://github.com/ErgoAI
- xavxav 2y agoThere is still academic work on Prolog, and more broadly deductive / logic programming. If you are looking at things with a more industrial bent, I would look to Datalog which trades generality in Prolog for performance and predictability. Alternatively, you can go the other way and look at lambdaProlog which adds real abstractions / HOFs to Prolog. What I've seen in practice is that while Prolog may be good at describing a solution, its performance is often too lackluster and brittle for actual deployment: it probably fits more as a prototyping language before you do a classic implementation of the solution in a more traditional language.
- a-french-anon 2y agoNo idea, but it might be worth looking into Mercury and {mini,micro}Kanren/core.logic as more practical iterations on it (either by adding things to Prolog or extracting the interesting to stuff to use in more general purpose languages).
- Avshalom 2y agoAt the end of the day "practical" means library support and community knowledge, by which measure Prolog and more specifically SWI and Sicstus are far more practical than any of the other logic languages or implementation options
- harperlee 2y agoWell if your problem does not require a solution that’s 100% written in prolog, then any relational/CLP system that can be hosted or work as a library is going to win in terms of library support and community knowledge, at solution level. So e.g. a core.logic solution can make extensive use of the jvm ecosystem.
- sprayk 2y agoThe most recent prolog news I've come across in recent years is some updates to SWIprolog (can't find a good link) and some talk of Scryer-prolog[0] which is a more recent implementation of Prolog in Rust. One interesting development recently is a load of research into, reverse engineering of and emulation of the 1986 Sega AI Computer[1], which used prolog under the hood for mostly educational software. Unfortunately it does not seem there is a way to actually write some prolog for the thing today :( [0] https://github.com/mthom/scryer-prolog https://github.com/mthom/scryer-prolog [1] https://www.smspower.org/SegaAI/Index https://www.smspower.org/SegaAI/Index
- upghost 2y agoProlog has reached an exciting new milestone with Scryer prolog. It is the first highly performant open source iso-compliant Prolog. I would check out Markus Triska's work to have your mind blown: https://www.metalevel.at/prolog https://www.metalevel.at/prolog https://youtube.com/@thepowerofprolog https://youtube.com/@thepowerofprolog
- overclock351 2y agoDo you have any papers comparing Scryer with other prolog systems (like SWI-prolog or SICStus prolog) performance-wise ?
- jodrellblank 2y agoThere are some benchmarks here of SWI Prolog's benchmark suite on diffrent Prolog systems by Jan Wielemaker the SWI Prolog author: https://swi-prolog.discourse.group/t/porting-the-swi-prolog-benchmark-suite-comparing-8-prolog-systems/6997#the-modern-systems-vs-swi-prolog-2 https://swi-prolog.discourse.group/t/porting-the-swi-prolog-... He finds Scryer performs worse, which he does comment on, he also explains some tradeoffs and historic choices in SWI's design which affects its performance. I think I have seen the author of Scryer saying that's not surprising and Scryer is still building up core functionality where SWI has had 30+ years to optimise, but I don't remember where I read that. SWI has a document explaining some strengths and weaknesses regarding performance: https://www.swi-prolog.org/pldoc/man?section=swiorother https://www.swi-prolog.org/pldoc/man?section=swiorother Edit: some discussion on Scryer previously on HN: https://news.ycombinator.com/item?id=28966133 https://news.ycombinator.com/item?id=28966133
- katelyn2598 2y ago[dead]
- sirwhinesalot 2y agoNot sure about Prolog itself but Datalog really needs to overtake SQL, it's just so much better. Related areas like constraint programming are still very relevant.
- pfilo8 2y agoCould you explain more or point out some interesting references? I'm currently trying to understand how Datalog compares to SQL and, potentially GraphDBs
- greenavocado 2y agoProlog and Datalog example (they are identical in this case) % Facts parent(john, mary). parent(mary, ann). parent(mary, tom). % Rules ancestor(X, Y) :- parent(X, Y). ancestor(X, Z) :- parent(X, Y), ancestor(Y, Z). % Query ?- ancestor(john, X). The Prolog code looks identical to Datalog but the execution model is different. Prolog uses depth-first search and backtracking, which can lead to infinite loops if the rules are not carefully ordered. Datalog starts by evaluating all possible combinations of facts and rules. It builds a bottom-up derivation of all possible facts: a. First, it derives all direct parent relationships. b. Then, it applies the ancestor rules iteratively until no new facts can be derived. For the query ancestor(john, X): It returns all X that satisfy the ancestor relationship with john. This includes mary, ann, and tom. The order of rules doesn't affect the result or termination. Datalog guarantees termination because it operates on a finite set of possible facts. Prolog uses a top-down, depth-first search strategy with backtracking. For the query ancestor(john, X): a. It first tries to satisfy parent(john, X). This succeeds with X = mary. b. It then backtracks and tries the second rule: It satisfies parent(john, Y) with Y = mary. Then recursively calls ancestor(mary, X). c. This process continues, exploring the tree depth-first. Prolog will find solutions in this order: mary, ann, tom. The order of clauses can affect both the order of results and termination: If the recursive rule were listed first, Prolog could enter an infinite loop. Prolog doesn't guarantee termination, especially with recursive rules. SQL is more verbose. The equivalent of the Datalog/Prolog example above is: -- Create and populate the table CREATE TABLE Parent ( parent VARCHAR(50), child VARCHAR(50) ); INSERT INTO Parent VALUES ('john', 'mary'); INSERT INTO Parent VALUES ('mary', 'ann'); INSERT INTO Parent VALUES ('mary', 'tom'); -- Recursive query to find ancestors WITH RECURSIVE Ancestor AS ( SELECT parent, child FROM Parent UNION ALL SELECT a.parent, p.child FROM Ancestor a JOIN Parent p ON a.child = p.parent ) SELECT DISTINCT parent AS ancestor FROM Ancestor WHERE child IN ('ann', 'tom'); This is a more interesting example of how one might use Datalog on a large dataset: % Define the base relation friend(Person1, Person2). % Define friend-of-friend relation friend_of_friend(X, Z) :- friend(X, Y), friend(Y, Z), X != Z. % Define potential friend recommendation % (friend of friend who is not already a friend) recommend_friend(X, Z) :- friend_of_friend(X, Z), not friend(X, Z). % Count mutual friends for recommendations mutual_friend_count(X, Z, Count) :- recommend_friend(X, Z), Count = count{Y : friend(X, Y), friend(Y, Z)}. % Query to get top friend recommendations for a person top_recommendations(Person, RecommendedFriend, MutualCount) :- mutual_friend_count(Person, RecommendedFriend, MutualCount), MutualCount >= 5, MutualCount = max{C : mutual_friend_count(Person, _, C)}. The equivalent Postgres example would be: WITH RECURSIVE -- Base friend relation friends AS ( SELECT DISTINCT person1, person2 FROM friendship UNION SELECT person2, person1 FROM friendship ), -- Friend of friend relation friend_of_friend AS ( SELECT f1.person1 AS person, f2.person2 AS friend_of_friend FROM friends f1 JOIN friends f2 ON f1.person2 = f2.person1 WHERE f1.person1 <> f2.person2 ), -- Potential friend recommendations potential_recommendations AS ( SELECT fof.person, fof.friend_of_friend, COUNT(*) AS mutual_friend_count FROM friend_of_friend fof LEFT JOIN friends f ON fof.person = f.person1 AND fof.friend_of_friend = f.person2 WHERE f.person1 IS NULL -- Ensure they're not already friends GROUP BY fof.person, fof.friend_of_friend HAVING COUNT(*) >= 5 -- Minimum mutual friends threshold ), -- Rank recommendations ranked_recommendations AS ( SELECT person, friend_of_friend, mutual_friend_count, RANK() OVER (PARTITION BY person ORDER BY mutual_friend_count DESC) as rank FROM potential_recommendations ) -- Get top recommendations SELECT person, friend_of_friend, mutual_friend_count FROM ranked_recommendations WHERE rank = 1; Full example you can run yourself: https://onecompiler.com/postgresql/42khbswat https://onecompiler.com/postgresql/42khbswat
- aldousd666 2y agoI've actually been thinking about this quite a bit. I remember a foray into prolog when I was a younger pup in 2004-6. With the Advent of llms, I think that perhaps we could use llms to extract triples from large corpuses of text and then use that to build our prolog stores or ontologies and work on them. I haven't really experimented much with it but you saying this has reminded me that I should dig that back up again.
- felixyz 2y agoShameless plug: you should check out my podcast The Search Space for a view of the broader landscape of Prolog and logic programming: https://thesearch.space/ https://thesearch.space/ I don't publish episodes often but I have a lot of good interviewees lined up :) In general, I would advice you to look beyond Prolog and explore Answer Set Programming, the Picat language, and the connections between logic programming and databases (SQL, RDF or otherwise). Not instead of Prolog, but in parallel. Prolog is awesome!
- overclock351 2y agoASP is in another uni course of mine ;). I'll check the podcast, thanks
- forks 2y agoI'll second the plug: it's an excellent podcast
- harperlee 2y agoGood to know there is further content lined up! I’m subscribed and eagerly waiting for it!
- agumonkey 2y agothanks for the thread for allowing to find you and you for making the interviews
- duranga1234 2y agoI love your podcast! I wish you published episodes more often! I particularly enjoyed the first episode, the conversation with Robert Kowalski.
- shrimp_emoji 2y agoMy professor swapped Prolog out for Rust at the last minute. I don't know whether he did us a disservice or a favor.
- overclock351 2y agoThat is my point, i think that prolog isn't just a simple tool to solve stuff, i think that it's potential can still be explored (even if, to be fair, Rust can run on a functional paradigm setting)
- jeroenvlek 2y agoWhat a curious swap. May I ask which course he taught?
- shrimp_emoji 2y agoIt was a whirlwind "survey of languages" course. After blowing our minds with functional programming via OCaml, the last segment was traditionally logical programming via Prolog. But he decided to spare us, I guess, and made me fall in love with Rust for a few years. :p (Or he sadistically meant to inflict the trauma of knowing how much better C and C++ could be but never will be, which stays with you even after you stop using Rust and return to those.)
- tashmahalic 2y agoI’d love to hear more about your trauma :-). What are the main ways C and C++ could be better?
- shrimp_emoji 2y agoThe easiest answer: they should have a build and test and packaging system like Cargo built-in. The best you have is a tedious anarchy of third-party systems, of which CMake seems to have come out the winner. I use CMake, but it's no Cargo (as an understatement). Borrowing and ownership is great for building safe code, whether it's single- or multi-threaded. In C, you have a nest of pointers, and a pointer communicates nothing about the ownership of its memory. Stuff can go, and leak, and dangle, everywhere. C++ mitigated this a little with references. Then it bolted on smart pointers, mitigating it further. Without learning Rust, though, I don't think I'd be as good of a C/C++ programmer because, unlike Rust, those languages don't force you to think about where memory lives and where it's going. The module system is also way better. Then I could take cheap shots: `u8` is way better than `uint8_t`. Rust had slices from the beginning, to be able to refer to parts of strings in a cheap way with easy syntax, whereas only C++17 introduced the comparatively awkward `std::string_view`. There are ways I think Rust is worse though! The easiest is that it still doesn't have a standard and will probably not see the uniquely deep and broad support of C/C++ in my lifetime. :p
- pjmlp 2y agoI would say in the open source world, SWI Prolog is still the king implementation, in regards to tooling, language features beyond ISO Prolog, and toolchains. https://www.swi-prolog.org/ https://www.swi-prolog.org/
- overclock351 2y agoi've been aware of that for a while, it seems to be the state of the art at least in my university (to the point that to this day the researchers are trying to convert old prolog projects to this implementation)
- colanderman 2y agoThe CLP (constraint logic programming) systems available in some Prologs take it to the next level: https://us.swi-prolog.org/pldoc/man?section=clp https://us.swi-prolog.org/pldoc/man?section=clp
- tannhaeuser 2y agoWith compliments to your prof ;), interest in Prolog just now is recovering from a year-long focus on W3C's RDF/SPARQL. TBL surely had an itch to scratch with regards to logical knowledge representation dating back even longer than the web [1]. But Prolog has broader applicability not only in logical/knowledge graph querying, but also in solving all kinds of discrete combinatorical optimization problems. Or, as the Quantum Prolog site [2] puts it, "planning, optimization, diagnostics, and complex configuration." The site demos logistics optimization (in-browser demo) and reports initial optimization (parallelization) of Inductive Logic Programming and other ML tasks for partially auto-generating Prolog code from existing solutions. Edit: ... and on performance vs SWI Prolog, too [1]: https://en.wikipedia.org/wiki/ENQUIRE https://en.wikipedia.org/wiki/ENQUIRE [2]: https://quantumprolog.sgml.io https://quantumprolog.sgml.io
- PaulHoule 2y agoThe problem w/ OWL is that everybody wants to work with first-order logic + math, but Gödel proved it isn't decidable. For instance if I wanted to express financial regulations or business rules inside a bank or other business I'd need to use math: for instance to express the conditions for reserve requirements or approving a loan. OWL is best thought of as a set of templates for generating first-order logic rules that are decidable and also (in theory) quick to evaluate with the Tableau algorithm. In certain domains you might tolerate tools that are imperfect, like it isn't fair to expect a SMT solver to figure out this one x^N + y^N = z^N where x,y,z and N are all positive integers with N>2. For that one it would try to find solutions and probably time out. For some similar problems (a different polynomial) it might give you an answer. OWL doesn't want to go there which is a big reason people say "Nein Danke!"
- kstrauser 2y ago> Gödel proved it isn't decidable. He did no such thing. He proved undecidable problems exist in any system powerful enough to be useful. That doesn’t make those systems useless, though.
- 2y ago
- sproutini 2y agoThe problem with Prolog is that it's based on unification, and small unification engines can be expressed in a few lines in any functional programming language. That narrows down the already small niche where one would choose Prolog by probably a few orders.
- tpoacher 2y agoIs this in the same sense that "one could write lisp in 99 lines of c"? In my opinion, this does not imply that proper lisp (and correspondingly prolog) implementations are useless, just because a simple implementation can be written in a different, "more expressive" language.
- sproutini 2y agoNo, not really. A lisp in 99 lines of C would barely be useful. In contrast, Prolog mostly shines where you need reasoning/unification over a database of facts -happens pretty often,- but that's just too easily expressed in any proper functional language. And with a bit more pain in an imperative/OO language.
- jhbadger 2y agoThere is a very practical embedable logic-programming engine called miniKanren for many programming languages that can be used to add the logic-programming techniques of Prolog to other languages. https://en.wikipedia.org/wiki/MiniKanren https://en.wikipedia.org/wiki/MiniKanren There's a great book in the same series as the "Little Lisper"/"Little Schemer" books called "The Reasoned Schemer" that uses MiniKanren with Scheme.
- z5h 2y agoI've been using Prolog daily for the past 1.5 years. I've also implemented and used a Kanren in Elm, and there is simply a world of practical difference.
- btbuildem 2y agoFor some, how a language is implemented seems to be the paramount thing. For many, how the language faces the user, how its paradigms fit the problems at hand and the user's mode of seeing the world, that is more important. These days, with the terabytes the petaflops and the megajoules, it might be even less relevant how the gears are turning inside the black box.
- segmondy 2y agoIt's a powerhouse, an even bigger secret than Lisp at beating the average.
- zelos 2y agoEclipse CLP still seems slightly active: https://eclipseclp.org/ https://eclipseclp.org/. I used it for some process scheduling research in the early 2000s but I've never had the chance to apply it in the non-academic world
- rramadass 2y agoThough i only know Prolog cursorily it is in my todo list of languages to study. I think it has great value in that it teaches you a different paradigm for programming. You might also want to look at Erlang which is used in the Industry and would be helpful for your future. Joe Armstrong was originally inspired by Prolog and he conceived Erlang as Prolog-Ideas+Functional/Procedural+Concurrency+Fault-Tolerance. Hence you might find a lot of commonalities here. Here is a recent HN thread on a comparison - https://news.ycombinator.com/item?id=40521585 https://news.ycombinator.com/item?id=40521585 There is also "Erlog" (by Robert Virding, one of the co-creators of Erlang) which is described as, Erlog is a Prolog interpreter implemented in Erlang and integrated with the Erlang runtime system. It is a subset of the Prolog standard. An Erlog shell (REPL) is also included. It also says, If you want to pass data between Erlang and Prolog it is pretty easy to do so. Data types map pretty cleanly between the two languages due to the fact that Erlang evolved from Prolog. - https://github.com/rvirding/erlog https://github.com/rvirding/erlog
- btbuildem 2y agoHa! That explains a lot. I've started looking into Prolog recently, and there were some... familiar echoes in there, reminiscent of Erlang. But of course, the submarine is like a cigar, not cigar like a submarine.
- rramadass 2y agoThe Development of Erlang by Joe Armstrong (pdf) - https://dl.acm.org/doi/pdf/10.1145/258948.258967 https://dl.acm.org/doi/pdf/10.1145/258948.258967
- tannhaeuser 2y agoSure, Erlang was prototyped on Prolog because Prolog has excellent built-in facilities for domain-specific languages: you can define new unary or binary operators along with priorities and associativity rules (you can use this to implement JSON or other expression parsing in like two lines of code, which is kindof shocking for newcomers, but comes very handy for integrating Prolog "microservices" into backend stacks), and you get recursive-decent parsing with backtracking for free as a trivial specialization of Prolog evaluation with a built-in short syntax (definite clause grammars) even. But apart from syntax, Erlang has quite different goals as a backend language for interruption-free telco equipment compared to Prolog.
- gorkempacaci 2y agoProlog, and Constraint Programming especially are great to have in your toolbox. I’ve done research in the field for years, and my job in the industry today is writing Prolog. There are real issues with Prolog: - no proper module nor package system in the modern sense. - in large code bases extra-logical constructs (like cuts) are unavoidable and turn Prolog code into an untenable mess. SWI prolog has single-sided unification guards which tackle this to a degree. - lack of static and strong types makes it harder to write robust code. At least some strong typing would have been nice. See Mercury as an example of this. All being said, Prolog is amazing, has a place in the future of programming, and gives you a level-up understanding of programming when you get how the types in every OO program is a Prolog program itself.
- ecshafer 2y agoThere are a lot of problems that Prolog / Constrain programming will solve very elegantly, and much more easily than imperative languages. I think constraint based programming is seriously under used in the industry, and too many programmers are unaware or unable to write constraint based code. I have always hoped to have just a constrain based programming subsystem in a lot of languages, for those niche cases.
- ToucanLoucan 2y agoMaybe it's just me but I see a lack of a package manager as a massive, massive pro. I can't stand how seemingly every language has a package manager which requires it's own installation and you have to learn how to use THAT thing and then you need some library off github that does some minor task really well but you can't just download the fucking code, you have to import it via, idk, the Fork-Lyft manager which requires Python 3.3 and the PillJump framework and it's just like, I just want a fucking function to parse JSON, I don't want to saddle my system with 600 MB of shit I don't need. Old_man_yells_at_cloud.jpg
- qu1j0t3 2y agodon't confuse "module system" with "package manager"
- 2y ago
- DonHopkins 2y agoYou might be interested in reading about the Japanese "Fifth Generation Computer Systems" project from 1982, which revolved around PROLOG. https://en.wikipedia.org/wiki/Fifth_Generation_Computer_Systems https://en.wikipedia.org/wiki/Fifth_Generation_Computer_Syst... >The Fifth Generation Computer Systems (FGCS; Japanese: 第五世代コンピュータ, romanized: daigosedai konpyūta) was a 10-year initiative begun in 1982 by Japan's Ministry of International Trade and Industry (MITI) to create computers using massively parallel computing and logic programming. It aimed to create an "epoch-making computer" with supercomputer-like performance and to provide a platform for future developments in artificial intelligence. FGCS was ahead of its time, and its excessive ambitions led to commercial failure. However, on a theoretical level, the project spurred the development of concurrent logic programming. >The term "fifth generation" was intended to convey the system as being advanced. In the history of computing hardware, there were four "generations" of computers. Computers using vacuum tubes were called the first generation; transistors and diodes, the second; integrated circuits, the third; and those using microprocessors, the fourth. Whereas previous computer generations had focused on increasing the number of logic elements in a single CPU, the fifth generation, it was widely believed at the time, would instead turn to massive numbers of CPUs to gain performance. [...] >Concurrent logic programming >In 1982, during a visit to the ICOT, Ehud Shapiro invented Concurrent Prolog, a novel programming language that integrated logic programming and concurrent programming. Concurrent Prolog is a process oriented language, which embodies dataflow synchronization and guarded-command indeterminacy as its basic control mechanisms. Shapiro described the language in a Report marked as ICOT Technical Report 003,[7] which presented a Concurrent Prolog interpreter written in Prolog. Shapiro's work on Concurrent Prolog inspired a change in the direction of the FGCS from focusing on parallel implementation of Prolog to the focus on concurrent logic programming as the software foundation for the project.[3] It also inspired the concurrent logic programming language Guarded Horn Clauses (GHC) by Ueda, which was the basis of KL1, the programming language that was finally designed and implemented by the FGCS project as its core programming language. >The FGCS project and its findings contributed greatly to the development of the concurrent logic programming field. The project produced a new generation of promising Japanese researchers. https://www.sjsu.edu/faculty/watkins/5thgen.htm https://www.sjsu.edu/faculty/watkins/5thgen.htm >The Japanese Fifth Generation project was a collaborative effort of the Japanese computer industry coordinated by the Japanese Government that intended not only to update the hardware technology of computers but alleviate the problems of programming by creating AI operating systems that would ferret out what the user wanted and then do it. The Project chose to use PROLOG as the computer language for the AI programming instead of the LISP-based programming of the American AI researchers. The Japanese National Fifth Generation Project: Introduction, survey, and evaluation: https://stacks.stanford.edu/file/druid:kv359wz9060/kv359wz9060.pdf https://stacks.stanford.edu/file/druid:kv359wz9060/kv359wz90... >Abstract: Projecting a great vision of intelligent systems in the service of the economy and society, the Japanese government in 1982 launched the national Fifth Generation Computer Systems (FGCS) project. The project was carried out by a central research institute, ICOT, with personnel from its member-owners, the Japanese computer manufacturers (JCMs) and other electronics industry firms. The project was planned for ten years, but continues through year eleven and beyond. ICOT chose to focus its efforts on language issues and programming methods for logic programming, supported by special hardware. Sequential 'inference machines' (PSI) and parallel 'inference machines' (PIM) were built. Performances of the hardware-software hybrid was measured in the range planned (150 million logical inferences per second). An excellent system for logic programming on parallel machines was constructed (XLI). However, applicationswere done in demonstration form only (not deployed). The lack of a stream of applications that computer customers found effective and the sole use of a language outside the mainstream, Prolog, led to disenchantment among the JCMs. Japan's Fifth Generation Computer Systems: Success or Failure? https://www.reddit.com/r/prolog/comments/owb0xg/japans_fifth_generation_computer_systems_success/ https://www.reddit.com/r/prolog/comments/owb0xg/japans_fifth... https://instadeq.com/blog/posts/japans-fifth-generation-computer-systems-success-or-failure/ https://instadeq.com/blog/posts/japans-fifth-generation-comp... >This post is a summary of content from papers covering the topic, it's mostly quotes from the papers from 1983, 1993 and 1997 with some edition, references to the present and future depend on the paper but should be easy to deduce. See the Sources section at the end. [...] >Prolog vs LISP >Achieving such revolutionary goals would seem to require revolutionary techniques. Conventional programming languages, particularly those common in the late 1970s and early 1980s offered little leverage. >The requirements clearly suggested the use of a rich, symbolic programming language capable of supporting a broad spectrum of programming styles. >Two candidates existed: LISP which was the mainstream language of the US Artificial Intelligence community and Prolog which had a dedicated following in Europe. >LISP had been used extensively as a systems programming language and had a tradition of carrying with it a featureful programming environment; it also had already become a large and somewhat messy system. Prolog, in contrast, was small and clean, but lacked any experience as an implementation language for operating systems or programming environments. [...] >Fun Trivia >The one commercial use we saw of the PSI machines was at Japan Air Lines, where the PSI-II machines were employed; ironically, they were remicrocoded as Lisp Machines.
- emmanueloga_ 2y agoTangent to Prolog, perhaps check Flix, which includes logic programming features [1], and is discussed here from time to time [2]. -- 1: https://doc.flix.dev/fixpoints.html https://doc.flix.dev/fixpoints.html 2: https://news.ycombinator.com/item?id=25513397 https://news.ycombinator.com/item?id=25513397 2: https://news.ycombinator.com/item?id=31448889 https://news.ycombinator.com/item?id=31448889 2: https://news.ycombinator.com/item?id=38419263 https://news.ycombinator.com/item?id=38419263
- honorious 2y agoI have been interested in Prolog since my time at the University, and I loved the idea of logic programming. For "proper" Prolog, in 2024 it is a niche language alive in specific constraint solving applications, but not really used outside of that. I haven't seen anyone attempting at using prolog as a general purpose language since the 90'. Datalog and logic-inspired languages tend to pop up here and there as domain-specific languages. Rego is a recent incarnation which had good adoption for k8s and other "modern" systems. However, when trying to get people in my org to adopt it in practice, I saw engineers struggle with the paradigm when complexity grows to more than toy problems.
- PaulHoule 2y agoDon't forget the Datalog subset! In the 2000s I was interested in inference over RDF and wanted something a bit more than RDFS and OWL and found out about Datalog: https://en.wikipedia.org/wiki/Datalog https://en.wikipedia.org/wiki/Datalog There wasn't a lot of literature on it or implementations then but a few years later people realized it's a great query language for complex queries that does a great job on transitive closures, can do math (unlike OWL which won't do it because Gödel proved first order logic + math is a hot mess) I took a comparative programming languages course circa 1993, the instructor thought that that Prolog was a taste of the future of programming. At first I thought the way you can implement ordinary procedural code in Prolog was really clever but if you write very much of it I think it is awkward; for instance it is common to treat procedural success as a logical failure because that gets the behavior you want. It's counterintuitive that you could write a reasonably fast interpreter for Prolog but Warren figured out how to do it and it really is a neat trick. In the 1980s the Japanese Fifth Generation project dreamed about parallel Prolog on a machine with 100s of CPUs but it was discovered pretty quickly that you couldn't really parallelize Prolog execution so they came up with the less expressive language https://en.wikipedia.org/wiki/KL1 https://en.wikipedia.org/wiki/KL1 I am amused to see papers today where people are working on tasks similar to what they worked on in that project, parallelizing them with commodity hardware, and get scaling curves that look very similar to what was done with KL1. (In the end the 5GP settled on the same message-passing architecture that everybody else did until the GPU revolution came) One of the nicest examples in Prolog is writing a parser by just writing the productions which works because Prolog's resolver is quite similar to a common parsing algorithm. In the large however, you can add a library to a normal programming language like Python or Java where you write the same grammar in a DSL and it is handled by the library. See also production rules systems which use "forward chaining" with the RETE algorithm and variants for an approach which looks like Prolog in some ways but works in the reverse direction. My favorite example of this now is http://www.clara-rules.org/ http://www.clara-rules.org/ I built a prototype of a stream processing engine where the control plane was implemented as a set of production rules that would build a processing pipeline of reactive operators, key-value and triple stores and then tear it down. Unlike another stream processing engine I worked on, mine always got the right answers. I think a production rule system could be the target of a "low code" system. I'm a little disappointed that I've never seen a Javascript framework that uses production rules because they are a great answer to asynchronous communication choreography. (See complex event processing)
- Nihilartikel 2y agoI've brushed up against it in the form of datalog as the query language for databases like datomic and xtdb, so it's soul is alive and well! I'm also considering a prolog like domain specific language to make a state syncing engine with pure declarations of how the state in system A is reflected in System B, etc. Prolog itself may not be mainstream, but it is an answer to a the universal problem space of constraint solution, so comp sci will always be in its long shadow.
- Guthur 2y agoI chose to use prolog to essentially build an expert system across and heterogeneous data ecosystem. Prolog could certainly use some serious improvements to its tooling. But the language is simple enough that it doesn't prove too much of an issue. You can get some much out of language it can be very powerful. In the system we've built it makes up a purely logical core that is completely referentially transparent, we leave all the ecky side effecting to a host program.
- GistNoesis 2y agoThe "magic" of Prolog is built upon two interesting concepts : Unification ( https://en.wikipedia.org/wiki/Unification_(computer_science)#A_unification_algorithm https://en.wikipedia.org/wiki/Unification_(computer_science)... ) and Backtracking ( https://en.wikipedia.org/wiki/Backtracking https://en.wikipedia.org/wiki/Backtracking ). Often bad teachers only present the declarative aspect of the language. By virtue of being declarative, it allows to express inverse problems in a dangerously simple fashion, but doesn't provide any clue for a solution. And you are then using a declarative language to provide clues to guide the bad engine toward a solution. Making the whole code an awful mashup of declarative and imperative. Rules : - N integer, a integer > 1, b integer > 1 - N := a * b Goal : N = 2744977 You can embed such a simple problem easily but solving it is another thing. The real surge of Prolog and other declarative constraint programming type of language will be when the solving engines will be better. Unification is limited to the first order logic, high-order logic unification is undecidable in the general case. So we probably will have to rely on heuristics. By rewriting prolog goal solving as a game, you can use deep learning algorithms like alphago (Montecarlo tree search). This engine internally adds intermediate logical rules to your simply defined problem, based on similar problems it has encountered in its training set. And then solve them like LLM, by picking the heuristically picking the right rule from intuition. The continuous equivalent in a sort of unification is Rao-Blackwellisation (done automagically by deep-learning from its training experience) which allows to pick the right associations efficiently kind of the same way that a "most general unification algorithm" allows to pick the right variable to unify the terms.
- radomir_cernoch 2y agoDo you see a good way to include backtracking in an imperative programming language? I can imagine how unification would work, since the ubiquitous "pattern matching" is a special case of Prolog's unification. But I've never seen how backtracking could be useful...
- vmchale 2y agobacktracking is perilous in general; logic programming languages have really nice abilities for such but I don't know how to avoid pathological inefficiency.
- mvolfik 2y agoIf you are interested in small fun stuff, SWI-Prolog has network libraries. Just recently, I implemented a network gomoku (5-in-a-row) game in it for my school project: https://gitlab.mff.cuni.cz/volfmat1/prolog-network-gomoku https://gitlab.mff.cuni.cz/volfmat1/prolog-network-gomoku. Turns out you can also write quite imperative-style code with it :D
- grose 2y agoIt's great to hear new people are interested in the language! I was enlightened a couple years ago and fell in love. Currently I'm focusing on creating easy-to-use embeddings of Trealla Prolog using Wasm. You can find my TypeScript library here: https://github.com/guregu/trealla-js https://github.com/guregu/trealla-js and Go library here: https://github.com/trealla-prolog/go https://github.com/trealla-prolog/go. The goal is to make the libraries as painless as possible. Trealla is a portable and lightweight Prolog written in C that supports CLP(Z) and is broadly compatible with Scryer. It's quite fast! I'm currently using it for some expert system stuff at $work and as an internet forum embedded scripting language for $fun. Speaking of Scryer, they recently got their WebAssembly build working and I hope to contribute a JS library for them in the future as their API stabilizes. Scryer and Trealla are both aiming for ISO compatibility, so it's my hope that we can foster an ecosystem for modern ISO Prolog and provide more embeddings in the future. It's super convenient to get logic programmer superpowers in your favorite language. Also check out Scryer's new website: https://www.scryer.pl/ https://www.scryer.pl/ For something on the silly side, check out https://php.energy https://php.energy. Prolog Home Page, it's web scale :-). It's proof that you can integrate Prolog with bleeding edge stuff like Spin (server-side wasm ecosystem).
- vmchale 2y agoGirard has some commentary scattered about his writing. The search algorithms for logic programming are simply slow, it's a very interesting idea in programming languages, but there's a reason it's not widely used. > PROLOG, its misery. Logic programming was bound to failure, not be- cause of a want of quality, but because of its exaggerations. Indeed, the slogan was something like « pose the question, PROLOG will do the rest ». This paradigm of declarative programming, based on a « generic » algorithmics, is a sort of all-terrain vehicle, capable of doing everything and therefore doing everything badly. It would have been more reasonable to confine PROLOG to tasks for which it is well-adapted, e.g., the maintenance of data bases. > On the contrary, attempts were made to improve its efficiency. Thus, as systematic search was too costly, « control » primitives, of the style « don’t try this possibility if... » were introduced. And this slogan « logic + control13 », which forgets that the starting point was the logical soundness of the deduction. What can be said of this control which plays against logic14? One recognises the sectarian attitude that we exposed several times: the logic of the idea kills the idea. > The result is the most inefficient language ever designed; thus, PROLOG is very sensitive to the order in which the clauses (axioms) have been written.
- withoutboats3 2y agoThis is a great quote and sadly true. What text is this from?
- thih9 2y ago"The Blind Spot: Lectures on Logic" by Jean-Yves Girard
- YeGoblynQueenne 2y agoFor me this kind of criticism is very familiar. It comes from theoretical computer scientists who have these purist ideological convictions about how a declarative language should look and behave, that are as unrealistic, because impossible to implement on a real-world computer, as they are uninteresting for practicing programmers because strictly a matter of aesthetics. Such critics have never made anything useable themselves and are simply angry that someone else made something that works in the real world while they were busy intellectually masturbating over their pure and untouchable vision. Although I concede that my comment might be a bit unfair to Girard who did, after all, invent the mustard watch.
- 29athrowaway 2y agoWith ChatGPT it is a great time to learn new programming languages. Questions such as "give me table with a glossary of basic Prolog terminology with examples" as well as others can be helpful.
- evgskv 2y agoI think of Prolog as a general purpose logic programming language and Datalog to be logic programming more focused on data analysis. Data analysis is a very large area, so boundary might get blurry at times. If your data is in a relational database consider Logica - a Datalog family language that compiles to SQL and runs naturally on SQLite, Postgres, DuckDB and Google BigQuery. Easy to install, easy to play with in CoLab or any other Jupyter notebook. Works for data analysis (aggregation, filtering etc) that is commonly associated with SQL, as well as recursive logical querries commonly associalted with Logic programming per-se. Here is what it looks like for a data-analysis-ish query of finding popular baby names over time: # Count babies per year. NameCountByYear(name:, year:) += number :- BabyNames(name:, year:, number:); # For each year pick the most popular. TopNameByYear(year) ArgMax= name -> NameCountByYear(name:, year:); # Accumulate most popular name into a table, dropping the year. PopularName(name: TopNameByYear()); The classic grand-parent rule looks as usual: Grandparent(a, c) :- Parent(a, b), Parent(b, c); Here is a recursive program for finidng distances in a directed graph: D(a, b) Min= 1 :- Edge(a, b); D(a, b) Min= D(a, x) + D(x, b); Links to CoLabs: Grandparent, ancestor: https://colab.research.google.com/drive/1lujnnUOXsF6VrC9__jVB38DLNpZ3boVq?usp=sharing https://colab.research.google.com/drive/1lujnnUOXsF6VrC9__jV... Distance in graph: https://colab.research.google.com/drive/1sOCODHqN0ruxZSx_L-V6e9tJsIJE2sQj?usp=sharing https://colab.research.google.com/drive/1sOCODHqN0ruxZSx_L-V... Github repo: https://github.com/EvgSkv/logica https://github.com/EvgSkv/logica
- conjurernix 2y agoNot exactly a prolog, but Verse, a logical (and functional, or functional logic) programming language developed at Epic Games by Simon Peyton Jones of Haskell fame and Tim Sweeney. You can already use it to build mods for fortnite or something like that not really sure. But there's no open source compiler available yet.
- jodrellblank 2y agoWhat is it like? 50 years of historic cruft. Questionable whether there are more trip hazards than usefulness for ordinary coding. A fractured community which feels like there are more Prolog systems than Prolog code. Learning Prolog is less "how do I do things in Prolog" and more "how do I contort my things to avoid tripping over Prolog?". A few dedicated clever people and idealists and dreamers talking about ontologies and building things I don't understand, e.g. the link in https://news.ycombinator.com/item?id=40994780 https://news.ycombinator.com/item?id=40994780 that could either be genuinely "Prolog is suitable for things no other language is" or "Fusion is 10 years away" or "Perpetual motion is here and so is cold fusion!", I can't tell. But I suspect from the lack of visible activity out in the wider world, closer to the latter than the former. Or perhaps the people able to make use of its strengths are few and far between. There's a saying about driving to a town which has been hollowed out and is now a road through some empty store fronts and car parks: "there's no there there". The soul of a place is missing, it's no longer a destination, just some buildings on some land. Prolog has the opposite of that, a main road straight past it, few buildings or people, but there is a there there - an attractor, spark of something interesting and fun. Buried in years of cruft. Might be a Siren's call though, a trap - but if it is it appears less dangerous than the LISP one.
- chamomeal 2y agoWhat do you mean by LISP as a siren call? I’ve just started learning clojure and besides the lack of static types (which is pretty harsh for me), it seems like a fun and practical language.
- epgui 2y agoClojure is probably the most beautiful language I've ever worked with. Nothing is perfect, but Clojure is very simple and elegant.
- 7thaccount 2y agoOnly downside is I don't know Java, so some things that should be obvious are opaque to me.
- 7thaccount 2y agoMy honest opinion is to avoid Prolog for most enterprise needs in favor of a regular general purpose programming language that calls out to a mathematical or constraint solver via API when the need arises. This way you get a language that is easier to learn with a strong ecosystem of libraries along with a solver that is built for your particular problem. Prolog may excel in some niche cases that are documented out there which is fine. For the majority of cases I can think of...it is too esoteric. Prolog is SUPER cool though as is it's history. You should definitely play with it a bit.
- vector_spaces 2y agoTo piggyback onto OP to ask about something very loosely related: what about miniKanren? Are there any active projects or work being done here, either in academia or industry? Most of the ones listed on minikanren.org appear to be dead -- although I haven't gone through them all since last year
- tpoacher 2y agoYou may find this paper interesting: https://www.cambridge.org/core/journals/theory-and-practice-of-logic-programming/article/fifty-years-of-prolog-and-beyond/3A5329B6E3639879301A6D44346FD1DD https://www.cambridge.org/core/journals/theory-and-practice-... title: Fifty Years of Prolog and Beyond (2022)
- waldrews 2y agoThere are a few magical algorithms/systems which give you superpowers if you can find the right application for them. At least in the pre-LLM era, they were some of the magical tools we had, for just solving declaratively specified difficult problems without us explicitly writing code, while (unlike certain AI techniques which shall remain nameless) providing correctness guarantees and often being deterministic and stable. Prolog and logic programming is one, together with its relative, constraint logic programming, and its relative mixed integer programming, which in turn is part of the broader linear and convex programming family. What else should we put in that category?
- z5h 2y agoIn theory, Prolog is the king of languages. Simultaneously a logical formalism, and (with a resolution system) a language for computation, AND the ultimate meta-programming language as its homoiconic but only goals are evaluated (there is no eager/lazy evaluation fuss - a term is just a term), and goals can only succeed (and have any consequence) if there is already a matching clause. In practice, there are some very performant and maintained implementations with small but helpful communities. Also in practice. With all of this power, it's clear that anything could be done (well) in Prolog, but it's not always clear what that way might be. DCGs are an example of a beautiful, elegant, simple, powerful way of building parsers (or state machines) that was not immediately evident to the Prolog community for some time. The perpetual conundrum as a user will be "I could do it this way, but there are certainly better ways of doing this, and I have many avenues I could explore, and I don't know which might be fruitful in what timeline".
- wkyleg 2y agoI like Peter Norvig's book "Paradigms of AI Programming," where you learn old fashioned symbolic AI with LISP and Prolog. Is it outdated? Absolutely, but it is a classic read. Maybe a use case for new AI models could be creating more old fashioned expert systems written in LISP or Prolog that are easier for humans to audit. Everything tends to come back full circle. https://www.amazon.com/Paradigms-Artificial-Intelligence-Programming-Studies/dp/1558601910 https://www.amazon.com/Paradigms-Artificial-Intelligence-Pro...
- foobarqux 2y agoLogic programming is overrated, at least for logic puzzles (2013) https://news.ycombinator.com/item?id=36154011 https://news.ycombinator.com/item?id=36154011
- harperlee 2y agoAnd the response for the curious: Logic programming is underrated (also 2013): https://news.ycombinator.com/item?id=5846185 https://news.ycombinator.com/item?id=5846185
- gnulinux 2y agoI recommend that you check Souffle programming language out, here: https://souffle-lang.github.io/index.html https://souffle-lang.github.io/index.html * It is a dialect of Prolog * It reads from and writes to SQLite database format as well as CSV. This allows you to preprocess or postprocess data Souffle produces, or Souffle reasons. E.g. you can generate bunch of data in Python, output Sqlite, reason in Souffle. Load reasoning output back into python via sqlite. * It is pretty feature complete when it comes to logical reasoning, and transactional database management. You get best of both Prolog and Sqlite worlds.
- hpincket 2y agoI've played around with Prolog on and off for 7 years. Still a novice. It's one of those languages that forces your mind to grow in new directions. It's difficult to make a case for it. The declarative paradigm is nice, but compared to other languages you're only saving a couple for-loops. I think its benefit comes from expressiveness for problems where clpfd can be applied. I once built an internal tool with Python and SWI Prolog that combined user input with CLPFD to configure test accounts in a consistent and useful way. Users could provide partial constraints, and the system would fill in the rest. Again, the ease of clpfd is great. I've had some fun generating Prolog facts/databases with LLMs and it's something I want to explore more. Note: I was just messing around with Prolog this week: https://hpincket.com/adding-an-easter-egg-to-our-numeronym-predicate.html https://hpincket.com/adding-an-easter-egg-to-our-numeronym-p...
- throwaway4aday 2y agoIt's an interesting but fundamentally flawed idea. My suggestion would be to play with it and have fun but don't bet the house on it. If you're curious what the flaw is, think Empiricism vs Rationalism.
- ghufran_syed 2y agoI know almost nothing about prolog, but I enjoyed this tutorial using Datalog, a subset of prolog as an alternative data query language to SQL: https://www.learndatalogtoday.org/ https://www.learndatalogtoday.org/
- wolfspider 2y agoFormal verification uses Prolog a lot. System on TPTP at U of Miami utilizes this for many of the formally verified tests on there. It is just a more intense discipline than general programming which is why I’m perpetually drawn to it trying to find more real world applications. It is not exactly Prolog but close enough to mention the similarities.
- WaterScorpion 2y agoAs someone who had the exceedingly rare opportunity to experience professional context Prolog. Lol. Lmao. Even.
- fuzztester 2y agocut.
- evgskv 2y agoyes.
- fuzztester 2y ago[flagged]
- AlexeyBelov 2y agoI'm reporting this to dang via email. This uncivility has no place on this sub.
- kamaal 2y agoIf you are struggling to get Prolog. Think about it this way. In a regular programming language you write code and then write unit test cases to validate it. In prolog, all you do is write the test cases and then its up to the compiler to write and run the code for you. In other words you define a set of cases for which a logic is supposed to hold true. The compiler then decides what the code must look like if that is the case. This might look easy for simple True/False kind of cases. But when you have to write test cases for functions that return deeply nested data structures and all their variations. Then it becomes easier said than done. The other part that makes Prolog hard to get, is you are only allowed recursion to iterate or define things. All of this makes it a little hard to think, write and trouble shoot Prolog. If you are reading Prolog code then try to think of it like you have access to a code repo's unit test cases, but the actual code doesn't exist. The test cases are considered sufficient enough to define the code in a concrete way. As you might have started to notice by now. This is actually harder than writing the code itself. In a regular programming language, you get sufficient space to write a function that might not do 100% of what was intended(bugs). Im prolog such an adventure will produce absolutely something else altogether.
- ristos 2y agoProlog is a really interesting language. It's like lisp in that, it's definitely worth learning very well, even if you don't find a use-case for it, because the things you learn help you think about programming in a whole new way. The prolog community is pretty active. SWI has a discourse group. There's SWISH, CLP(FD/Z), abduction via CHR (a rewrite system) or libraries like ACLP. Prolog is homoiconic, and it achieves it in a unique way, via things like functor/3 and =../2 rather than a macro system. There's growing interest in ISO-standard, pure, monotonic prolog for writing large, clean prolog codebases. SWI is the most mature prolog, but Scryer and Trealla are very active and ISO conformant. Trealla is quite embeddable, particularly in javascript codebases. There's also janus for python, and the community is looking to integrate prolog with LLMs. Prolog shines for writing bidirectional parsers, NLP, expert systems, abductive reasoning, and constraint logic programming. Pure monotonic prolog has some very useful properties in terms of debuggability, making it useful for large prolog programs. There's also some interesting work in developing pure io (library(pio)). Prolog also has a few different techniques for coroutining, including shift/reset. Markus Triska has a very nice youtube series and book on prolog that's worth watching/reading. The main downside to prolog is really just that there's a steep learning curve to it that puts a lot of people off and prevents it from gaining more traction, similar to why langs like lisp, haskell, and idris have trouble gaining traction. SWI has a lot of features, but it's also not ISO conformant, and a lot of libraries aren't portable and/or feel very procedural/imperative, which defeats the purpose of prolog. The useful libraries can often be ported to less popular prologs that are more promising, like scryer and trealla. For example, I managed to port ACLP to trealla yesterday without much effort, which is a pretty useful abductive system for writing expert systems or any sort of abductive reasoning.
- ristos 2y agoYou can also change the search strategy used in Prolog, ie using library(search), supporting BFS and iterative deepening. Tabling is also supported. Another useful tool for homoiconicity is clause/2: ?- assertz((foo(X) :- append(X, _, [1,2,3]))). true. ?- clause(foo(X), Body). Body = append(X, _, [1, 2, 3]). If you really like Haskell and OCaml's pattern matching, you'll probably really love Prolog. Prolog's pattern matching is much more powerful.
- fraber 2y agoProlog is very, very dead. I love Prolog with all my heart, but it excells at problems that are solved today much more efficiently using neuronal networks. So it's utterly obsolete. The issue of Prolog is that you need to code your rules manually. Doing ML with Prolog is possible, but very clumsy. Better stick to Python. Speed is irrelevant, because most problems suitable for Prolog are exponential. Implementation is irrelevant, because SWI-Prolog does all you need with good integrations, except that it's a bit slower. But that's irrelevant, see above. Learning Prolog is a great experience for any advanced computer science student. It amazes, doesn't it?
- gorkempacaci 2y agoProlog was never good at the things they thought it would be at, like AI, which is better done by ML today, specifically often like you said, with NNs. But it turned out to be good for other things, and those use cases are still alive today, even though there are many competitors. Look at Tiobe index, Prolog's usage is constant just under 1 percent, and has been for decades. So it's good for something.
- YeGoblynQueenne 2y agoProlog was never designed for function approximation, like Neural Nets, so there is no comparison. Machine Learning with Prolog is perfectly possible and not at all clumsy. In fact these days we can even say it is done elegantly, by raising everything to the second order of logic where deduction and induction become one and the same. Let me know if you need links and refs, but please try to keep your knowledge up-to-date before making big, splashy statements like "Prolog is very, very dead".
- YeGoblynQueenne 2y agoHere's what I'm doing with Prolog: https://github.com/stassa/louise https://github.com/stassa/louise Louise is a Meta-Interpretive Learning (MIL) system. MIL is like a second-order Prolog where first-order programs are learned from higher-order programs by Resolution. There's a long thread of literature on MIL going back to 2014 but it now seems we're starting to move towards applications, e.g. I'm doing a post-doc where I use MIL to learn autonomous behaviours for an agent that must guide a mobile robot in survey missions. Other colleagues are working on applications in biology. We're going slowly because there's very few of us but MIL is a powerful technique that extends the soundness and completeness of SLD-Resolution to induction, so I'm hopeful that good things will happen with a bit of elbow grease and a bit of patience.
- mnjksd 2y ago[flagged]
- wedesoft 2y agoThere is also miniKanren (e.g. Clojure core.logic is a. implementation). miniKanren is more generic than Prolog.
- rscho 2y agoMiniKanren, being purely relational, is a subset of Prolog.
- norswap 2y agoI'm fairly familiar with Prolog, from its operations & implementation, having also thaught it to students. Something I never really grokked however is: when to reach for it? It seems like a powerful tool for a certain class of problems, but somehow I never seem to stumble upon them. An obvious candidate is problems that map clearly to solvers that can limp along with sub-state-of-the-art performance. Solving sudokus is the classical classroom example. But somehow again, never really ran into something that maps to that (I have worked mostly in compilers and distributed system, with a smattering of application programming (frontend/backend)). Any ideas or anecdotes?
- nknld 2y ago[flagged]