Lambda the Ultimate

inactiveTopic A Prolog Introduction for Hackers
started 2/28/2004; 10:35:43 AM - last post 3/1/2004; 1:00:47 PM
andrew cooke - A Prolog Introduction for Hackers  blueArrow
2/28/2004; 10:35:43 AM (reads: 8381, responses: 5)
A Prolog Introduction for Hackers
Prolog is decidedly a European language; [...] Despite this, do not be afraid; Prolog is a very useful tool in its own right. Good luck.

Popular intro on a mainstream technology/discussion site.
Posted to teaching/learning by andrew cooke on 2/28/04; 10:36:39 AM

Frank Atanassow - Re: A Prolog Introduction for Hackers  blueArrow
2/29/2004; 10:09:56 AM (reads: 294, responses: 0)
Prolog is decidedly a European language; not only was it originally invented by a Frenchman, the majority of Prolog implementations are developed and used in Europe

And algorithms were discovered by a Muslim, Al-Khawarizmi, whose progeny now litter one of the states in that godforsaken Axis of Evil. In this post 9/11 world, we can no longer afford to acknowledge terrorists, so I suggest we henceforth prefer the word `liberty-rithms'.

bryan rasmussen - Re: A Prolog Introduction for Hackers  blueArrow
2/29/2004; 11:24:39 AM (reads: 297, responses: 0)
liberty rhythms? Rock&Roll is dead.

Peter Van Roy - Re: A Prolog Introduction for Hackers  blueArrow
3/1/2004; 12:49:22 PM (reads: 217, responses: 1)
From the article:

Calculating the factorial:

% fac(N,R) : R is the factorial of N.

fac(0,1).

fac(N,R) :- P is N-1, fac(P,Q), R is N*Q.

Using this pattern is simple: typing the query fac(5,R)., for example, gives the result: R = 120. When playing around a little, though, many deficiencies start becoming apparent, including unwanted infinite loops and the fact that fac(N,120) doesn't give the expected result. The reason for this is the fact that Prolog is very ill-suited for numerical computation; arithmetic in Prolog is a hack, and doesn't integrate well into the Prolog search engine too well.

Wrong and misleading! The "unwanted infinite loop" is a consequence of the second clause being incorrect: it does not state a logical truth. Adding 'N>0' to it would make it correct and would end all infinite loops. The "arithmetic is a hack" phrase is both incorrect and misleading. In fact, the only issue is that basic arithmetic in Prolog is directional: 'Var is Expr' evaluates the term Expr as an expression and unifies the result with Var. Nondirectional arithmetic is possible; it is done routinely by constraint programming systems.

The author tries valiantly (and does say some right things), but be careful: he gets some of the simple ideas wrong!

Peter Van Roy - Re: A Prolog Introduction for Hackers  blueArrow
3/1/2004; 1:00:47 PM (reads: 209, responses: 0)
More from the article:

Wait one second, Prolog is a logic-based language!

No, it is not. Prolog has several system patterns that were (very) loosely inspired by formal logic; these were designed to ease the use of Prolog for those people that are already familiar with formal logic. However, if you persist with your delusion that Prolog is a language for "handling logic predicates", you will get bitten sooner or later! (And probably sooner than later.)

More misleading and incorrect information. The right answer is that Prolog has a subset that is a pure logic language, and that good Prolog programs are careful to exploit this.

Section 9.7 in CTM gives a better explanation of the soul of Prolog than this article.

Ehud Lamm - Re: A Prolog Introduction for Hackers  blueArrow
3/1/2004; 1:23:47 PM (reads: 210, responses: 0)
that basic arithmetic in Prolog is directional... Nondirectional arithmetic is possible; it is done routinely by constraint programming systems.

This is one of the frsutrating things about (classic) prolog.