Re: if then else



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
.



Relevant Pages

  • Re: Which anime characters would you NOT want to wake up in bed with?
    ... if sober" clause, not on the "oh shit I'm gonna die" clause, because I ... Same reason as above, and also because I'd ... Because my mind would COMPLETELY ... S'LITTLES: Feel the loli. ...
    (rec.arts.anime.misc)
  • Re: UPDATE using params, again, deosnt work
    ... If those values are correct and the where clause value is ... I just mention this b/c this is very weird and it's getting weirder. ... Sending an update command is standard far and there's no reason that it ... did you run the Select statement beforehand? ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Enforcing Christian values on others?
    ... termination no matter what the reason. ... That would be covered under a different clause: ... You will be given notification and you will be ...
    (uk.religion.christian)
  • Re: Grid Control ItemData event not firing
    ... > VS.NET used to play tricks by removing the Handles clause. ... >>I have a grid control on a page that I copied from another page and ... >> For some reason it seem my ItemData event never fires. ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: I need some help from native speakers of Japanese
    ... Now, there is a constraint in English Wh-question formation, to the ... clause, be it causal, concessive or otherwise, cannot be moved out of ... "Is the fact, that he went somewher, the reason, that you think so?", ...
    (sci.lang.japan)