Paralife
Paralife

Reputation: 6236

Common lisp, undefined intersection function behaviour?

According to CLHS entry for the INTERSECTION function (http://www.lispworks.com/documentation/HyperSpec/Body/f_isec_.htm):

For every pair that satifies the test, exactly one of the two elements of the pair will be put in the result.

My problem is that i need to know which one of the two elements of the pair will be put in the result, which matters when, for example :key #'car is used to extract the arguments to test against, since the cdr might be different. I would like to have a guarantee that either always the first or always the second element will be put in the result. Am I missing something or is this just unspecified behaviour, so I shouldnt use it for my case?

Upvotes: 6

Views: 313

Answers (1)

Fred Foo
Fred Foo

Reputation: 363587

intersection simply doesn't make the guarantee you want; it implements set-theoretic intersection with a lot of extras, but just not that extra. You'll have to roll your own.

Upvotes: 6

Related Questions