17

My company has a project running in Prolog and I want to clarify few things about how to go about learning it. I know Prolog is different. It should not be learnt just like any other language.

Having said that, and considering the fact that I did not lay my hands on any Prolog book yet, Is there any book or online resource, where I can learn Prolog the way how we learn C/C++? What I mean is , just to be operational in C/C++, you just need to know the structure of the program, like main { } , loops, conditions, branches, and few functions that you can use to start writing basic programs in C/C++.

Just this way can I learn Prolog and is there any book that just gives me an idea how to Program in Prolog? (basics, loops, how to implement conditions, program structure, what's predicate? how to use it? how to define it? and so on...).

halfer
  • 19,824
  • 17
  • 99
  • 186
JPro
  • 6,292
  • 13
  • 57
  • 83
  • I don't mean to spoil the party, but consider what Peter Norvig wrote about [Teach Yourself Programming in Ten Years](http://norvig.com/21-days.html) on his blog. – repeat Jan 28 '16 at 00:15

3 Answers3

23

If you're after a single book, I can highly recommend "The Art of Prolog":

Coming to Prolog from something like C/C++ isn't just a matter of learning a programming language. It's a wholly different way of thinking about programming.

Prolog is about asking the computer questions (or 'queries' if you like). Computation is almost a side-effect of the computer trying to answer your question. There is no meaningful equivalent to loops or conditionals because a prolog programmer wouldn't think in those terms.

A good Prolog program looks like a description of the problem that you're trying to solve decomposed into recursive cases and subproblems rather than lists of instructions organised into functions or classes.

The best way to learn Prolog is to set aside all your previous programming experience. Actually thinking about C and C++ will make Prolog harder to learn and use. Try to adopt a beginner's mind and maybe an approach more like an algebraist than a programmer.

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Dafydd Rees
  • 6,941
  • 3
  • 39
  • 48
  • 2
    +1 In general I think this answer is helpful, but I wouldn't go overboard and say completely forget all your other programming experience. It is possible to write code that behaves in an imperative manner in Prolog (eg with the help of cuts) and sometimes it's expedient to do this. Also, you should always be thinking about the complexity of the algorithms that you are creating. You still need to think about what the machine will actually be doing when you ask it a question. A prior understanding of algorithms and complexity is going to be useful here. – nedned Jan 03 '10 at 08:55
8

As a supplement to the Prolog tutorials and textbooks mentioned in the other answers, I would suggest having a quick look at this short document:

Prolog for Imperative Programmers

I think it's part of what you're looking for. It won't teach you Prolog, but it will help bridge the gap to understanding Prolog. It describes the basics of Prolog using terminology that experienced non-Prolog programmers would understand. For example, it shows you control structures in Prolog, i.e. sequence, selection and repetition. It does assume that you've already started learning Prolog, though.

It's good if you want to understand something new in terms of something you already know. However, armed with this knowledge/understanding, there is a risk that you could end up writing C code in Prolog syntax. Good luck!

Nelson
  • 1,022
  • 5
  • 9
7

What's wrong with Learn Prolog Now, which is usually the top recommendation each time this kind of question gets asked?

It may not give you exactly the terminology you want -- I believe it doesn't even mention "predicate" (uses "Facts, Rules, and Queries" instead) or "loops" (it just shows how to use recursion instead) -- but getting the terminology right once the concepts are clear should be simple, fast, and easy, and "Learn Prolog Now" does seem to do a good job about making the concepts clear.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395