Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.oz.au (Richard O'keefe) Newsgroups: comp.lang.prolog Subject: Re: loops in prolog Summary: BEWARE BEWARE Message-ID: <2921@goanna.oz.au> Date: 28 Feb 90 09:36:30 GMT References: <1032@fs1.ee.ubc.ca> <470002@hpbbi4.HP.COM> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 32 In article <470002@hpbbi4.HP.COM>, stefan@hpbbi4.HP.COM (#Stefan Bachert) writes: > loop:- > repeat, > action_1, > (not condition_1;action_2,fail), > action_3. BEWARE. A 'repeat" loop should always have its cut in the same clause. The cut is just as much part of the loop structure as the 'repeat'. It is *extremely* confusing for human readers if you put the cut in some other predicate (rather like putting the 'end loop' of an Ada loop in a different procedure). A tip: if you have some rather scrambled control structure it may be useful to first try to write down a regular expression that describes the possible sequences of tests and actions, and use the regular expression as the basis of your code. In this example, I am guessing that the intention is action_1 (condition_1 action_2 action_1)* ~condition_1 action_3 which naturally leads to the structure p :- action_1, p_loop. p_loop :- ( condition_1 -> action_2, action_1, p_loop ;/* ~condition_1*/ action_3 ). All done by kindness.