Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!swrinde!ihnp4.ucsd.edu!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!conway
From: conway@munta.cs.mu.OZ.AU (Thomas Charles CONWAY)
Subject: Re: If-Then-Else (was: Re: Otherwise?)
Message-ID: <9505709.26556@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
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> <D4I8DM.Mwq@info.bris.ac.uk> <9505704.23884@mulga.cs.mu.OZ.AU>
Date: Sat, 25 Feb 1995 22:18:34 GMT
Lines: 27

fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:

	[deletia]
>
>Mercury solves this problem, because Mercury's compile-time mode checking
>ensures that the run-time check isn't necessary.
>

The example which Fergus and I both know well is in the Mercury compiler
itself which we bootstrapped from NU-Prolog (and later SICStus Prolg,
but that is another story). To start with we used NU-Prolog's
(if then else) construct for safety, and later once the mode analyser
was working we replaced them with ( -> ; ) since the compiler's
checking would ensure that our programs were not unsound. When we
did this (and replaced (not G) with (\+ G) for the same reasons),
performance went up dramatically. We were frequently passing in
the compiler's main data structure which was ground, and megabytes
in size.

Of course, one of the problems with using ( -> ; ) is that it puts
a hard cut after executing the condition, so that if the condition
were to produce multiple solutions these would be pruned. The Mercury
( -> ; ) only prunes the else goal when the condition succeeds, so
the ( -> ; ) construct as a whole can output multiple bindings that
were produced in the condition.

Thomas
