Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!tektronix!decvax!mandrill!arun
From: arun@mandrill (Arun Lakhotia)
Newsgroups: comp.lang.prolog
Subject: Tail Recursive loops <-> Failure Driven loops
Message-ID: <2467@mandrill.CWRU.Edu>
Date: 6 May 88 04:58:36 GMT
Sender: arun@mandrill.CWRU.Edu
Reply-To: arun@mandrill (Arun Lakhotia)
Organization: CWRU Dept of Computer Engineering and Science
Lines: 42

Some weeks (may be months) back, an article by Micha Meier had some
comments on repeat-fail loop vs tail-recursive loops, including:

>	There is no reasonable argument to force people to use
>	tail-recursive loops instead of repeat-fail loops;

which led Saumya Debray to write:

> There may or may not be arguments to *force* anyone to avoid failure-
> driven loops, but there are a couple of reasons one might want to avoid
> them anyway:

Meier's argument in favor of failure-driven loop was related to
efficiency issues. Debray's argument against it was that it is
trickier to write "correct" failure driven loop, supporting his
argument by an incorrect translation of a tail-recursive loop to a
failure-driven one.

Their arguments hint that, forgetting efficiency, one type of loop can
be transformed to other. I believe this can only be true for a
restricted class of programs, or is there a general "transformation"
scheme from one to another (without any restriction).  Could someone
pass me pointers to literature that deal with transformations in
either directions, and/or give the characteristics of programs that
can be transformed in either directions.

In particular I am curious about, Debray's comment:
>(2)  It's not too hard to automate the transformation from tail-recursive
>     loops to failure-driven loops (with a little guidance from the user,
>     in the form of simple compiler directives), especially for the usual
>     case of deterministic loops.

Intuitively speaking: At the termination of a failure-driven loop,
variables bindings performed during the execution of a failure-driven
loop, are eventually lost (due to failures).  However, those done in a
tail-recursive loop remain, if the loop terminates successfully -
deterministic or not.  It would be nice, thus, to know how
tail-recursive loops can be transformed to failure-driven loops, 
*** without using any side-effects ***.


Arun