From: JP Massar
Subject: Question about :test semantics in set operations
Date: 
Message-ID: <3e7f7248.10718780@netnews.attbi.com>
Consider

(defun f (x y)
	(set-exclusive-or x y :test #'(lambda (x y) (print (list x y))
(eql x y))))
F
(f '(a b) '(d e))


Does ANSI Common Lisp specify what is to be printed out here?

That is, is it guarenteed that the test function is called exactly
once on the cross-product of the two lists, or may the test function
be called more than once on some or all of the pairs, or may the test
function not be called at all on some of the pairs?

(Answer might be in the HS somewhere, but I can't seem to find it.  I
don't consider 

"For all possible ordered pairs consisting of one element from list-1
and one element from list-2, the :test or :test-not function is used
to determine whether they satisfy the test."

an unambiguous answer to the question although I admit it could be
interpreted as insisting on the 'exactly once' interpretation, which
would be terribly inefficient for some set operations.)

From: Kent M Pitman
Subject: Re: Question about :test semantics in set operations
Date: 
Message-ID: <sfwn0jk4c5j.fsf@shell01.TheWorld.com>
······@alum.mit.edu (JP Massar) writes:

> ... is it guarenteed that the test function is called exactly
> once on the cross-product of the two lists, or may the test function
> be called more than once on some or all of the pairs, or may the test
> function not be called at all on some of the pairs?

I don't think there's a restriction, but as you say, it's hard to be sure.

Wouldn't this preclude various optimizations?  At mininum, you'd want to
say "at most".  But I don't see any reason to restrict it at all.  
Market pressures keep implementations from getting silly here, and mostly
it's hard to see someone getting this really super-wrong, but I'm trying
to imagine any well-styled code you could write that would care...
From: Paul F. Dietz
Subject: Re: Question about :test semantics in set operations
Date: 
Message-ID: <fR-cnRyYQZEsMeKjXTWcpw@dls.net>
Kent M Pitman wrote:

> Wouldn't this preclude various optimizations?  At mininum, you'd want to
> say "at most".  But I don't see any reason to restrict it at all.  
> Market pressures keep implementations from getting silly here, and mostly
> it's hard to see someone getting this really super-wrong, but I'm trying
> to imagine any well-styled code you could write that would care...

Many implementations seem to have mixed up the *order* of the arguments
to the test function, though.

	Paul
From: Tim Bradshaw
Subject: Re: Question about :test semantics in set operations
Date: 
Message-ID: <ey31y0wuvch.fsf@cley.com>
* JP Massar wrote:
> Does ANSI Common Lisp specify what is to be printed out here?

I don't think so.

> That is, is it guarenteed that the test function is called exactly
> once on the cross-product of the two lists, or may the test function
> be called more than once on some or all of the pairs, or may the test
> function not be called at all on some of the pairs?

I think there's no guarentee about anything.  For instance an
implementation could notice something about the test function and do
some clever trick which didn't involve calling it at all.

--tim