Talk:Prolog

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Former good article nomineeProlog was a good articles nominee, but did not meet the good article criteria at the time. There may be suggestions below for improving the article. Once these issues have been addressed, the article can be renominated. Editors may also seek a reassessment of the decision if they believe there was a mistake.
Article milestones
DateProcessResult
October 17, 2006Good article nomineeNot listed

Free PROLOG distribution missing[edit]

There is a free prolog implementation missing in the article : Arity Prolog for Windows, it can be downloaded from www.arity.com It uses an old text based user interface (for creating program code text files) with good debug tool, offers good speed, simple and solid operation for 32bit systems.

Portability : It's Edingburg like, not ISO. Doesn't support other operating systems but interpretation/compilation in SWI-PROLOG for example is direct, unless you use many specific Arity commands like local & global counters, the [! !] operator (works like once/1 SWI-PROLOG operator), etc. all very handy but specific.

Edgardo Garcia

See Also[edit]

I added a *See Also section* of WP links because of the significance of typed prolog variants in the evolution of Oz and Alice; the others are these as *See Also* usually covers related/alternative/other-than-this links in other WP CS articles. I didn't think to check for a reference to Peter van Roy's excellent CTM book from MIT Press which is so even-handed in its treatment of Prolog's strengths and weaknesses I will add a link to YProlog when it becomes available Prolog/V should be restored to Squeak Smalltalk 3.10

What makes Prolog special?[edit]

What makes Prolog special?

Prolog combines several quite unusual and innovative constructs:

  • a] recursion
  • b] type free or typeless variables
  • c] meta level reasoning
  • d] built in search
  • e] unification
  • f] automatic memory management
  • g] DCGs

The net result is that Prolog tends to allow the programmer to concentrate on encoding what they know about a problem and let the Prolog engine find an answer which fits. Prolog is well suited to certain types of applications which are not easy to code in conventioanl languages

What is 'lacking'?

  1. data types
  2. control (for loops)
  3. global variables/destructive assignment

Why are they missing? and can they be 'emulated'; often they are not present for good reason, but can readily be incorporated through some extra code.

Prolog programs can be seen as a collection of rules or clauses which have a Head if Body structure, and facts, i.e. they are clauses with no conditional body. The Prolog run-time system will try to solve any given query goal by establishing a chain of reasoning which is consistent with the program clauses and the facts.

Lets examine some of these constructs:

a] Recursion (also found in other langugaes such as ...) The ability for programs to invoke themselves as part of their definition. Implies that there are some type or recursive data structure such as a list or tree which can be processed by the recursive program.

b] type free or typeless variables Variables are logical and have their scope limited to the local program clause; they can become fully or partially instantiated (bound) to any type of data or structure. The programmer does not need to specify in advance what variables will be bound to for the program to compile.

c] meta level reasoning Programs can use other programs as data and varibles can become bound to orher program clauses. This means that programs can be built wihch are themselves interpreters for other languages or rule systems.

d] built in search Prolog contains a search engine which will try and find a solution based on the data and program presented.

e] unification Prolog unification provides a powerful pattern matching element which heps select which clauses to use and by mayching patially bound variables in structures, helps fill out the final answer.

f] automatic memory management The garbage collector ensures that lists, trees, data are recycled once no longer required. This frees the programmer from having to manage the compuetrs resources.

g] DCGs Definite clause grammar provide a way of expressing grammar, either for natural or formal languages, in a logic programming language. They can be seen as an alternative to BNF Backus–Naur_form Clive spenser (talk) 15:37, 21 February 2024 (UTC)[reply]

