🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4246

Re: Re: loops in prolog

#4246
From: #Stefan Bachert
Date: Mon, 05 Mar 1990 11:16
57 lines
2505 bytes
>> 	once_true(X):-call(X),!.	% predicate X is determinated
>> 	once_true(_).			% and always true

>I am *sick* of seeing people reinvent once/1 and giving it new names.
>It is traditionally a library predicate in Edinburgh Prologs.

once/1 is defined as

	once(X):-call(X),!.

and that for it can be FAILED.

>I've even *more* sick of people thinking it is a good idea.
>If X is supposed to be determinate, then *WRITE* X so that it *IS*
>determinate, don't patch it up in the calls.  When I see a program
>using once/1 I am willing to bet that it is badly written in other
>ways too.

In your last comment you talked about clearness of programs.
Using once or once_true will clarify the situation. Your proposal
will do it not! 

>> Your proposal will still eat up the stack.

>Not so.  Stack space is reclaimed on failure or on determinate exit,
>and tail calls don't take stack space in a modern Prolog.  Recall
>that the recursive form of the loop was
>	p :- action_1, p_loop.
>	p_loop :- ( condition -> action_2, action_1, p_loop ; action_3 ).
>If action_1 and action_2 are determinate, then this loop does *NOT*
>"eat up the stack" in a decent Prolog system.

If so your proprosal will run just on your special implemention of prolog.
It takes a lot knowledge to detect that p_loop is determinated. And it is not
obvious to the programmers.
My proposal will run in any prolog.

>(Note that in the 'repeat'
>form of the loop action_1 had better not fail, otherwise there's a nasty
>liitle infinite loop there.  The recursive version has no such problem.)

That's why I introduce once_true/1

>> PS: I don't like ->/2 because of its dubious definition.

>*WHAT* dubious definition?  The if->then;else construct was defined
>quite clearly in the DEC-10 Prolog manual, as far back as 1979:

>	( P -> Q ; R ) is like call(( P, !, Q ; R )) except that
>	it is transparent to cuts in Q and R
>	( P -> Q ) is like call(( P, !, Q )) except that
>	it is transparent to cuts in Q

Exactly that. Try to implement -> /2 in Prolog. (? exceptions)
->/2 is more a precompiler directive than a prolog predicate.

Stefan
Technical Details
Message-ID: <470005@hpbbi4.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!decwrl!ucbvax!hplabs!hp-ses!hpbbn!hpbbi4!stefan
References: <1032@fs1.ee.ubc.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!decwrl!ucbvax!hplabs!hp-ses!hpbbn!hpbbi4!stefan
From: stefan@hpbbi4.HP.COM (#Stefan Bachert)
Newsgroups: comp.lang.prolog
Subject: Re: Re: loops in prolog
Message-ID: <470005@hpbbi4.HP.COM>
Date: 5 Mar 90 11:16:21 GMT
References: <1032@fs1.ee.ubc.ca>
Organization: Hewlett-Packard GmbH
Lines: 57