Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!pipex!warwick!bsmail!lapu!bowers
From: bowers@lapu.cs.bris.ac.uk (Antony Bowers)
Subject: If-Then-Else (was: Re: Otherwise?)
Message-ID: <D4I8DM.Mwq@info.bris.ac.uk>
Lines: 48
Sender: bowers@lapu (A. Bowers)
Nntp-Posting-Host: lapu.acrc.bris.ac.uk
Organization: University of Bristol, Dept of Computer Science
References: <D3x65E.JED@uceng.uc.edu> <3i1888$q7c@goanna.cs.rmit.edu.au> <9505502.26941@mulga.cs.mu.OZ.AU> <3ijuvd$fqi@goanna.cs.rmit.edu.au> <3ikadr$a95@news.irisa.fr>
Date: Fri, 24 Feb 1995 12:36:58 GMT

In article <3ikadr$a95@news.irisa.fr>, ridoux@calypso.irisa.fr (Olivier Ridoux) writes:
|> Still, I am not happy with the standard Prolog meaning for (C->A).  Seeing
|> no logic in (C->A;B) I would like to read it as a conditional statement as 
|> in a procedural language (if C then A else B).  In these languages, 
|> (if C then A) usually means (if C then A else skip).  It seems to me that 
|> 'skip' is simply much more close to 'true' than to 'false'.  So (C->A) should
|> denote (C->A;true).

While it may be difficult to see the logic in Prolog's (C->A;B), there 
is no difficulty in giving a logical meaning to conditionals of the form 
(if C then A else B). The meaning is (C & A) \/ (~C & B). This idea was 
introduced by Lee Naish in NU-Prolog. There is no need to think of 
conditionals purely procedurally.

Goedel has this form of conditional, and it is very successful in that 
it almost completely eliminates the need for explicit pruning, while 
remaining entirely declarative. There is a more powerful version with 
existential quantifiers available.

One problem with (A->B) in Prolog is that declaratively it is just 
conjunction, and it seems rather pointless to use the arrow just to 
conceal a one-solution operator. In Goedel one would write ({A} & B) to 
achieve the same effect, where {A} means "find one solution for A".

In Goedel (IF C THEN A) means (C & A) \/ ~C, and this seems natural to 
me, probably by analogy with imperative languages as Olivier Ridoux 
suggests. Let me be the first to point out that this construction is 
nowhere near as useful as might be expected, and it is difficult to find 
any convincing examples. Here's an attempt:

PREDICATE MemberCheck : a * List(a).

MemberCheck(x, [y|ys]) <-
   IF x ~= y
   THEN MemberCheck(x, ys).

MemberCheck(x, xs) is declaratively the same as Member(x, xs), but 
procedurally it succeeds only once and leaves no choicepoints (on the 
Bristol Goedel implementation). Thus it can run to completion only when 
x and xs are sufficiently instantiated to be sure no solutions are 
pruned, and this is enforced by the system. 

Languages that enforce safe negation and lack an explicit cut operator 
are so much easier to understand than Prolog (and consequently much 
nicer to teach).

-- 
Antony Bowers                   Department of Computer Science
bowers@compsci.bristol.ac.uk    University of Bristol
Voice UK +(0)272 288919         Queens Building, University Walk
Fax   UK +(0)272 251154         Bristol BS8 1TR, UK