I have some reactions to what you claim makes Prolog special:
1) recursion: almost all modern languages support recursion (Fortran since Fortran90 standard). It is the exceptional Turing complete language that does not support recursion.
2) Type-free or typeless variables: (This might be called "dynamically typed"?) Lisp has this. Python as well, right? Good but not special.
3) Metalevel reasoning: other languages support this, e.g., lisp. Prolog does it in a particularly nice way, I would say, but I wouldn't call the concept "unusual or innovative". Maybe the particular expression of the concept is.
4) builtin search: I would call this nondeterminism, as a programming language concept, and I agree that this makes Prolog somewhat unusual. (But note that SNOBOL had nondeterminism before Prolog.)
5) unification: Yes! agreed. But I would attribute this to the fact that Prolog has "assign-once variables". I.e., in Prolog a variable can get only one value, and once it has a value, it cannot be changed. That (and the tree data type that Prolog supports) leads directly to the unification algorithm. So I think of unification as a consequence of variables being "assign once."
6) automatic memory management: this is certainly good, but it is not unusual or innovative. Lisp had a garbage collector in the 60's (50's?) and Java and python have it.
7) DCG's: yes.
Maybe I got carried away. Maybe my point is that I don't think this is a particularly good list under the heading of "quite unusual and innovative". Maybe more like: "good, useful, powerful, convenient, ..."
But having got this far, let me continue:, with what Prolog is "lacking":
1) Data types: I assume you mean builtin data types: arrays come to mind. This is certainly arguable, and has been argued.
2) Loops: I may be an outlier here, but I personally think that the lack of iterative constructs is an advantage. In Prolog all iteration must be done through recursion. I think it's pretty easy to explain that if you want to do a loop, just do tail recursion instead. The mapping is straightforward and programmers should be able to do that. But the difference is that with recursion, you must introduce a name for the recursive predicate, whereas with iteration there is no name. That might be an inconvenience, but it does force the programmer to come up with that name, and that is a name that will (hopefully) convey the meaning of the loop, what it does, and thus the invariant preserved by the loop. And to make the programmer think about this will, I believe, lead to more often correct programs. I'm sure mine is the minority view here, but there it is.
3) global, destructive assignment. Prolog does have this: assert/retract. I suppose it's no surprise, but I think these are disadvantages of Prolog, and makes Prolog programs worse, and harder to understand and get correct. Remember Wirth's contention (my paraphrase) that what you leave out of a language is more important than what you put in. As my advisor would say, assert/retract "fills a much-needed gap." This is something that should be left out, at least how it is in current Prolog. ButterBookie (talk) 17:11, 23 February 2024 (UTC)[reply]
I would like to use the presented gcd specification to make a general point I think we need to keep in mind when presenting Prolog solutions. The specification presented was:
gcd(A, B, C) :- divides(C, A), divides(C, B), forall((divides(D, A), divides(D, B)), D =< C).
This is a nice understandable, declarative, executable specification of a solution to the GCD problem. But it is hopelessly inefficient. It is O(n^2). But Euclid's algorithm is O(log n). So no real programmer would use this as an algorithm to solve the GCD problem. My point is that if we leave the impression that this is a good, practical solution to this problem, i.e., the way it is (and should be) done in Prolog, then we will definitely lose the "real" programmers. This might be the kind of presentation that leads to real programmers thinking Prolog is a toy language. ButterBookie (talk) 19:10, 25 February 2024 (UTC)[reply]

What makes Prolog special is that it is closer to natural language than any other computer language. This makes it far easier to represent domain knowledge in human-oriented terms, because the user does not need to think like a computer.

The proximity of Prolog to human language makes it, not only a programming language, but also a database language and knowledge representation language. No other programming language has such wider capabilities.

The main difference between Prolog and natural language is that natural language is ambiguous. Translation from natural language to Prolog forces users to express themselves unambiguously, and this is not always easy. However, learning to recognise and remove ambiguities is also useful for human-to-human communication.

It is often claimed that, as a declarative language, Prolog allows users to represent knowledge and leave the problem-solving to the Prolog implementation. This is like claiming that in human communication it is solely the reader's responsibilty for any failure to understand what a writer has written. This contradicts all advice about how to write effectively in natural language. To be a good writer, the writer needs to have a good model of the reasoning process that a reader uses to understand the writer's intended meaning. The writer should attempt to express that meaning in a form that makes the reader's processing costs as small as possible.

We can apply these considerations to the issues above. Here is a Prolog definition of greatest common divisor, which is close to a mathematician's definition and which uses neither recursion nor iteration:

gcd(A, B, C) :- divides(C, A), divides(C, B),
    forall((divides(D, A), divides(D, B)), D =< C).

— Preceding unsigned comment added by Robert Kowalski (talkcontribs) 10:05, 24 February 2024 (UTC)[reply]

Designers of Prolog[edit]

I have removed my name from the infobox as one of the designers of Prolog. Although Prolog is based on the procedural interpretation of Horn clauses and SLD resolution, it includes several, additional features, including depth-first search and homoiconicity, which were added by Alain Colmerauer. These additional features are defining features of Prolog, which contribute greatly to its practical utility.

SLD resolution is derived from SL resolution, which Donald Kuehner and I developed in Edinburgh for the unrestricted clausal form of logic. However, as far as I know, SL resolution was first implemented in Marseille by Philippe Roussel under Alain's direction, for use in question-answering. This earlier experimentation with SL resolution was also important for the subsequent design and implementation of Prolog. Robert Kowalski (talk) 10:56, 11 March 2024 (UTC)[reply]