logo       

Re: VERY URGENT, CUT AND FINDALL/3: msg#01610

Subject: Re: VERY URGENT, CUT AND FINDALL/3

> As you've quite clearly and comprehensively pointed out, the use of
> findall/3 is a most inefficient means of finding the "symmetric difference
> of two sets". However, the posing of this problem does provide a simple
> introduction to the use of findall/3. Having successfully solved such a
> problem the way is then paved for more complex applications, as well as a
> deeper understanding, of findall/3 [and its brethren].
> 
> To my mind this is another example of 'bad code' having its uses [at least
> in a teaching context].

[I have seen Richard's reply to this]

For me, it is not a matter of bad code versus good code, it is a
matter of specification version algorithm. It is clear that if one
were "programming" symmetric difference of two sets, one wouldn't use
findall/3. If one were "specifying" it, the use of findall/3 is
very appropriate (setof/3 might even do better).

Logic is a good specification language and a bad algorithm
implementation language.

Prolog lends itself to both specification and implementation,
sometimes in one go.
That's why the solutions in the book at
http://www.cs.kuleuven.be/~dtai/ppcbook/ often use a specification
style of programming, because when under time pressure, (Prolog
executable) specification leads quickly to a correct program -
inefficient at times, but often just by constant factors.

The fact that findall/3 is perceived as inefficient is more of a
historic (Prolog) implementation accident than a necessity anyway.

Cheers

Bart Demoen

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm




<Prev in Thread] Current Thread [Next in Thread>