🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4228

Re: loops in prolog

#4228
From: Richard O'keefe
Date: Wed, 28 Feb 1990 09:36
32 lines
1453 bytes
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.
Technical Details
Message-ID: <2921@goanna.oz.au>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok
References: <1032@fs1.ee.ubc.ca> <470002@hpbbi4.HP.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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