Named constants?

Re. Kowalski. Prolog is a very leaky abstraction of logic. Understanding ‘under the hood’ seems like a necessity.

Every new language involves kicking the wheels to find out why it works the way it does.
It would be helpful to find a Wiki/cookbook - an Effective Prolog in the same vein as effective C++
that shows best practices, and more importantly, why. I gained a much quicker mastery of C++, for example, once I understood that the compiler needs to see sufficient type information to be able to know about much memory to reserve on the stack for a variable - a surprisingly large number of language quirks just fall out from this this fact, which you could argue is an ‘implementation detail’, but is one that leaves you constantly fighting the language until you know it.

Most of tutorials and books seem to good on the ‘this is how you do…’ part, but thin on the why part. Which is the only way to truly learn.

I have so many questions:

  • Best practices for clean code (naming of implementation vs internal details). In the process of
    system bring-up - readability matter to my because I want (need!) other to help in the full
    implementation, otherwise I’ll be working evenings and weekends.

  • Why is the second unit test failing? How to write unit-tests|how to hard-undo? Global state is how a Prolog do, so to avoid global state? The first thing I want to do with any new system is write unit tests to capture what I think is true (and be a reference for my staff). Prolog is a messy eater - every test can make assertions - breadcumbs that interfere with subsequent tests. (Hence my long question on modules that Jan and Paulo answered).

  • Why are outputs generally the last parameter (when they exist)? Convention, or some stack-friendly consequences?

  • Why order of declarations matters. (Which is not true for logic). I know the answer, but it is in fact an essential under-the-hood implementation detail, without which I sure I’ll be forever fighting the language.

  • Can an expression have a value other than true or false. (Seems no. Why not? Are there counter examples? Can expressions be terms that evaluated later…) Prolog seems to want expressions to be always true or false. (X==Y+1) is an expression that is true false. But what is (Y+1)? It is also an expression \+(Y, 1) that is true or false. The variable value we see in program output is the thing that makes the expression true. This didn’t really click for me until I implemented a non-deterministic predicate in datalog, in which you must provide different implementations depends on whether the parameters are grounded or not AND always provide success or fail as the result. Its also the why of why named constants are not trivial.

  • What’s the complexity cost of matching predicates. (are all, any? arguments indexed, or just the first)?

… Does such an ‘Effective Prolog’ resource exist?

1 Like