6 ms·
Prolog is awesome and I recommend learning it if only for kicks and experiencing foreign programming paradigm. Many concepts are expressed in a completely diff
by xlii 3y ago
Prolog is awesome and I recommend learning it if only for kicks and experiencing foreign programming paradigm. Many concepts are expressed in a completely different and (when paradigm "kicks in") are arguably much simpler.
E.g. in Prolog you don't usually operate on collection but instead provide information what the collection item actually is and then let the implementation figure it out. Drawing dependency tree is an effect of 3 rules: what is an entity, how to figure out that entity X and Y have relation, how to represent it.
I have 2 gripes with it, though. One is that it's difficult and thus it's hard to convince people to learn/use it. Second - I didn't yet found way to seamlessly integrate it into other apps (I know that FFI is an option, but it doesn't convince me as production ready).
For the last couple months I've been looking for some more "production" Prolog alternatives but what I found so far (LispWorks, Franz Allegro CL) costs a kidney and is not integration friendly.
If anyone has success integrating Prolog in modern software please share, I'm really curious.
I'm also looking for some GUI solutions in it as XPCE doesn't work on Mac :(
Oh, and check out the Swish for online notebook:
https://swish.swi-prolog.org https://swish.swi-prolog.org
- pipo234 3y agoI've worked a couple of years developing supply chain optimization software in C++ using ILOG constraint propagation software (Solver, now owned by IBM). At the time we considered BinProlog. It had built range propagation, compiled to native x86 and had descent FFI interop. Nevertheless seems to have been abandoned in favour of SWI prolog and GNU toolchain. Not sure about GUIs; I would consider that a very different expertise. We used our own canvas C++ rendering engine and some horrible integrated 4GL devtool call "4D", or "Fourth Dimension". https://www.tomshw.it/data/images/2/0/4/3/infor-advanced-scheduling-19643f201a247ba8ee38058f679d40a5d.jpg https://www.tomshw.it/data/images/2/0/4/3/infor-advanced-sch...
- zelos 3y agoI spent a year while failing to get a PhD in process scheduling writing all the constraints in Prolog, before the university got an ILOG license and I realised how much time I'd wasted.
- alex_lav 3y ago> Prolog is awesome and I recommend learning it if only for kicks and experiencing foreign programming paradigm. Many concepts are expressed in a completely different and (when paradigm "kicks in") are arguably much simpler. Seconded. Probably the biggest mind-explosion type experience as a programmer in my entire life. Even something simple like building a Sudoku solver is insanely fun IMO.
- bmitc 3y agoI agree. Prolog was the only time I've been very much mindblown when learning programming languages. Erlang/Elixir is a close follow-up, but that was more of the seamless nature of it all and not really the ideas like Prolog.
- bmitc 3y agoYou may be interested in Shen. It has this KLambda kernel language that can be implemented by a host platform, which then gives you the entire Shen language that includes a Prolog. I recently learned about this.
- bjackman 3y ago> If anyone has success integrating Prolog in modern software please share, I'm really curious. Not sure if these count but: - Gerrit's submit predicates are configured in Prolog. (Edit: deprecated!) - An internal product I worked with at Google is built around a Datalog knowledge base that gets codegen'd. Then you can query it directly or use a UI to generate queries. Both of these seem to work nicely but they're pretty limited use cases. My experience with Prolog at university was that it was pretty fun but there's just no way I would wanna use it for anything that isn't inherently Prolog-shaped. As soon as we were implementing nontrivial stuff in it the abstraction leaked like a sieve and you felt mostly like you were hacking against the backtracking algorithm rather than taking any actual advantage of the language.
- xlii 3y agoYeah, Gerrit predicates being deprecated are (in my opinion) sign how hard it is to convince people to use Prolog. If people maintaining Gerrit cannot use it (and probably there was push at Google too), then how to convince The Median Dev...?
- hanwenn 3y agoNot sure what "push at Google" means. For full context: the idea to use Prolog came from the project founder. In retrospect, it was a terrible idea, because almost nobody knows or likes Prolog, and that includes the SWEs at Google both on my team, and the ones configuring Gerrit. (I run the team that works on Gerrit at Google.)
- ahefner 3y agoI understand in practice that "nobody knows or likes Prolog" is a valid criticism, but was it a sound idea technically?
- bbor 3y agoI'd say "we don't have the human resources to support the development of this system in the long term" to be a pretty valid technical reason. Remember that we're engineers, not scientists -- the goal is efficacy
- OrangeRange 3y agoWhen working in Java a couple of years ago I once ran into a random Prolog error. Turns out that the XML parser used by a large subset of the Java world is written in Prolog (Hint: the error came from an Apache lib, just like in this link: https://stackoverflow.com/questions/3030903/content-is-not-allowed-in-prolog-when-parsing-perfectly-valid-xml-on-gae https://stackoverflow.com/questions/3030903/content-is-not-a...)
- tannhaeuser 3y agoNope, that's a misunderstanding on your part I'm afraid. The "prolog" in that error message/SO question refers to an XML prolog, which is the part in an SGML/XML document up to the first content element ie. an XML declaration and a DTD, both optional.
- jodrellblank 3y agoThat's https://www.merriam-webster.com/dictionary/prologue https://www.merriam-webster.com/dictionary/prologue - "the preface or introduction to a literary work".
- hooby 3y agoI had to do a little bit of Prolog back in University, decades ago, and it broke my head. I managed to actually solve all the programming tasks we were given (and as I was the only one to do so among my peers, many copied my solutions) - but if anyone then asked me to explain how I did it, I was at a loss. I basically stared at the screen until some sort of intuition hit, and if that didn't work, repeat the process until it does... I guess the paradigm never really "kicked in" for me ;)
- xlii 3y agoCan I suggest adding it to a "when I'm REALLY bored" list? ;-) It took me years for Prolog to kick in and it did when I was trying to... optimize my taxes in a very complex context (e.g. where I live there's a VAT difference on ketchup depending if it's sold on the fresh hot-dog or wrapped one). But since then I try to advocate and use it as often as I can. Mostly because paradigm is super fun to work with and refreshing after all day of working on "normal" languages.
- bux93 3y agoI had the same experience at university. Then, say 5 years later, it "kicked in" and I kept wondering "why isn't this implemented in prolog?" at many, many points.
- tannhaeuser 3y agoWhile there are solutions based on foreign function interfaces and host calling conventions for particular Prologs, you'd basically integrate the kind of apps envisioned/demoed on the Quantum Prolog site [1] like you would any other modern subsystem - as a SaaS and/or via containers. Let's say you have a Prolog optimization app for your business domain, such as an elaborate version of the container ship scheduling problem discussed on the site [2]. Traditionally you'd generate Prolog facts encoding the problem instance, and then invoke Prolog to solve the problem and output one or more found solutions. A variant of this expecting a certain directory structure with facts/rules to exist is used by the Aleph machine learning package also demoed on the site [3]. This is popular and very flexible because of Prolog's ultra-flexible term datatypes. Alternatively, you can implement, in Prolog itself, a small wrapper to parse a JSON representation of your problem instance, where "implement" doesn't really describe it since basic JSON parsing using Prolog's built-in operator precedence parser is as easy as :- op(600, xfy, :). MyJSON = { "this": "bla", "that": 100, "L": [ 1, "two", 3 ] } but applied to standard input using term reading, provided your Prolog has curly braces (should come with ISO DCGs). The in-browser variant of Quantum Prolog [4] emits JSON right away. An API/language binding to call Prolog from a particular host environment is less suited for the kind of apps discussed on the Quantum Prolog site since these tend to be longer-running, and potentially parallelized workloads. But let's say a multiplayer game universe represented as Prolog database (or maybe a highly interactive solution viewer/picker under very particular circumstances) might need a different integration model. [1]: https://quantumprolog.sgml.io/ https://quantumprolog.sgml.io/ [2]: https://quantumprolog.sgml.io/container-planning-demo/part1.html https://quantumprolog.sgml.io/container-planning-demo/part1.... [3]: https://quantumprolog.sgml.io/bioinformatics-demo/part1.html https://quantumprolog.sgml.io/bioinformatics-demo/part1.html [4]: https://quantumprolog.sgml.io/browser-demo/browser-demo.html https://quantumprolog.sgml.io/browser-demo/browser-demo.html
- Scicomath 3y ago[dead]
- maweki 3y ago> I didn't yet found way to seamlessly integrate it into other apps (I know that FFI is an option, but it doesn't convince me as production ready). There is indeed an issue with side-effects that doesn't work well with the backtracking semantics. And I am not sure there's a good solution for it. Other LP languages, like Curry, just forbid side-effects under nondeterminism and you have to collect and handle them using an implementation of effect-handlers if they aren't at the top level. That's a quite restrictive solution that needs a lot of discipline, a good architecture, and framework support. But Prolog, doing side-effects whenever, wherever such a side-effect-entailing predicate is encountered as a proof goal doesn't work either and you're bound to make your life very difficult. Even if you are careful, the code that you produce, just looks like imperative code. So nothing really gained here from using Prolog. I'm still looking/researching about solutions inbetween. Without too too much success.
- tannhaeuser 3y agoMaybe you can review Quantum Prolog's optional reification of the regular Prolog database in order to be able to backtrack over assert/retract and other destructive predicates to represent actions in eg. robotic planning. Works basically like a call/1 variant where the Prolog database to evaluate against is specified as argument rather than assumed as implicit global default, with the database a freely manipulatable list term of facts or even rules. See [1]. [1]: https://quantumprolog.sgml.io/container-planning-demo/part2.html https://quantumprolog.sgml.io/container-planning-demo/part2....
- maweki 3y agoThat's a nice idea and it kind of works with the internal database. But in terms of FFI or other interactivity, you can't un-read bytes from an input stream or un-write to another process. That makes interoperability inherently imperative. My use case is, that you usually wouldn't un-move a robot. You want to re-plan from the current position, if an obstacle comes up. You sure as hell don't want to backtrack into an alternate plan from your original starting position.
- 3y ago
- gleenn 3y agoClojure has a Prolog library written for it called core.logic. I definitely didn't know Prolog well enough to make good use of all the esoteric function names but it seemed cool. https://github.com/clojure/core.logic https://github.com/clojure/core.logic
- deleted 3y ago[deleted]
- FreakLegion 3y agoCore.logic is a miniKanren with some Prolog-ish additions. If you're thinking of names like membero and appendo, those are from miniKanren.
- chuchana 3y agoI know it's not Prolog, but since you mention Lisp: have you checked out Screamer (https://nikodemus.github.io/screamer/ https://nikodemus.github.io/screamer/)?
- xlii 3y agoI did and it's one of my favorite implementations actually! Unfortunately I get this weird vibe with many Common Lisp libraries that they feel... legacy and deprecated. For sure CL isn't super popular language and it is very stable, but minimal development dynamic makes me feel insecure about the solution.
- worthless-trash 3y agoImho, that vibe is great once you get use to it. I think the programming community expects more updates when it simply isnt required.
- scns 3y agoIt sounds similar to Clojure libs. It might be an Illusion. Maybe those libs are done, zero to minimal need for further development! Our perception is shaped by regular bugfixes in other languages
- vintagedave 3y ago> If anyone has success integrating Prolog in modern software please share This doesn't directly answer you, but Prolog was used by David Hovell the Windows NT network configuration to enforce consistency [1][2]. I've heard it's been removed since, so doesn't count as "modern". It's a _beautiful_ application of Prolog though. [1] https://news.ycombinator.com/item?id=36821871 https://news.ycombinator.com/item?id=36821871 which leads to https://web.archive.org/web/20030218034509/http://www.research.microsoft.com/research/dtg/davidhov/pap.htm https://web.archive.org/web/20030218034509/http://www.resear... -- very worth reading! [2] https://news.ycombinator.com/item?id=14046420 https://news.ycombinator.com/item?id=14046420
- marcosdumay 3y agoI do think that the best way to enforce validation rules is with a logic-paradigm language executed both during compile and run times. That would technically be a dependent type system, but with a bias of allowing runtime verification, instead of trying to prove everything at compile time.
- anon____ 3y agoRacket has Racklog: > Racklog is an embedding of Prolog-style logic programming in Racket. “Embedding” means you don’t lose Racket: You can use Prolog-style and conventional Racket code fragments alongside each other. Racklog contains the full repertoire of Prolog features, including meta-logical and second-order (“set”) predicates, leaving out only those features that could more easily and more efficiently be done with Racket subexpressions. https://docs.racket-lang.org/racklog/index.html https://docs.racket-lang.org/racklog/index.html Racket also has GUI, and basically everything else you may need.
- fuzztester 3y ago>Racket also has GUI, and basically everything else you may need. How about good docs and examples, community, decent perf for small apps at least? Racket newbie here. Had just played around with a little some years back when it was called MZ Scheme, PLT Scheme or such. There was an IDE called Dr Scheme, IIRC. I guess all that is part of Racket now.
- anon____ 3y agoDocumentation and educational material is where Racket is unbeatable: https://docs.racket-lang.org/index.html https://docs.racket-lang.org/index.html. The performance is around Python / general scripting level; perfectly acceptable. As you guessed, DrScheme became DrRacket. You can find more info at https://www.racket-lang.org https://www.racket-lang.org, presented much better than I could do here.
- fuzztester 3y agoThanks.
- klibertp 3y agoDocs - oh boy. 90% of contributors to Racket are educators with many decades of experience teaching. The quality, depth, organization, interlinking, examples, references to papers... basically everything about Racket docs is at the level you just don't see anywhere else. Both the reference and guide are works of art. You get Realms of Racket and Beautiful Racket on top of that. Programming Languages: Application and Interpretation you'd find on the same shelf as SICP. How to Design Programs should be mandatory reading (and an antidote for the mind) for every OOP-focused dev out there (though, by the time they're "OOP-focused" they're most likely a lost cause anyway...) What's funny here is that Racket includes an OOP system, which is also described with incredible detail and thoughtfulness. The way they derive mixins from first-class anonymous classes is beautiful and enlightening. I've learned so much from docs.racket-lang.org that no other single resource can even begin to compare. Performance: closer to Groovy, Clojure or Raku than to Python, Ruby or JS. That is, startup is not as fast, but execution after that is decent. For a few years, performance improvements were not the focus of development due to the migration from custom VM to Chez Scheme. Now Racket on Chez is the default and I think we'll see further improvements on that front (easier maintenance and better potential performance were the reasons behind the migration IIRC.) The community is small, and the core strength of Racket is not something normal programmers use in day to day programming (that strength being the ability to shape the syntax and semantics of your code at will, ad hoc, anytime, with no friction at all, in any way you want). On the other hand, the results of giving that power to a bunch of very smart people are really worth seeing.
- verdverm 3y ago> I recommend learning it if only for kicks and experiencing foreign programming paradigm. Many concepts are expressed in a completely different and (when paradigm "kicks in") are arguably much simpler. I say the same thing about CUE these days, it can be a real mind bender but gives us a new way to think about taming config and schema complexity. CUE is also much easier to add into existing workflows to turn that logical programming glory into pragmatism. https://cuelang.org https://cuelang.org | https://cuetorials.com https://cuetorials.com
- nmfisher 3y agoThis looks really interesting, thanks for linking. Is this a Google project? It wasn't immediately clear.
- verdverm 3y agoIt was originally developed at Google, but Marcel is no longer there, there is a team and company behind it now. The language is going to a foundation (still waiting for update from the CUE team), fun fact, it started as a fork of Go (for the lexer, parser, and a bunch of goodies in that source tree) CUE's history is from borg, borgfig, GCL, but takes the approach Marcel always wanted to if not tied to the existing practices in a large company, namely Typed Feature Structures and logical programming (no overrides, layering, inheritance, general recursion) We're about to release a TUI for working with CUE, and hoping that it will make learning much easier for people. We do a lot with Cuetorials, but there is only so much you can do on a website (/rant WASM limitations). Using the Go SDK is the way to unlock CUE super powers. https://github.com/hofstadter-io/hof https://github.com/hofstadter-io/hof
- iot_devs 3y agoYou are looking for souffle: https://souffle-lang.github.io/ https://souffle-lang.github.io/
- throwaway290 3y agoYarn Berry used Prolog for constraint definitions, but I think they gave up on it...
- Ayc0 3y agoIn yarn 4, they introduced an equivalent using pure JS But I don't know if they still support prolog (or maybe as a plugin provided by them for the migration)
- alfiedotwtf 3y agoCheck out Mercury! [1] - Strongly typed and integrates with other languages really really nicely. Besides the reference material on the official site, there's a lovely crash course [2] as well. Prince's [3] base is Mercury and integrates Rust and C without fuss. [1] https://mercurylang.org/ https://mercurylang.org/ [2] https://mercury-in.space/crash.html https://mercury-in.space/crash.html [3] https://www.princexml.com/ https://www.princexml.com/
- okaleniuk 3y agoIn a way, every static typed compiler has a bit of Prolog in it: https://wordsandbuttons.online/logic_programming_in_cpp.html https://wordsandbuttons.online/logic_programming_in_cpp.html
- cylinder714 3y agoI'm really enjoying your book of essays, So You Think You Know C [PDF]: https://wordsandbuttons.online/SYTYKC.pdf https://wordsandbuttons.online/SYTYKC.pdf
- okaleniuk 3y agoThank you!
- prepor 3y ago> If anyone has success integrating Prolog in modern software please share, I'm really curious. https://terminusdb.com/ https://terminusdb.com/ is almost entirely written in prolog. + a little bit of Rust and JS.