Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uunet!in1.uu.net!newsflash.concordia.ca!CC.UMontreal.CA!IRO.UMontreal.CA!tarau
From: tarau@IRO.UMontreal.CA (Paul Tarau)
Subject: Re: Readability (was Re: Indexing (was Re: Help!! ...))
Message-ID: <D74w50.KDx@IRO.UMontreal.CA>
Sender: news@IRO.UMontreal.CA
Organization: Universite de Moncton, Canada
References: <3m34ll$304@gaudi.ac.upc.es> <3mfo2q$jc@goanna.cs.rmit.edu.au> <9510618.27288@mulga.cs.mu.OZ.AU>
Date: Sun, 16 Apr 1995 15:24:35 GMT
Lines: 51

In article <9510618.27288@mulga.cs.mu.OZ.AU> conway@munta.cs.mu.OZ.AU (Thomas Charles CONWAY) writes:

>p([], 0).
>p([X|Xs], Sum) :-
>	p(Xs, Sum0),
>	Sum is Sum0 + X.
>becomes
>p(H1, H2) :-
>	(
>		H1 = [],
>		H2 = 0
>	;
>		H1 = [X|Xs],
>		H2 = Sum,
>		p(Xs, Sum0),
>		Sum is Sum0 + X
>	).
>).
>
>We then do indexing on all disjunctions. This means that where
>Prolog programmers will often introduce a small auxiliary
>predicates to get better indexing, Mercury programmers can mostly
>use an explicit disjunction. This removes the need for the
>overhead of a predicate call, and often results in better
>readability of code.
>

I agree with the usefulness of better indexing and your right as a
compiler writer to transform the code internally to whatever suits you,
but do you really think that the second version is more readable?

Explicit equalities are recessive compared with selection by
unification (or even pattern matching as in Haskell, ML or Miranda). 
Just count the number of symbols or variable names or total size
of the (visible) code or whatever other complexity measure!

I remember myself that after excessive exposure to C explicit
disjunction looked readable to me... 
Exposure to Haskell usually cures this, with the added benefit
of enjoying inferred types. Of course, I also remember the 
not so enjoyable (but arguably healthy) Pascal or TurboProlog
habit of declaring them :-) 

More generally, I think that the Mercury experience is valuable for
(and should be `sold' on) the overall efficiency of the implementation 
(as it is/was the case with PDC/Turbo Prolog) and less obviously
for the language features/programming style it advocates.


Paul Tarau

