News for hackers. Stuff that matters.
Re:The Power of Prolog by triska on Wednesday April 08, 2020 @03:37PM (#22816238)
Thank you very much for your interest, I greatly appreciate it!

I hope you are all doing reasonably well. Please take care!

This book was most recently discussed here in May 2018:

https://news.ycombinator.com/item?id=17121028

Since then, I have added a new chapter, Logical Foundations of Prolog:

https://www.metalevel.at/prolog/logic

Also, I have made several other additions and improvements. You can see most of the changes since the last discussion in a public git repository:

https://github.com/triska/the-power-of-prolog/compare/8a94ed...

Currently, I am working on several videos that will eventually form the core of the book. Here are a few previews:

https://www.metalevel.at/prolog/videos/logic

https://www.metalevel.at/prolog/videos/timetabling

https://www.metalevel.at/prolog/videos/sparrows_on_eagles

These videos are all work in progress, and they may be replaced by better versions at any time. Hence, if possible, please use the links above to refer to them: They will always point to the latest versions.

Alternatively, please use the following overview page that shows all videos:

https://www.metalevel.at/prolog/videos/

Also, I have published a comprehensive journal paper about my CLP(B) system, i.e., a SAT solver with some nice algebraic properties, seamlessly integrated into Prolog as a specialized form of unification:

https://www.metalevel.at/boolean.pdf

For Prolog application programmers and system implementors, the paper's appendices may be especially interesting. They formalize a few important concepts that are also a major theme in the book.

As of October 2019, the CLP(B) system is also available in Mark Thom's Scryer Prolog. Scryer is a Rust-based Prolog implementation that is freely available, conforms to the Prolog ISO standard, represents strings efficiently as lists of characters, and includes important features for implementing Prolog-based constraint solvers:

https://github.com/mthom/scryer-prolog

As of a few days ago, Scryer Prolog also ships with my implementation of CLP(ℤ), Constraint Logic Programming over integers. This is a very useful declarative paradigm for solving combinatorial tasks, in some ways superior to SAT solving because it allows more convenient modeling, easier experimentation with different formulations, and reasoning at a higher conceptual level. The chapter on declarative integer arithmetic contains more information, and further pointers:

https://www.metalevel.at/prolog/clpz

For illustration, here is an example page where you can solve timetabling instances with this approach:

https://www.metalevel.at/prolog/timetabling/

I welcome all comments and suggestions about the book, these videos, and Prolog in general. Also, I would like to take this opportunity to thank all readers for your thoughtful comments and endorsements. Your feedback and encouragement are making this work especially worthwhile.

Enjoy!

Re:The Power of Prolog by mthom on Wednesday April 08, 2020 @08:40PM (#22818725)
Some coming features of Scryer Prolog for those interested:

- Automatic detection and compilation of partial strings

- Streams, including sockets

- Garbage collection in anticipation of very fast yet logically pure I/O

- Improvements to the instruction dispatch loop (many opportunities for enhancement there, probably a good place to start for a beginning contributor)

In the past few months, we've added delimited continuations, tabling, partial strings, and Markus' CLP(B), CLP(ℤ) and format libraries. For a hobbyist project I'd say we're moving at a fairly quick pace!

Longer term, we're interested in:

- JIT compilation to native code (Cranelift seems a good candidate?)

- Low-level integration with Common Lisp environments

I'd love to have system-level contributors, although library contributions are always very welcome!

Re:The Power of Prolog by koeng on Thursday April 09, 2020 @12:12AM (#22819697)
I'm fairly new to programming in Prolog - how does Scryer Prolog compare to more common implementations like Swi Prolog?
Re:The Power of Prolog by mthom on Thursday April 09, 2020 @11:02AM (#22823187)
Scryer is not yet as fast or feature-rich as SWI. SWI has been in business for about 30 years longer, so that shouldn't surprise anyone. Also, Scryer is committed to strict conformance to the ISO Prolog standard, which SWI has disregarded for a while now.
Re:The Power of Prolog by triska on Wednesday April 08, 2020 @09:26PM (#22818990)
Thank you a lot Mark for participating in this discussion, and for all your work on Scryer Prolog during the last few years!

In the hope to attract further contributors to Scryer Prolog, especially with interest in Rust, I have now created a GitHub issue that collects a few self-contained features that could be interesting to look into for Rust programmers:

https://github.com/mthom/scryer-prolog/issues/319

I hope that's OK, and I invite everyone who is interested in these topics to contribute to this very innovative new Prolog system! Already in this early stage, it provides several important features that no other system currently has. Thank you again!

Re:The Power of Prolog by mthom on Wednesday April 08, 2020 @10:33PM (#22819285)
Yes, thank you for the Power of Prolog! Scryer was and is being written under its influence.
Re:The Power of Prolog by felixyz on Thursday April 09, 2020 @02:38AM (#22820341)
> very fast yet logically pure I/O

Sounds interesting, do you have a link or something else to share regarding your conception of logically pure I/O?

Re:The Power of Prolog by Avshalom on Thursday April 09, 2020 @08:38AM (#22821935)
Re:The Power of Prolog by falsissime on Thursday April 09, 2020 @12:59PM (#22824627)
From the interface (mostly yes, that, is apart from the impure extensions added later, and that chars are used and not codes) it is the same. But from the implementation behind it´s different. In particular from the space requirements. A text of n characters requires 3 * 8 * n bytes in SWI, but n + 2 * 8 bytes in Scryer. So there is a factor 24 in space requirements (on 64bit).

Also, there is now ample room for input that SWI once almost offered.

Re:The Power of Prolog by falsissime on Thursday April 09, 2020 @05:54AM (#22821093)
Re:The Power of Prolog by 7thaccount on Wednesday April 08, 2020 @10:06PM (#22819161)
How usable is Scryer Prolog? Is it a single executable, or does it have a complex install?
Re:The Power of Prolog by mthom on Wednesday April 08, 2020 @10:31PM (#22819278)
Decently, I'd say. It is a single executable that you have to build yourself. If you want a recent build, there are a few extra steps, but they're nbd. There are build instructions in the README ("Installing Scryer Prolog") at:

http://github.com/mthom/scryer-prolog

Re:The Power of Prolog by wwweston on Wednesday April 08, 2020 @04:39PM (#22816826)
> Scryer is a Rust-based Prolog implementation that is freely available

!

As well as an exclamation I suppose that's the cut on my "write a prolog to learn rust" predicate, backtracking to finding out more about this, especially since I just came across a little puzzle for which integer constraint programming is perfect this week.

Re:The Power of Prolog by aargh_aargh on Wednesday April 08, 2020 @07:42PM (#22818379)
While I'm not interested in learning Prolog at this time, I skimmed through both your book and site and find it really easy to understand. The writing is simple (I bet it takes a lot of effort to produce simple to undestand writing) and what seems to be lower-than-usual text/information density of the page both helps with reading and makes the text beautiful - a joy to read. Thank you, I hope to revisit this bookmark once I have free time again.
Re:The Power of Prolog by triska on Wednesday April 08, 2020 @07:55PM (#22818465)
Thank you a lot, it is really encouraging to hear this!

One of my goals with this specific form of presentation is to counteract "skimming" by making it unrewarding: When readers are tempted to "skim" a chapter, they usually find out that they were already almost at the end of the chapter, so reading the entire chapter and thinking about the content becomes the preferred strategy.

One potential drawback of this approach is that readers who do not want to think about the content, or do not read the material with the required focus may come to the conclusion that it is too terse.

In my opinion, what matters here, maybe more than in other texts, is the strategy of reading that is required to best absorb the material. I am doing my best to ensure that it is all there. Yet, the full potential is only realized with active cooperation from the reader. I think it would be possible to convey some of the points also with lengthier explanations, though at the substantial cost of sacrificing peak impact potential. I am very glad to hear that this approach is working well for you, thank you a lot for your feedback!

Re:The Power of Prolog by carapace on Wednesday April 08, 2020 @04:19PM (#22816630)
I want to say thank you, for your book and for all the work you're doing promoting and improving Prolog.
Re:The Power of Prolog by triska on Wednesday April 08, 2020 @04:30PM (#22816749)
You are very welcome!

I greatly enjoy all your postings about your Prolog-based interpreter for Joy:

https://osdn.net/projects/joypy/scm/hg/Joypy/blobs/tip/thun/...

I impulsively upvote this every time I see it. Thank you for sharing such an interesting project!

Re:The Power of Prolog by carapace on Wednesday April 08, 2020 @08:30PM (#22818656)
You're very kind. It's unfinished, and I doubt whether it will ever be useful for anything (other than just being kinda neat in and of itself.) I need to deal with compiling loops/recursion/fixpoints. But thanks! I appreciate it.

Your advice to use CLP(FD) for the semantics of integer math operations was fantastic!

Re:The Power of Prolog by mthom on Thursday April 09, 2020 @11:02AM (#22823200)
You don't mind if I port Thun to Scryer Prolog, do you? With full credit to you, of course. I'd like to include it as an example.
Re:The Power of Prolog by carapace on Thursday April 09, 2020 @03:00PM (#22825968)
Not at all, that would be awesome. It's GPL'd, have at it. (^_^)

I typically use SWI Prolog but I hope the code is mostly portable. The parser uses a couple of DCGs from the "basics" lib but I think those are also portable or at least simple to re-implement.

The tricky bit might be the semantics of math (and comparison) ops. I've tried two other sets of semantics, one that attempts to perform math operations (and catch the errors if e.g. an arg is a logic var rather than an int) as you go, and another that just builds expression trees (evaluation is delayed) like so:

    func(+, [int(A), int(B)|S], [int(A + B)|S]).
Just to point out, in SWI Prolog the ints are "BigNums" while in GNU Prolog they're machine words (so modular arithmetic, mod 2^32). You could use Rationals or make up some other semantics. This all gets into Categorical paradigm programming. http://conal.net/papers/compiling-to-categories/ The same (point-free) expression can be used to develop concrete programs over various categories: Hardware circuits, partial evaluation, differentiation, dataflow graphs, and so on.
Re:The Power of Prolog by felixyz on Thursday April 09, 2020 @02:42AM (#22820356)
Hadn't seen this before. How nice that you called it Thun! Warms my heart.
Re:The Power of Prolog by carapace on Thursday April 09, 2020 @03:14PM (#22826128)
Cheers! Manfred von Thun seems like he was a pretty great guy. I wanted to honor him.
Re:The Power of Prolog by kitd on Thursday April 09, 2020 @04:25AM (#22820730)
Great article and thank you very much!

As someone with only fleeting knowledge of Prolog, this was by far the best introduction I've come across.

Re:The Power of Prolog by bhk on Wednesday April 08, 2020 @08:08PM (#22818535)
It would help if you could point users to a Prolog implementation that is compatible with your examples. I couldn't find any in the book, but going up to your home page I found a couple of references to SWI-Prolog, and installed that, but the first two examples in the book resulted in syntax errors regarding the "#>" and "#=" operators.
Re:The Power of Prolog by Avshalom on Wednesday April 08, 2020 @08:35PM (#22818691)
I can't remember exactly where it is mentioned (it is somewhere) but in SWI-Prolog you need to put

  :- use_module(library(clpfd)).
at the top of your file (or just use_module(library(clpfd)). at the console)
Re:The Power of Prolog by falsissime on Thursday April 09, 2020 @05:40PM (#22827494)
Or

    :- use_module(library(clpz)).
for its successor which runs with SICStus and Scryer.