News for hackers. Stuff that matters.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by wizzwizz4 on Thursday November 07, 2024 @10:14AM (#42077339)
It doesn't scale that well because integers are their own, opaque thing in Prolog, and the is predicate is unidirectional. However, there's no inherent reason this has to be the case: you can construct your own representation of the integers from the Peano axioms, and recover bidirectionality of addition. (You'll want to be using some typed variant of Prolog with the "unary tree of units" optimisation, otherwise integers take O(n) space in memory, but it's possible in the language.) Prolog works how it does, because it's (mostly) backwards-compatible with a facts database used for symbolic AI research, where all atoms were opaque.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by lmkg on Thursday November 07, 2024 @10:41AM (#42077598)
Check out the CLP(ℤ) library by Markus Triska, who is also the author of Scryer Prolog. It defines new comparison predicates that lets you use bidirectional logical programming on standard integers with standard math operations.

https://github.com/triska/clpz

Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by dsabanin on Thursday November 07, 2024 @05:19PM (#42081735)
Markus is not the author of Scryer Prolog, Mark Thom is.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by rscho on Thursday November 07, 2024 @11:42AM (#42078265)
There are many ways to recover relational behaviour. Libs such as clp(fd) (superseded by clp(Z)), clp(BNR) and others.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by Avshalom on Thursday November 07, 2024 @12:22PM (#42078694)
BNR notably works with real numbers and non linear constraints.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by ahoka on Thursday November 07, 2024 @11:23AM (#42078048)
“you can construct your own representation of the integers from the Peano axioms”

This is how the Idris prelude defines nat, the type of natural numbers (with some magic making it actually fast). I think that’s very cool.

Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by coliveira on Thursday November 07, 2024 @01:30PM (#42079406)
Modern Prolog libraries have handled the issues of unidirectional integer predicates, so the old ways of handling numeric values is not relevant for most problems.
Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by jfmc on Friday November 08, 2024 @01:23AM (#42084644)
Many times the algorithm that you are implementing requires a precise data flow that is not reversible, so using traditional arithmetic (is/2) is better for catching errors.

On the other hand CLP(FD) is not new at all (it is very popular for constraint programming).

Re:I'm Not Mutable, I'm Partially Instantiated (Prolog) by rscho on Friday November 08, 2024 @03:16AM (#42085208)
Why would it be better for error handling? If you'll be using unidirectional flow only, then the point is moot. But using clp is arguably better IMO, allowing type and range checks while allowing relational execution.