Live data from Hacker News

Prolog Coding Horror

metalevel.at

41–50 of 88 posts

Re: Prolog Coding Horror

#41
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.

Gerrit had an embedded prolog engine, and I recall branch protection rules / PR workflows were configured using progolog.

Re: Prolog Coding Horror

#42

I haven’t used Prolog, but I have a little experience with Erlang and a lot with Elixir. As I understand it, the early versions of Erlang were inspired by Prolog. For those with familiarity with both Prolog and Erlang, can you comment on the similarities and differences between? Is/was Erlang basically Prolog with OTP bolted on?

Super simple example

    % Prolog
    next_light(green, yellow).
    next_light(yellow, red).
    next_light(red, green).

    % Erlang
    next_light(green)  -> yellow;
    next_light(yellow) -> red;
    next_light(red)    -> green.
Notable differences:

- `;` in Erlang indicates multi clause function

- In Prolog next_light is database, in Erlang it's just a function

Question: What's the light before green?

    % Erlang
    % Returns actual value
    prev_light_search() -> 
    [State || State 
So syntax IS similar though the thing is that Prolog is more like binding and quering database and Erlang is executing function.

In a nutshell Erlang is more like: "when I have X, then I can calculate Y" and Prolog like "If I want Y, what's the X".

Re: Prolog Coding Horror

#43
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 for logic what inverse kinematics is for robotics.

Where in imperative programming languages you supply arguments to a function and get a result in Prolog you can give the result of a function call and get all argument sets that lead to that result.

But you are right that in production systems you would seldom see Prolog, for reason that you can easily LLM.

Re: Prolog Coding Horror

#44
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.

My last use case: Testing Scenario Generator.

I have a application that has actions and actions can happen pretty much in any order. By default all scenarios should be an error except for ones that are in the boundary of logical steps, e.g.

   login  -> ...[!logout]... -> logout
   login  -> ...[!logout]... -> dashboard
   upload -> ...             -> view_file
Of course you can immediately see problem with this scope - what happens when non-logged-in user tries to upload or user logouts after upload etc.

So I have ~50 actions, ~30 constraints which generate >200 scenarios which then are transformed into test suite.

Yet in short: Prolog is useful everywhere it's simple to express a rule but not that easy to implement it.

Re: Prolog Coding Horror

#45
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.

Not used. Quote about prolog: The elegant solution is not efficient. The efficient solution is not elegant.

I feel like an inefficient solution is inelegant by definition.

Re: Prolog Coding Horror

#46
post #27

now we may have a more powerful "Prolog" - LLM Agent, though not precise and correct somtimes.

It reminds me of an old joke:

Radio Yerevan: A listener asks: "Is it true that in Moscow, on Red Square, they are giving away cars?"

Our answer: "Yes, it is true. Except it isn't in Moscow, but in Leningrad. And it isn't on Red Square, but on Palace Square. And they aren't cars, but bicycles. And they aren't giving them away, they are stealing them."

Re: Prolog Coding Horror

#47
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 Maemo (the mobile OS from Nokia) had the profile manager (day mode/night mode etc) written in Prolog. To me it seems like it's a very appropriate application for it.

Re: Prolog Coding Horror

#49
post #45

Earlier quoted context omitted.

Not used. Quote about prolog: The elegant solution is not efficient. The efficient solution is not elegant.

I feel like an inefficient solution is inelegant by definition.

Richard O'Keefe in The Craft of Prolog: "Elegance is not optional".

Re: Prolog Coding Horror

#50
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.

TerminusDb

[0] https://en.wikipedia.org/wiki/TerminusDB

[1] https://github.com/terminusdb/terminusdb

Post reply on HN