OKeefe.R.A.@EDXA@sri-unix.UUCP (10/12/83)
From: Richard HPS (on ERCC DEC-10) <OKeefe.R.A.@EDXA>
% File : SETOF.PL
% Author : R.A.O'Keefe
% Updated: 11 October 1983
% Purpose: Define set_of/3 and bag_of/3
/* This file defines two predicates which act like setof/3 and
bagof/3. I have seen the code for these routines in DEC-10
and in C-Prolog, but I no longer recall it, and this code was
independently derived in 1982 by me and me alone.
Most of the complication comes from trying to cope with free
variables in the Filter; these definitions actually enumerate
all the solutions, then group together those with the same
bindings for the free variables. There must be a better way of
doing this. I do not claim any virtue for this code other than
the virtue of working. In fact there is a subtle bug: if
setof/bagof occurs as a data structure in the Generator it will
be mistaken for a call, and free variables treated wrongly.
Given the current nature of Prolog, there is no way of telling
a call from a data structure, and since nested calls are FAR more
likely than use as a data structure, we just put up with the
latter being wrong. The same applies to negation.
Would anyone incorporating this in their Prolog system please
credit both me and David Warren; he thought up the definitions,
and my implementation may owe more to subconscious memory of his
than I like to think. At least this ought to put a stop to
fraudulent claims to having bagof, by replacing them with
genuine claims.
*/
[ setof.pl is available through FTP as {SU-SCORE}PS:<PROLOG>Setof.Pl
If you do not have ARPAnet access, I have a LIMITED number of
hardcopy listings that could be mailed. -ed ]