Learning recursion in Prolog

Tag: recursion , prolog , declarative-programming Author: zhengzengya Date: 2014-04-01

I have a basic understanding of how recursion works in Prolog. I am finding it difficult to think in declarative paradigm. Could you suggest some learning resources(with solved examples) for writing recursive predicates?

This is a nice variety of problems that use recursion: ic.unicamp.br/~meidanis/courses/mc336/2009s2/prolog/problemas
Click on the Prolog tag below your question. :)

Best Answer

My answer here to the question "Prolog programming - path way to a solution" lists several [book] resources.

When I was learning Prolog, I found Leon Sterling and Ehud Shapiro's The Art of Prolog far more enlightening than other books on the subject

Art of Prolog cover

Richard O'Keefe's The Craft of Prolog looks good, too, but I can't say I've ever looked at it:

Craft of Prolog cover

comments:

Craft is pretty advanced. I got a lot of mileage out of Programming in Prolog. IMO, Prolog books tend to be great; I haven't read a real stinker yet.

Other Answer1

I think that Prolog shows its best in 'basic' Natural Language Processing. Indeed, that was its first and foremost battlefield, long time ago.

('basic' because NLP has much complexity that's not related at all to the choice of any implementation...)

But NLP show two fields where recursion it's important for implementation (it's inherent in the problem):

  • grammars are inherently recursive - recursion in the 'data'
  • parsing: need a language to analyze languages - metaprogramming as a basic tool.

Parsing can be seen as the simplest area where both problems need to be solved.

As a consequence, the book I do prefer it's Prolog and Natural-Language Analysis, by Pereira-Shieber.