Answers.Body: <p>Prolog <em>promises</em> "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.</p>
  
  <p>Too much confusion, even for a non-beginner.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-17T23:58:12.197Z
Answers.Text: 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.
Answers.UserDisplayName: Frax
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-17T20:19:16.527Z
Answers.LastActivityDate: 2018-05-18T12:16:10.163Z
Answers.LastEditDate: 2018-05-18T12:16:10.163Z
Answers.UserDisplayName: vonbrand
Answers.Body: <p>I do and am currently teaching a high school student Prolog but not as a first language.</p>
  
  <blockquote>
    <p>Is it OK to use logic programming(like Prolog) as students' first language?</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>The reasons are</p>
  
  <ol>
  <li><p>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.</p>
  
  <p>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 (<a href="https://rads.stackoverflow.com/amzn/click/0321417461" rel="nofollow noreferrer">Amazon</a>) (<a href="http://www.worldcat.org/oclc/770866932" rel="nofollow noreferrer">WorldCat</a>). 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. </p>
  
  <p>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 <a href="https://www.metalevel.at/prolog" rel="nofollow noreferrer">The Power of Prolog</a> by Markus Triska</p>
  
  <p>While there are several places to get online help with Prolog, the one I use is StackOverflow with the <a href="https://stackoverflow.com/questions/tagged/prolog">Prolog</a> tag.</p></li>
  <li><p>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 (<a href="https://en.wikipedia.org/wiki/Unification_(computer_science)#Syntactic_unification_of_first-order_terms" rel="nofollow noreferrer">think bi-directional pattern matching</a>). 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.</p></li>
  <li><p>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.  </p>
  
  <p>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.</p></li>
  <li><p>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 <a href="https://github.com/Z3Prover/z3" rel="nofollow noreferrer">Z3</a> can be used instead for other languages.</p></li>
  <li><p>There may be other languages that can do what Prolog can do and do more. e.g. <a href="http://www.mercurylang.org/" rel="nofollow noreferrer">Mercury</a> or expand on Prolog as a proof assistant, e.g. <a href="https://coq.inria.fr/" rel="nofollow noreferrer">Coq</a></p></li>
  <li><p>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.</p></li>
  <li><p>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. </p></li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-08T21:06:55.540Z
Answers.Text: 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](http://www.htdp.org/) 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).
Answers.UserDisplayName: Charles Duffy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-09T12:37:11.890Z
Answers.Text: 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.
Answers.UserDisplayName: Peter Taylor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-09T13:44:54.527Z
Answers.Text: 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.
Answers.UserDisplayName: Ben I.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-09T15:14:31.413Z
Answers.Text: 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.
Answers.UserDisplayName: Charles Duffy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-09T15:17:38.080Z
Answers.Text: (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).
Answers.UserDisplayName: Charles Duffy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-09T15:21:22.080Z
Answers.Text: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/77249/discussion-between-charles-duffy-and-guy-coder).
Answers.UserDisplayName: Charles Duffy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-15T17:07:13.383Z
Answers.Text: If common use in industry were the core requirement for choosing a language to teach, we'd all still be programming COBOL and FORTRAN. The BASIC and PASCAL languages both started as teaching languages. They were widely used in industry for a time, and their descendant offspring Visual Basic keeps their legacy alive.
Answers.UserDisplayName: pojo-guy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-08T14:17:00.930Z
Answers.LastActivityDate: 2018-05-09T15:02:46.217Z
Answers.LastEditDate: 2018-05-09T15:02:46.217Z
Answers.UserDisplayName: Guy Coder
Answers.Body: <p>As <a href="https://cseducators.stackexchange.com/a/4729/1293">Guy Coder</a> 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 <em>how to build things.</em> <a href="https://en.wikipedia.org/wiki/Logic_programming" rel="noreferrer">Logic Programming</a> 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. </p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>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 <em>the what</em> rather than <em>the how</em>. In CS, we <strong>build things</strong> and so the focus is mainly on the how, especially at the start. </p>
  
  <p>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. </p>
  
  <p>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 <a href="https://en.wikipedia.org/wiki/Skynet_(Terminator)" rel="noreferrer">Skynet</a> doesn't come along first. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-30T01:08:43.580Z
Answers.Text: 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.
Answers.UserDisplayName: vonbrand
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-08T15:30:00.197Z
Answers.LastActivityDate: 2018-05-08T15:30:00.197Z
Answers.UserDisplayName: Buffy
Body: <p>Some use FP, some use OOP, some use procedure. </p>
  
  <p>It seems few universities start with logic programming, why?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-08T23:44:32.073Z
Comments.Text: 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.
Comments.UserDisplayName: pojo-guy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-09T05:38:13.173Z
Comments.Text: 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.
Comments.UserDisplayName: Kinaeh
Tags: <language-choice>
Title: Is it ok to use logic programming(like Prolog) as students' first language?
ThreadText: # Is it ok to use logic programming(like Prolog) as students' first language?
  
  (Asked by: username_0 on 2018-05-08)
  
  Some use FP, some use OOP, some use procedure.
  
  It seems few universities start with logic programming, why?
  
  **Tags:** language-choice
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_2**: 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.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_5 on 2018-05-08. Score: 15 | Accepted answer
  
  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](https://rads.stackoverflow.com/amzn/click/0321417461)) ([WorldCat](http://www.worldcat.org/oclc/770866932)). 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](https://www.metalevel.at/prolog) by Markus Triska
  
     While there are several places to get online help with Prolog, the one I use is StackOverflow with the [Prolog](https://stackoverflow.com/questions/tagged/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](https://en.wikipedia.org/wiki/Unification_(computer_science)#Syntactic_unification_of_first-order_terms)). 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](https://github.com/Z3Prover/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](http://www.mercurylang.org/) or expand on Prolog as a proof assistant, e.g. [Coq](https://coq.inria.fr/)
  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.
  
  > **Comments:**
  > **username_6**: 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](http://www.htdp.org/) 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).  
  > **username_7**: As a third party, it seems to me that username_6' 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.  
  > **username_8**: 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 @username_7 did.  
  > **username_6**: username_7 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.  
  > **username_6**: (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).  
  > **username_6**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/77249/discussion-between-username_6-username_6-and-username_5).  
  > **username_1**: If common use in industry were the core requirement for choosing a language to teach, we'd all still be programming COBOL and FORTRAN. The BASIC and PASCAL languages both started as teaching languages. They were widely used in industry for a time, and their descendant offspring Visual Basic keeps their legacy alive.  
  
  ---
  
  ### Answer by username_9 on 2018-05-08. Score: 9
  
  As [username_5](https://cseducators.stackexchange.com/a/4729/1293) 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](https://en.wikipedia.org/wiki/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](https://en.wikipedia.org/wiki/Skynet_(Terminator)) doesn't come along first.
  
  > **Comments:**
  > **username_3**: 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.  
  
  ---
  
  ### Answer by username_3 on 2018-05-17. Score: 3
  
  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.
  
  > **Comments:**
  > **username_4**: 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.  
  
  ---
  
  