[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-mit-scheme] membership procedures

From: Wacek Kusnierczyk
Subject: [Bug-mit-scheme] membership procedures
Date: Tue, 11 Nov 2003 11:17:29 +0100


While using the membership-testing procedures ('member' etc.
sec. 7.6 in the refman), I have noticed an inconsistency.
Namely, the procedure 'member-procedure' either produces a member
procedure that requires arguments in order reverse compared to that
of 'member' (or any of the predefined member procedures), or requires
the predicate used as its argument to treat its arguments (the
in reverse order.

It will be best explained by an example.

Suppose you have a list containing pairs of the format (symbol . count),
where the symbol is the proper element, and count is just for some
additional functionality.

(define seq
   '((a . 1) (b . 2) (c . 3)))

To find out whether a symbol is an element of the list, you can't simply
the symbol to the elements of the list. You have to compare it to cars
of the elements.
This may be achieved as follows:

(member 'a (map car seq))

Unfortunately, this approach, though discovering that 'a is on the list,
only a list of cars of the elements, not a part of the original list.
You need to use 'member-procedure' as follows:

(define car-member
   (member-procedure (lambda (test-element list-element)
                                  (equal? test-element (car

However, applying 'car-member' causes an error:

(car-member 'a seq)
> error msg

because it tries to access the car of... 'a.

The problem is that the original member-procedures accept their
arguments in the order
(element, list), while the newly produced procedure does it in the
reverse order.
This may be corrected by reversing the order of arguments to the

(define car-member
   (member-procedure (lambda (list-element test-element) ...)))

I consider this as an inconsistency. The manual does not specify the
order of arguments
of the predicate. Here the attempt to access the car of 'a caused an
error, but suppose
the elements (in the sense of the test-element, not the list-element)
are pairs themselves.
Then, the first implementation of 'car-member' would not cause an error,
though not working

(define seq
  '(((a b) . 1) ((b c) . 2) ((c d) . 3)))
((member-procedure (lambda (x y) (equal? x (car y)))) '(b c) seq)

returns '(), though it should return (((b c) . 2) ((c d) . 3)).

I hope you consider this explanation as clear. Please let me know
if you intend to correct this, or add a warning in the manual.
users may need to spend a lot of time to discover why their perfectly
correct code
does not work.

Waclaw Kusnierczyk

Dept. of Computer and Information Science
Norwegian University of Science and Technology
N-7491 Trondheim, Norway
tel +47 73591875
fax +47 73594466
email address@hidden


reply via email to

[Prev in Thread] Current Thread [Next in Thread]