Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!godot.cc.duq.edu!newsgate.duke.edu!news.mathworks.com!newsfeed.internetmci.com!in2.uu.net!allegra!alice!pereira-x.research.att.com!user
From: pereira@research.att.com (Fernando Pereira)
Subject: Re: Language ecology (was: Is Visual Prolog "real" Prolog?)
X-Nntp-Posting-Host: pereira-x.research.att.com
Message-ID: <pereira-1805962140010001@pereira-x.research.att.com>
Sender: usenet@research.att.com (netnews <9149-80593> 0112740)
Organization: AT&T Research
References: <317752DA.C2C@pdc.dk> <andrews.830314122@Turing.Stanford.EDU> <4m4ard$knq@goanna.cs.rmit.edu.au> <4mda7n$7mk@mod-serv.dfki.uni-sb.de> <4mn8jk$pje@mulga.cs.mu.OZ.AU> <pereira-0805962321250001@greeley.research.att.com> <4nilp3$qd5@orion.cybercom.net> <4nj74a$jta@soap.news.pipex.net>
Date: Sat, 18 May 1996 20:40:01 GMT
Lines: 74

In article <4nj74a$jta@soap.news.pipex.net>, John Fletcher
<lk04@dial.pipex.com> wrote:
> dennis@amzi.com (Dennis Merritt) wrote:
> <snip>
> >
> >person(socrates).
> >person(plato).
> >person(zeno).
> >
> >mortal(X) :- person(X).
> >
> > This is great, and anyone can see how logical it is, but when the
> > programmers manager asks for a report of all mortals, there isnt a
> > clue in the language design that this program is the way to create
> > that report:
> >
> >mortal_report :-
> >  write(Mortal Report), nl,
> >  mortal(X),
> >  write(X), nl,
> >  fail.
> >mortal_report.
> >
> 
> 
> IMHO, the directly comparable Prolog program is:
> 
> person(socrates).
> person(plato).
> person(zeno).
> 
> person_report :-
>     write(Person Report), nl,
>     forall( person(X), (write(X), nl) ).
> 
> (forall/2 is usually provided as a built-in or library predicate).
> 
> This still obscures the mapping to the machine, which I don't care about,
> but makes the intended meaning clear and explicit.
Actually, neither program makes the meaning that explicit. I would rather write:

people(People) :-
   findall(Person, person(Person), People).

people_report(Report) :-
   people(People),
   format_list(People, Report).

print_people_report :-
   people_report(Report),
   print_report(Report).

with appropriate definitions of format_list to map a list to a report
object (whatever that is) and of print_report.

The reason I go over this seemingly trivial example is that it actually
illustrates the point I was was making originally and Dennis Merritt
disagreed with. Both Dennis's original mortal_report and your
person_report are too tied to the underlying (Prolog) machine (they depend
on backtrack loops), where in fact what we want to accomplish has a
simple, mostly declarative, specification: print (the imperative part, a
verb) a report of the list of all people we know about (the declarative
part, expressed in English here by a noun phrase). In writing the program
this way, I follow both the natural language structure of the
specification and Richard O'Keefe's advice to keep imperative computation
as "high up" as possible in a program. The lesson here is that our own
experience of working close to the machine in other languages often
obscures the possibility of using higher-level languages to bring the
level of programming discourse much closer to the natural-language
specification of tasks. If this problem arises even with experienced
Prolog programmers, that supports my point that the mental environment
created by lower-level languages is a difficult one for high-level ones,
*independently* of the suitability of the languages to particular tasks in
an ideal world.
