Live data from Hacker News

Ask HN: What's Prolog like in 2024?

news.ycombinator.com

211–220 of 289 posts

Re: Ask HN: What's Prolog like in 2024?

#211
post #165

Earlier quoted context omitted.

To be even more precise, Prolog programs only ever run forward because the order of evaluation is fixed as top-down, left-to-right. These notions of "forward" and "backward" are very unhelpful and should be given up. Beginners find the order of evaluation hard enough to understand, let's not confuse them even more. Also, the notion is woefully incomplete. Let's say we consider this "forward": ?- list_length([a, b, c]…

What's going on in the second example? Did Prolog generate a list term stuffed with gensym variables, which satisifies the list_length being 3?

It generated a list stuffed with distinct logical variables. Any list of length 3 is unifiable with this list. Or in other words, this is the unique (up to variable renaming) most general list of length 3.

Whether this is a "yes" to your question depends on what your mental model of "gensym variables" is. They are variables, not symbols (which Prolog would call atoms).

Re: Ask HN: What's Prolog like in 2024?

#212

Earlier quoted context omitted.

I have two short examples in one of my books that I am currently re-writing. Here is a link directly to the Python+ Prolog interop examples https://leanpub.com/pythonai/read#use-predicate-logic-by-cal...

Thanks for the link. I have played with PySwip ( https://github.com/yuce/pyswip ), and the MQI looks like a more maintainable approach to integrating SWI-Prolog with Python ( https://github.com/SWI-Prolog/packages-mqi ). The biggest source of friction I noticed when playing with PySwip was that because Prolog code was represented as strings, you avoided generating it on the fly. It would be nice to have an embedded D…

Don’t go looking at pony’s source code for inspiration. The api is neat but when your app starts to get complicated it begins to not work well.

Re: Ask HN: What's Prolog like in 2024?

#213

Earlier quoted context omitted.

Thanks for the link. I have played with PySwip ( https://github.com/yuce/pyswip ), and the MQI looks like a more maintainable approach to integrating SWI-Prolog with Python ( https://github.com/SWI-Prolog/packages-mqi ). The biggest source of friction I noticed when playing with PySwip was that because Prolog code was represented as strings, you avoided generating it on the fly. It would be nice to have an embedded D…

I noticed the same friction while trying to integrate Answer Set Programming solvers into Python projects. The people who built the dominant ASP solver actually provide nice solutions though. Possible inspiration for Prolog tooling: Clorm (Clingo ORM) [1] makes it easy to create facts after you define simple predicate Python classes. Here's an example project of mine which uses it to set up a scheduling problem (Pyth…

This is cool! I am glad to see that other people have thought in the same direction—and actually wrote the code. I have another reason to learn ASP.

Re: Ask HN: What's Prolog like in 2024?

#214

Prolog, 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 un…

You write Prolog code for a living? Where? Do you happen to have a story to share? I'm very curious.

Yes :) we make software that helps sell complex products (If your product has a million options and takes up a whole factory floor you can’t just have a series of dropdowns)

Re: Ask HN: What's Prolog like in 2024?

#215

Earlier quoted context omitted.

I'd advise to not use Prolog as general-purpose programming language, but as an embedded DSL or as a service for the part it's really suited for (if your app involves exploration and search over a large combinatorical space in the first place, such as in discrete optimization in industry, logistics, and finance). You really don't need yet another package manager and pointless premature modularization for modelling yo…

To me this makes Prolog sound like a tool to reach for similar to SQL. Specialized language for asking specific kinds of search or query over your data.

Indeed Prolog programs are also called databases sometimes. Some things Prolog can do over SQL:

- infinite data defined by recursive predicates

- flexible data structures (think JSON but better, called complex terms) and a way to query them (called unification algorithm)

- execution strategy fine-tuned for reasoning (called resolution algorithm). You can do this with SQL but you’d have to formalize things using set operations and it’d be very very slow.

On the other hand, SQL can query plain data very very fast.

Re: Ask HN: What's Prolog like in 2024?

#216

Earlier quoted context omitted.

I'd advise to not use Prolog as general-purpose programming language, but as an embedded DSL or as a service for the part it's really suited for (if your app involves exploration and search over a large combinatorical space in the first place, such as in discrete optimization in industry, logistics, and finance). You really don't need yet another package manager and pointless premature modularization for modelling yo…

At this point, why not use one of the many other CP solver packages out there and the layers on top like OR-tools?

Which one is as developed, as universal and as capable as Prolog with CLP and/or DCG?

Serious question, I'd like to have something that's easy to integrate with Node.js.

Re: Ask HN: What's Prolog like in 2024?

#217

Earlier quoted context omitted.

I still don't get how Java records can be used for anything like a DTO. Since you're a Clojure dev you may remember the pattern Rich Hickey described as "place oriented programming" :) Nearly every endpoint will have more than 2-3 fields and you really don't want a Java record with more than that many fields for the same reason you don't want a Java method with that many fields e.g. doIt(Long, String,String,Long,Stri…

> I still don't get how Java records can be used for anything like a DTO In Clojure, we often deserialize a result set from a database to a vector of maps. These maps have different keys depending on what exactly your query was selecting. In Java, one often "projects" results to some DTO. This is one scenario where records offer identical functionality while avoiding boilerplate. Regarding "place-oriented programming…

I'm also using it for projections. But to be honest we have a fairly large Quarkus app and only use projections in a few places. For immutable classes with a large number of fields where instances have to be created manually I usually use the builder pattern. But the analogy to typescript interfaces is interesting.

Re: Ask HN: What's Prolog like in 2024?

#218

Earlier quoted context omitted.

I'd advise to not use Prolog as general-purpose programming language, but as an embedded DSL or as a service for the part it's really suited for (if your app involves exploration and search over a large combinatorical space in the first place, such as in discrete optimization in industry, logistics, and finance). You really don't need yet another package manager and pointless premature modularization for modelling yo…

At this point, why not use one of the many other CP solver packages out there and the layers on top like OR-tools?

The domain-specific Prolog code bases you're going to create still can become large and represent a significant development effort. Prolog being an ISO standard with many conformant (or at least mostly conformant) implementations available and relatively strong mindshare and ecosystem compared to extremely niche "CP solver packages and OR-tools" (which one exactly?) significantly reduces project risks such as not being able to find experts, the system not meeting functional or performance requirements, or becoming obsolete down the road. The same cannot be said for some mythical "CP solver packages and OR-tools"; you've nowhere to go if your "CP solver packages and OR-tools" project fails. Optimization and scheduling/planning projects, by their nature, are somewhat experimental and need exploration. It would thus be very difficult to pick "CP solver packages and OR-tools" upfront.

Re: Ask HN: What's Prolog like in 2024?

#219
If 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.

Re: Ask HN: What's Prolog like in 2024?

#220
post #14

Prolog 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://youtube.com/@thepowerofprolog

[deleted]
Post reply on HN