🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99378

Re: cl.el breaks 'member

#99378
From: "Mark D. Baushke"
Date: Tue, 18 Sep 1990 08:03
92 lines
4011 bytes
On 18 Sep 90 20:09:07 GMT, Mike.Williams@comp.vuw.ac.nz (Mike Williams) said:

Mike>   I was quite surprised when I loaded Jamie Zawinski's tar-mode,
Mike> and discovered that some of my carefully crafted hacks no longer
Mike> worked.  In particular, anything which used 'member started
Mike> behaving differently.  I tracked down the problem to cl.el,
Mike> which *redefines* 'member, to give basically the same
Mike> functionality as 'memq. (tar-mode.el requires cl.el).

In a vanilla GNU Emacs, there are a two places where a defun for the
function 'member is made. These are doctor.el and cl.el. It looks like
doctor.el uses EQUAL for comparison while cl.el uses the more
traditional EQL.

I would argue that the version in doctor.el should be renamed
doctor-member and occurances of it within the doctor.el package
changed accordingly.

;;from doctor.el
(defun member (x y)
  "Like memq, but uses  equal  for comparison"
  (while (and y (not (equal x (car y))))
    (setq y (cdr y)))
  y)
;; from cl.el
(defun member (item list)
  "Look for ITEM in LIST; return first link in LIST whose car is `eql' to ITEM."
  (let ((ptr list)
        (done nil)
        (result '()))
    (while (not (or done (endp ptr)))
      (cond ((eql item (car ptr))
             (setq done t)
             (setq result ptr)))
      (setq ptr (cdr ptr)))
    result))

According to my favorite LISP text book (LISP 2nd ed. by Patrick Henry
Winston and Berthold Klaus Paul Horn, copyright 1984 Addison-Wesley
Publishng Company) the version in cl.el is more correct.

On page 143 is says:

	The first argument given to the primitive MEMBER need not be
	an atom. However, by convention, MEMBER normally uses EQL as
	its equality test. Consequently, the unwary may be a little
	surprised by this apparent anomaly:

		(MEMBER '(A B) '((A B) (B C)))
		 NIL

	MEMBER returns NIL, even though (A B) is an element of ((A B)
	(B C)), because MEMBER test for equality using EQL. This is
	reasonable, surprisingly. EQL is normally good enough, and EQL
	is typically much faster than EQUAL is.

Of course in common lisp, you can override this behavior using

	(MEMBER '(A B) '((A B) (B C)) :TEST 'EQUAL)

but we can not easily do that in GNU Emacs LISP. Still, I have come to
expect the documented behavior of MEMBER and would rather have it
continue to use EQL rather than EQUAL.

Mike>   For example:

Mike>   (member "abc" '("abc")) ==> ("abc")
Mike>   (require 'cl)
Mike>   (member "abc" '("abc")) ==> nil

Mike>     Why is 'member redefined??  How can I protect my favourite
Mike>   customisations from becoming completely weirded out by basic functions
Mike>   changing beneath my feet?  Should I define my own version of 'member??

I can only guess that you have previously loaded doctor.el.

I would recommend you define your own version of member and name it
something other than member (perhals equal-member is a good name?)
which uses equal rather than eql.
	
Mike>   P.S.  Sorry if I'm covering old ground here ...

I have not seen this ground covered.

Mike> --
Mike>       /-------------------- byrd@comp.vuw.ac.nz --------------------\ 
Mike>       | Mike Williams, Victoria University of Wellington, Aotearoa. |
Mike>       \------------ What's another word for Thesaurus? -------------/

-- 
Mark D. Baushke
mdb@ESD.3Com.COM
Technical Details
Message-ID: <9009180803.AA07733@kosciusko.ESD.3Com.COM>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!esd.3com.com!mdb

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,ece3248edb24e98b,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-09-18 01:03:17 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!esd.3com.com!mdb
From: mdb@esd.3com.com ("Mark D. Baushke")
Newsgroups: gnu.emacs.bug
Subject: Re: cl.el breaks 'member
Message-ID: <9009180803.AA07733@kosciusko.ESD.3Com.COM>
Date: 18 Sep 90 08:03:17 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: 3Com, 5400 Bayfront Plaza, Santa Clara, CA 95052-8145
Lines: 92
Posted: Tue Sep 18 09:03:17 1990