🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4168

Re: loops in prolog

#4168
From: Richard O'keefe
Date: Fri, 09 Feb 1990 10:09
31 lines
1271 bytes
In article <1032@fs1.ee.ubc.ca>, vincel@fs0.ee.ubc.ca (vincent li) writes:

> Question: how would you code the following loop in (Edingburgh) Prolog?

> loop:
>    action_1;
>    IF condition_1 THEN action_2; goto loop END IF;
>   action_3;

The answer is dead simple.
	loop :-
		action_1,
		(   condition_1 ->
		    action_2,
		    loop
		;/* ~condition_1 */
		    action_3
		).
> The code I came up with looks something like this:

> loop :-
>    action_1,
>    (condition_1 -> action_2,loop),
>    action_3.

> This works, but the recursive call eats up memory and I get out of heap

I have some bad news for you.  It DOESN'T work.  What this says is
to do action_3 WHETHER OR NOT condition_1 succeeds, and that's NOT
what the original sketch said!  You begin to convince me that Dijkstra
was right when he omitted the one-armed-IF-bandit from his notation.
Technical Details
Message-ID: <2850@goanna.oz.au>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!munnari.oz.au!goanna!ok
References: <1032@fs1.ee.ubc.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!munnari.oz.au!goanna!ok
From: ok@goanna.oz.au (Richard O'keefe)
Newsgroups: comp.lang.prolog
Subject: Re: loops in prolog
Keywords: loops
Message-ID: <2850@goanna.oz.au>
Date: 9 Feb 90 10:09:46 GMT
References: <1032@fs1.ee.ubc.ca>
Organization: Comp Sci, RMIT, Melbourne, Australia
Lines: 31