Some use FP, some use OOP, some use procedure.

It seems few universities start with logic programming, why?

  • 2
    $\begingroup$ I spent a fruitless year trying to figure out prolog in 1985. When I finally got something working (towers of hanoi) , I redid it in pascal in half the lines and about 15 minutes, and I understood what I had written. I have never looked at prolog again. $\endgroup$
    – pojo-guy
    May 8, 2018 at 23:44
  • $\begingroup$ Why would you use it as 'programming language' (instead of a tool to teach aspects of logic and logic formulas, ... )? When I started my studies, we had two different subjects, one was programming and another was logic. In the ladder we solved (simple but complex for us) logic problems with logic programming. $\endgroup$
    – Kinaeh
    May 9, 2018 at 5:38

3 Answers 3


I do and am currently teaching a high school student Prolog but not as a first language.

Is it OK to use logic programming(like Prolog) as students' first language?

While you could do it I would not advise doing it, let a student do it if they asked or be on a committee that would advocate for it.

The reasons are

  1. Prolog is so much unlike other programming languages that there are very few other resources that a student could use as references for learning it and they would be very dependent on the teacher for learning. Many of the students I teach talk to others to round out their understanding of what I teach and while I would like to think that they clearly understand everything I say and get it correct the first time that just does not happen and so the students look to other means to augment their learning. With Prolog it is not only hard to find other good resources, but also students (and especially high school students) are hesitant to seek out help of knowledgeable peers.

    With regards to books, there is only one book that I would use as an introductory teaching book and that is "Prolog Programming for Artificial Intelligence (4th Edition)" by Ivan Bratko (Amazon) (WorldCat). Java or Python have several tens of books and several are suitable for an introduction. Then for advanced books, Prolog only has a handful and of that only a few are of value. To learn the true art of programming in Prolog is something that only one or two books really are of mention.

    There are a few sites for learning Prolog, but many only skim the surface and of the web sites that teach Prolog most I would not recommend for a self-learner as they can leave you with more questions than answers. For more advanced topics the only web site of value I note is The Power of Prolog by Markus Triska

    While there are several places to get online help with Prolog, the one I use is StackOverflow with the Prolog tag.

  2. The key concepts to learning Prolog are not intuitive. Object-Oriented has state, and functional is stateless with pattern matching (one way). Prolog is stateless with unification (think bi-directional pattern matching). Thinking in recursion has to be natural, processing lists must be second nature, constraint problems are common, difference list, use of syntactic sugar with DCGs, the operator definitions such as xfx, xfy, xf are different than most languages, reification, SLD, logical purity, program slicing, predicates vs. functions, MGU, and other concepts not seen in other common languages.

  3. One first has to learn unification and get it correct before moving forward. The problem here is that sometimes the class has to move forward before a student understands unification and then the rest of the course is endless confusion to the student. Also unification is symbolic and getting students to understand that abstract concept is sometimes very hard. On one test I gave to drive the point home, part of the unification test was with English letters, part with Greek letters and part with symbols like a snowman. After unification comes backtracking or backward chaining which gives Prolog non-deterministic programming. List processing is typically next and that is another topic that can lose many students. When teaching list processing I teach induction with a base case and induction step(s). Cut is another topic that loses many students and can make or break many programming solutions. The point here is that you may have to proceed slower at first and then pick up the pace or risk losing many of the students and there are many key concepts that rely on previous key concepts where only a complete understanding will suffice.

    Note: I normally provide links to the keywords but here have purposefully left them out so as to give others a taste of what it means to try and understand Prolog by trying to put these ideas together by themselves. I think Prolog is great and use it weekly but I know when and where to use it appropriately.

  4. The best concepts of Prolog are typically incorporated into other languages as libraries or calls to external systems. In particular constraint solving is very useful but systems like Z3 can be used instead for other languages.

  5. There may be other languages that can do what Prolog can do and do more. e.g. Mercury or expand on Prolog as a proof assistant, e.g. Coq

  6. Very few companies seek out employees who know Prolog. Universities want their graduates to get hired. Why teach a student something that won't get them hired? Also since many companies don't use Prolog, if you know Prolog and try and advocate for it in a company, you are probably going to be on the losing side. Not that I find any of this agreeable, but that is reality.

  7. With regards to AI Prolog gives closed world answers and while that is beneficial for some AI problems, IMHO is an Achilles heal for others. As an example, when it comes to classifying pictures I would not use Prolog but a deep neural network.

  • $\begingroup$ I agree wholeheartedly with your conclusion, but am not sure I agree with (6). There are compelling reasons to use teaching languages -- there aren't many jobs available writing Racket, but HTDP is rightly lauded as a curriculum that teaches concepts applicable across a wide range of languages, and its use of Scheme is highly defensible: Becoming fluent in languages with a wide range of concepts, even when not actively used outside academia, makes it far easier to learn mainstream languages that adopt those concepts in the future (as is happening today with lambdas &c). $\endgroup$ May 8, 2018 at 21:06
  • 1
    $\begingroup$ As a third party, it seems to me that Charles' point addresses "Why teach a student something that won't get them hired?". I would also note that I interpreted "Not that I find that agreeable but that is reality" as referring specifically to the previous sentence rather than to the whole paragraph. $\endgroup$ May 9, 2018 at 12:37
  • $\begingroup$ I modified a word to make it (hopefully) match your intentions more clearly. (Feel free to roll back if I erred) I think we were all reading that sentence the way @PeterTaylor did. $\endgroup$
    – Ben I.
    May 9, 2018 at 13:44
  • 1
    $\begingroup$ Peter interpreted my objection correctly -- the argument seemed to apply not just to Prolog, but to any programming language not currently in widespread use outside academia. Features from academia make it into commercial languages over time -- see the introduction of lambdas to widespread commercial use in Java 8, CSP in Golang, etc; people who learned academic languages with those features would be better prepared to use those today, even if those languages do not themselves have commercial value. $\endgroup$ May 9, 2018 at 15:14
  • $\begingroup$ (See also the "Blub Paradox" from Paul Graham's "Beating the Averages", discussing the importance of teaching high-level concepts. Particularly, the argument that programming languages are not merely technologies, but habits of mind as well, and nothing changes slower is something that informs my position re: importance of exposure to a broad range of paradigms early). $\endgroup$ May 9, 2018 at 15:17

As Guy Coder says, Prolog doesn't help a lot with employment. But it goes a bit farther than that. As educators we normally teach students in CS how to build things. Logic Programming languages such as Prolog have other strengths, but building systems isn't their main goal. It therefore doesn't well support the courses that follow in most of the curriculum.

Logic Programming can be extremely important in some fields, such as (duh) Logic and also in AI, but not, generally speaking, in building information systems.

Actually, Logic Programming isn't the only useful tool that is seldom used as a first language. A CS curriculum isn't likely to treat SQL as a first programming language either, as useful (and powerful) as it is.

The main thing about these languages is that they focus on the answers themselves, not the algorithms used to find the answers. They are about the what rather than the how. In CS, we build things and so the focus is mainly on the how, especially at the start.

Later on, such descriptive or declarative language can be extremely useful and there are courses that go into how they work internally, but implementing those algorithms isn't something the typical programmer often does.

In the future, this may change, but I think we are many years away from having systems so powerful that we can just, in general, describe what we want and have the system figure out how to achieve it. It is a long term goal, of course. Just so long as Skynet doesn't come along first.

  • $\begingroup$ The problem is people naturally act (and think) procedurally (and object orientation is a natural extension), non-procedural (functional, logical, string matching, ...) languages are against all we've learnt about problem solving since we were toddlers. Recursion is a another case in point. $\endgroup$
    – vonbrand
    Aug 30, 2021 at 1:08

Prolog promises "programming in logic", but you end up worrying about the order of your predicates, and have to be acutely aware of the order in which they are recursively (procedurally!) tried by your interpreter.

Too much confusion, even for a non-beginner.

  • 1
    $\begingroup$ This. I didn't have any real experience with Prolog (i.e. used it only during programming in logic courses), but the main thing I remember was the constant struggle to keep the painfully imperative execution model under control. Actually, in my mind Prolog is simply an imperative language with a back-tracking based syntax designed to look like programming in logic, and with extremely obscured semantics for pointers/references. $\endgroup$
    – Frax
    May 17, 2018 at 23:58

Your Answer

