Re: if then else
- From: bart demoen <bmd@xxxxxxxxxxxxxx>
- Date: Thu, 21 Feb 2008 18:33:57 +0100
On Thu, 21 Feb 2008 11:00:40 -0500, Neng-Fa Zhou wrote:
Even if it is remedied, I won't advocate if-then-else. Don't you agree that
rule-based is more readable than if-then-else?
It might depend on the number of arguments of the predicate.
One reason for my liking if-then-else is that one usually writes
them with one clause head with all different variables with names that
mean something.
I would prefer giving a mode
declaration as in the following:
:-mode mmode(+,+,-).
mmode([],L1,L2) :- !, L2 = L1.
mmode(L1,[],L2) :- !, L2 = L1.
mmode([X|R],[Y|S],[X,Y|T]) :- mmode(R,S,T).
You just made me so happy :-)
Of course, mode declarations are preferable - the problem is that checking
them is quite a bit harder than checking type declarations.
BTW, one can't remove the cut from the first clause, but shouldn't the cut
be removed from the second clause ?
The above question is supposed to show that there is more to modes than
meets the eye :-)
or converting it into matching clauses:
mmatch([],L1,L2) :- true : L2 = L1.
mmatch(L1,[],L2) :- true : L2 = L1.
mmatch([X|R],[Y|S],L3):-true : L3=[X,Y|T], mmatch(R,S,T).
I prefer modes. One good thing about matching clauses: you must write
steadfast code, otherwise it won't work.
Here are the times I got on my Windows machine:
I will try those on my Mac later this evening - now it's time to prepare dinner !
Cheers
Bart Demoen
.
- Follow-Ups:
- Re: if then else
- From: Neng-Fa Zhou
- Re: if then else
- References:
- if then else
- From: bart demoen
- Re: if then else
- From: Neng-Fa Zhou
- Re: if then else
- From: bart demoen
- Re: if then else
- From: Neng-Fa Zhou
- if then else
- Prev by Date: Re: if then else
- Next by Date: Re: Prolog Control Flow
- Previous by thread: Re: if then else
- Next by thread: Re: if then else
- Index(es):
Relevant Pages
|
|