views:

171

answers:

3

Hi all,

May be this sort of question has been asked many times( as I see the list when I move the cursor to this messagebox), But 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...)

Can anyone please give me any suggestions in this?

+3  A: 

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
Thanks I will start with this one and I am expecting more answers.
JPro
+6  A: 

If you're after a single book, I can highly recommend "The Art of Prolog": http://books.google.com/books?id=w-XjuvpOrjMC&lpg=PP1&dq=the%20art%20of%20prolog&pg=PP1#v=onepage&q=&f=false

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.

cartoonfox
Thank you for an interesting suggestion.
JPro
+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.
humble coffee
+2  A: 

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
Thank you very much for this.
JPro