Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!portc01.blue.aol.com!newsxfer3.itd.umich.edu!howland.erols.net!agate!nntpfeed.doc.ic.ac.uk!sunsite.doc.ic.ac.uk!lyra.csx.cam.ac.uk!warwick!bris.ac.uk!lapu!bowers
From: bowers@lapu.cs.bris.ac.uk (A. Bowers)
Subject: Re: Helpppp!! sory to be so impatient but i need serious help
X-Nntp-Posting-Host: lapu.acrc.bris.ac.uk
Message-ID: <E4Goxr.41D@fsa.bris.ac.uk>
Sender: bowers@lapu (A. Bowers)
Organization: Unviversity of Bristol, Dept of Computer Science
References: <5bbpk4$mfl@sifon.cc.mcgill.ca> <32DC1FA1.4D36@eexi.gr>  <5bhq1k$rno$1@goanna.cs.rmit.EDU.AU> <wuj680svpz8.fsf@wistaria.i-have-a-misconfigured-system-so-shoot-me> <5bvsqr$927@mulga.cs.mu.OZ.AU>
Date: Thu, 23 Jan 1997 12:49:02 GMT
Lines: 52

In article <5bvsqr$927@mulga.cs.mu.OZ.AU>, fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes:
|> Richard's solution had the desirable that if writing fails, then
|> you backtrack to thinking again, and if that fails, then you
|> backtrack into studying again.  Of course, if we can study at all,
|> then we don't want to try cheating.
|> 
|> Now the only problem with that specification is that it is difficult
|> to implement in Prolog, because you need a soft cut ---
|> the best Prolog solution I can come up with requires twice as
|> much study ;-)
|> 
|> 	assignment_work :-
|> 		( study ->
|> 			study,
|> 			think,
|> 			write
|> 		;
|> 			cheat,
|> 			fail
|> 		).
|> 

Indeed, the soft, (or shallow) cut form of if-then-else is a very 
useful language feature. Goedel programmers use it all the time.

In Goedel, one might say:

AssignmentWork <-
   IF SOME [x] Study(x) 
   THEN
      Think(x, y) &
      Write(y)
   ELSE
      Cheat &
      Fail.

The variables are added because in a declarative language there is 
no point resatisfying goals that do not bind variables (no side 
effects). Think of "x" as the output from studying, developed into 
"y" by thinking. Note "x" is not in scope in the "else" part of the
formula.

This can't be directly implemented in "ordinary" Prolog (except by 
computing the condition twice, as Fergus does), but some Prolog's 
have a form of it; SICStus has if/3. Of course, in Prolog, the 
programmer is responsible for ensuring safeness, it is not enforced.

Perhaps Fergus will tell us if Mercury has a proper if-then-else?

-- 
Antony Bowers, Department of Computer Science, University of Bristol, UK.
http://www.cs.bris.ac.uk/~bowers/
