Live data from Hacker News

Prolog Coding Horror

metalevel.at

81–88 of 88 posts

Re: Prolog Coding Horror

#81
post #3

What do people use Prolog for in the real world? I learned about it on a university course and it seems so esoteric compared to other things on the course. Like something invented just for computer scientists to enjoy.

I've just rolled out an internal SWI Prolog app that is similar to one linked to elsewhere in the thread [1]. We have a large Cloud estate with 10s of thousands of resources in it. Detecting unused or misconfigured resources manually isn't practical, and there are significant cost savings to be had by cleaning things up. The Prolog app reads in JSON resource snapshots, creates an in-memory database of facts from it a…

What's your TUI made with? I'm kind of imagining some kind of n-curses based thing here tbh, using SWI-Prolog's C interface? Nothing like that?

Re: Prolog Coding Horror

#82
post #3

What do people use Prolog for in the real world? I learned about it on a university course and it seems so esoteric compared to other things on the course. Like something invented just for computer scientists to enjoy.

Prolog is very succinct and interactive so it is quite nice for modeling and analysing problem spaces, similar to what you might do with Z3 or some other solver library.

Prolog also has exceptionally good string management through DCG:s. If you have a bunch of structured text and want to query it, Prolog allows you to do that. The syntax is very simple so you can even just sed your data into Prolog code and load that sometimes.

Supposedly SICSTUS Prolog is used in flight booking, and NASA did something with it sometime, but that's kind of obscure. If you ever need a rule engine, consider poking it with logic programming for a bit, perhaps it'll turn out both pragmatic and elegant.

Re: Prolog Coding Horror

#83
post #36

Earlier quoted context omitted.

Everything, you heard the joke about those who don't know Lisp end up reinventing it, well, the same can be said for Prolog.

You can implement Prolog in Lisp trivially: https://t3x.org/lisp64k/prolog.html The linked code runs in this: Unix, DOS and CP/M https://t3x.org/klisp/index.html It will compile for CP/M and DOS (Turbo C), Unix, Windows and whatnot. 64k Lisp: https://t3x.org/lisp64k/index.html Zenlisp it's similar but almost gives an intro CS course (pre SICP) for the cheap implementing discrete Math and tons of stuff in pure Lisp, e…

>> https://t3x.org/lisp64k/prolog.html

Like most "Prolog implemented in a LISP" examples, that's not Prolog. It's a Prolog-like LISP language that is missing the point. Implementing Prolog in Lisp is only "trivial" if you try to do something trivial and call it "implementing Prolog in LISLP", instead of actually, you know, implementing Prolog. In Lisp.

Since we're discussing an article by Markus Triska, and he's commented on the same thing, I'll let him do the honours:

https://github.com/triska/lisprolog

Some online books show how to implement simple "Prolog" engines in Lisp. These engines typically assume a representation of Prolog programs that is convenient from a Lisp perspective, and can't even parse a single proper Prolog term. Instead, they require you to manually translate Prolog programs to Lisp forms that are no longer valid Prolog syntax. With this approach, implementing a simple "Lisp" in Prolog is even easier ("Lisp in Prolog in zero lines"): Manually translate each Lisp function to a Prolog predicate with one additional argument to hold the original function's return value. Done. This is possible since a function is a special case of a relation, and functional programming is a restricted form of logic programming.

I'll just add that this idea of a "trivial" implementation of Prolog in Lisp seems to come from SICP which itself proudly shows off how to "trivially" do the job. I once sat through a couple of hours of lecturing on Logic Programming and Prolog by Gerald Sussman, on youtube, just to try and form a mental model of his mental model about Prolog. I waited, and waited, and waited in vain for the other shoe to drop, thinking "well he must be coming to the subject of Resolution theorem-proving any moment now" but he never did. Instead he presented a version of Prolog that is quite unrecognisable by any working Prolog programmer, from the syntax, right down to the semantics; a version that only seemed to loosely share ideas like backtracking and pattern matching with Prolog. One-sided pattern-matching mind, not unification, because unification is, for some reason, really scary to Lisp and functional programming folks. A "Prolog" with the syntax of Scheme and with the semantics of Lisp variables and primitives like eval and so on. And when he was finally asked "how is real Prolog different" at the end of the lecture he said "because Prolog programmers have a really efficient interpreter". Meaning, I guess, the Warren Abstract Machine. Very disappointing.

Re: Prolog Coding Horror

#84
post #3

What do people use Prolog for in the real world? I learned about it on a university course and it seems so esoteric compared to other things on the course. Like something invented just for computer scientists to enjoy.

Many years ago I used Prolog (BIM Prolog, I believe ) since it was used as an event correlation engine in Tivoli Enterprise Console (IBM). Fun to assert predicates for complex correlation logic.

Re: Prolog Coding Horror

#85

Earlier quoted context omitted.

I've just rolled out an internal SWI Prolog app that is similar to one linked to elsewhere in the thread [1]. We have a large Cloud estate with 10s of thousands of resources in it. Detecting unused or misconfigured resources manually isn't practical, and there are significant cost savings to be had by cleaning things up. The Prolog app reads in JSON resource snapshots, creates an in-memory database of facts from it a…

What's your TUI made with? I'm kind of imagining some kind of n-curses based thing here tbh, using SWI-Prolog's C interface? Nothing like that?

It's not that sophisticated ;-) There's command editing using readline, result pagination using less and I output links to the reports and the Cloud console using ANSI HTTP link escapes. Primitive but sufficient.

Re: Prolog Coding Horror

#86

Earlier quoted context omitted.

I've just rolled out an internal SWI Prolog app that is similar to one linked to elsewhere in the thread [1]. We have a large Cloud estate with 10s of thousands of resources in it. Detecting unused or misconfigured resources manually isn't practical, and there are significant cost savings to be had by cleaning things up. The Prolog app reads in JSON resource snapshots, creates an in-memory database of facts from it a…

This sounds like a very useful way to use Prolog. I would also guess that is a more efficient and direct method for performing pattern detection vs an LLM.

Yes, exactly. The issue detection step isn't particularly well-suited to a LLM, as it will tell you itself. The issues can be established deterministically by examining the Cloud resource data with a set of relatively simple rules, and Prolog is ideal for that. Where a LLM comes into the picture is analysis of the symptoms - resource relationships, ages, ownership, hypothesising root causes, generating cleanup plans, management reporting and so on. The interface between Prolog and the LLM is a JSON file containing the detected symptoms which is described to the LLM by a Skill. It all works pretty well.

Re: Prolog Coding Horror

#87
post #3

What do people use Prolog for in the real world? I learned about it on a university course and it seems so esoteric compared to other things on the course. Like something invented just for computer scientists to enjoy.

Windows NT Networking configuration, which may have been removed in the post Win2K versions - see https://web.archive.org/web/20030218034509/http://www.resear... and https://news.ycombinator.com/item?id=36821871

Re: Prolog Coding Horror

#88
post #30

Earlier quoted context omitted.

> ... forbidden knowledge must not be leaked to the public. Understanding is a personal achievement and has nothing to do with "forbidden knowledge" when the source of said knowledge is both quoted above and freely available.

I fear that the joke didn't land with you.

It didn't and I am now doing a facepalm as penance. :-D
Post reply on HN