A plan-based approach to Prolog recursion
Jan Newmarch · ACM SIGCSE Bulletin · 1993
This paper discusses the learning of Prolog recursion, and shows ho w it is made easier by adopting a plan-based approach .Many common Prolog examples are shown to be derivable from simple plans .Thes e plans form an inheritance hierarchy, and this is also discussed . Introductio nLearners of any programming language often have problems learnin g the basic techniques appropriate to that language .One of the principal problems in learning a language such as Prolog is the heavy relianc e in the language upon a single technique, recursion [2,3,61 .Thi s causes difficulties even to those who have already learnt many of th e programming techniques appropriate to a language such as Pascal , because they cannot see how to translate their knowledge of, say, ho w to sum the elements of an array into the Prolog recursiv e environment .Much work has been done in the imperative languages on how t o devise "programming plans" to give high level guidance to peopl e trying to invent programs [1,4,51 .For example, the "running total " plan which is used to sum elements of an array contains two parts :initialise running total to zer o loop through the array , changing running Dotal each time .This paper shows that a plan-based approach may be successfull y applied to Prolog recursion, so that the "running total" problem, fo r example, appears as a general plan .The "summation of lis t elements" then becomes just a specialisation of this plan where th e running total sums the elements of the list .The plan of this paper is as follows : the next few sections discus s some of the simpler plans, and how they are used to construc t programs .This is then recast into 'object oriented terms' as it i s shown how plans may be categorised into an inheritance hierarchy .This hierarchy -for lists at any rate -is discussed in more detail , and it is shown that most Prolog list problems fit quite comfortabl y into this approach .The paper then examines sorting routines, an d shows how they fit into this organisation .The paper concludes b y discussing how this plan based approach may be extended to othe r data structures such as trees.