[Top][All Lists]

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

Re: if

From: Ron Stodden
Subject: Re: if
Date: Wed, 31 Jan 2001 23:42:18 +1100

Calum Grant wrote:
> A simpler variant of this problem is
>         insert_set(H, L, L) :- member(H, L), !.  % A "hack" according to FH
>         insert_set(H, L, [H|L]).
> which takes an item H and inserts it into a list L without duplicates, like
> a simple set.  The second clause should only be applied if the first one
> fails.  Therefore the ! is necessary.  This can be rewritten as
>         insert_set(H, S0, S) :-
>         (
>                 member(H, S0) -> S0=S;  % A "hack" according to RS
>                 S = [H|S0]
>         ).
> The difference is purely cosmetic, and I don't think it's worth arguing
> about.  It's a bit like saying that "|" is better than ";".

Argue?   Yes.   I would argue that the first is ultimately simpler,
more 'elegant', immediately lucid, and I suspect generates less code
and on that basis should run faster.  (Note the "should" <g>).


Ron. [AU]

reply via email to

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