I'm responding to the call on comp.lang.lisp to test CMUCL
19b pre-release.

remove-duplicates works as expected when it is the first
occurrence that is to be removed.

* (remove-duplicates '(a b c)
                     :test (lambda (x y)
                             (format t "~&Testing ~a and ~a." x y))
                     :from-end nil)

Testing A and B.
Testing A and C.
Testing B and C.
(A B C)

but when one uses :from-end t to specify keeping the first
occurrence the arguments to the test function get flipped.

* (remove-duplicates '(a b c)
                     :test (lambda (x y)
                             (format t "~&Testing ~a and ~a." x y))
                     :from-end t)

Testing B and A.
Testing C and A.
Testing C and B.
(A B C)

I discovered this when I was reading CLtL1. On page 247
Steele writes

    You may depend on the order in which arguments are given
    to /testfn/; this permits the use of non-commutative
    test functions in a predictable manner....

I thought "That is cool!". It means that I can generate a
short list of prime numbers in `Sieve of Eratosthenes' style
with

CL-USER(4): (remove-duplicates
             '(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
             :test (lambda (prime candidate)
                     (zerop (mod candidate prime)))
             :from-end t)
=> (2 3 5 7 11 13 17 19)

but CMUCL 19b lets all the numbers through the sieve.

This problem occurs on my shiny new build of FreeBSD 5.4
It also occurs on the 18b and 18d verions of CMUCL, ie on
old versions that run on FreeBSD 4.1, but it didn't feel
right to report a bug when I was still running software from
the previous century :-)

Alan Crowe
Edinburgh
Scotland


Reply via email to