[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if

From: Fergus Henderson
Subject: Re: if
Date: Tue, 30 Jan 2001 21:32:36 +1100

On 30-Jan-2001, Ron Stodden <address@hidden> wrote:
> Fergus Henderson wrote:
> > 
> > In logic languages which don't have if-then-else, but which do have
> > cut, e.g. Lambda Prolog, you can simulate if-then-else using cut.
> > But this is a hack; it's nicer if the language supports if-then-else
> > directly.
> No, it is the if-then-else that is the hack.  It isn't necessary,

How would you write something simple like the following code, then?

                % Insert a particular value in a bag.
        :- pred bag__insert(bag(T), T, bag(T)).
        :- mode bag__insert(in, in, out) is det.

        bag__insert(Bag0, Item, Bag) :-
                        map__search(Bag0, Item, Count0)
                        Count is Count0 + 1
                        Count = 1
                map__set(Bag0, Item, Count, Bag).

> The if-then-else construct carries with it an implied and nasty bias
> that the true path is what matters, and the false path is by its
> optionality less important, and so gets less thought and frequently
> no testing at all. 

?  I don't know where you're getting that from.  I certainly don't see
any such bias in the if-then-else construct.  I don't think there is
anything about the if-then-else construct that encourages programmers
to not test the else path.  All I can really say about that is that
the best language design in the world won't save you from bad

You may however be pleased to know that in Mercury the "else" part of
an if-then-else is not optional.

Fergus Henderson <address@hidden>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]