3 ms·
Are there any particularly excellent examples of prolog implemented as a library you could point us to?
by bwestergard 9mo ago
Are there any particularly excellent examples of prolog implemented as a library you could point us to?
- chii 9mo agonot OP, but for clojure : https://github.com/bobschrag/clolog https://github.com/bobschrag/clolog
- khaled_ismaeel 9mo agoNot exactly prolog, but logic programming implemented as a library/DSL: https://minikanren.org/ https://minikanren.org/
- jayd16 9mo agoIf it's a DSL then it's "writing a new language" and you're just calling from a native API, no?
- naasking 9mo agoEmbedded DSLs are libraries. They are the epitome of the advice to write a library. It just so happens that the library abstractions could map to a language if you wanted to add parsing and all of the other machinery.
- EricRiese 9mo agoClojure's core.logic is based on minikanren, so that fits the bill.
- exe34 9mo agonot prolog but logical programming in python: https://sites.google.com/site/pydatalog/ https://sites.google.com/site/pydatalog/
- deleted 9mo ago[deleted]
- ramses0 9mo agoMy time to shine! https://news.ycombinator.com/item?id=45902088 https://news.ycombinator.com/item?id=45902088 References were Racket with the Racklog library¹. There's also Datalog² and MiniKanren, picat, flix. There were tons of good comments there which you should check out, but PySwip seemed like "the right thing" when I was looking at it: https://github.com/yuce/pyswip/ https://github.com/yuce/pyswip/ ...documentation is extremely sparse, and assumes you already know prolog, but here's a slightly better example of kindof the utility of it: https://eugeneasahara.com/2024/08/12/playing-with-prolog-prologs-role-in-the-llm-era-part-3/#:~:text=the%20first%20place.-,Starting%20Point,-In%20this%20role https://eugeneasahara.com/2024/08/12/playing-with-prolog-pro... ...ie: # ya don't really care how this works prolog.consult("diabetes_risk.pl") # ...but you can query into it! query = "at_risk_for_diabetes(Person)" results = list(prolog.query(query)) ...the point being there's sometimes some sort of "logic calculation that you wish could be some sort of regex", and I always think of prolog as "regexes for logic". One time I wished I could use prolog was trying to figure the best match between video file, format, bitrate, browser, playback plugin... or if you've seen https://pcpartpicker.com/list/ https://pcpartpicker.com/list/ ...being able to "just" encode all the constraints, and say something like: valid_config = consult("rules.pl") + consult("parts_data.pl") + python.choice_so_far(...) rules.pl: only_one_cpu, total_watts < power_supply(watts) parts_data.pl: cpu_xyz: ...; power_supply_abc: watts=1000 choices: cpu(xyz), power_supply(abc), ... ...this is a terribly syntactically incorrect example, but you could imagine that this would be horrific code to maintain in python (and sqrt(horrific) to maintain in prolog), but _that's_ the benefit! You can take a well-defined portion and kindof sqrt(...) the maintenance cost, at the expense of 1.5x'ing the number of programming languages you need to expect people to know.
- dunham 9mo agoAs an example of a use case, "Gerrit Code Review"[1] is written in Java and uses prolog for the submit rules.[2] I haven't looked into the implementation. But taking a brief glance now, it looks interesting. They appear to be translating Prolog to Java via a WAM representation[3]. The compiler (prolog-cafe) is written in prolog and bootstrapped into Java via swi-prolog. I don't know why compilation is necessary, it seems like an interpreter would be fast enough for that use case, but I'd love to take it apart and see how it works. [1]: https://www.gerritcodereview.com/ https://www.gerritcodereview.com/ [2]: https://gerrit-documentation.storage.googleapis.com/Documentation/2.9/prolog-cookbook.html https://gerrit-documentation.storage.googleapis.com/Document... [3]: https://gerrit.googlesource.com/prolog-cafe/+/refs/heads/master/src/compiler/pl2am.pl https://gerrit.googlesource.com/prolog-cafe/+/refs/heads/mas...