From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Recent changes to add-to-list Date: Sun, 29 Oct 2006 10:38:07 +0100 Message-ID: <85ejsrlaww.fsf@lola.goethe.zz> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1162114849 3651 80.91.229.2 (29 Oct 2006 09:40:49 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 29 Oct 2006 09:40:49 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 29 10:40:46 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ge79p-0008QT-OI for ged-emacs-devel@m.gmane.org; Sun, 29 Oct 2006 10:40:46 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ge79o-0003sH-4u for ged-emacs-devel@m.gmane.org; Sun, 29 Oct 2006 04:40:44 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ge78J-0003j1-LZ for emacs-devel@gnu.org; Sun, 29 Oct 2006 04:39:11 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ge78H-0003hd-W6 for emacs-devel@gnu.org; Sun, 29 Oct 2006 04:39:11 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ge78H-0003h3-AX for emacs-devel@gnu.org; Sun, 29 Oct 2006 04:39:09 -0500 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.52) id 1Ge78H-0000vD-BT for emacs-devel@gnu.org; Sun, 29 Oct 2006 04:39:09 -0500 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1Ge78G-00006y-JR for emacs-devel@gnu.org; Sun, 29 Oct 2006 04:39:08 -0500 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id 791F41C452C6; Sun, 29 Oct 2006 10:38:07 +0100 (CET) Original-To: emacs-devel@gnu.org User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:61329 Archived-At: Hi, recently add-to-list got an optional comparison function argument, and Kim optimized a few general cases. The main problem I have with this is that it incurs additional runtime overhead even for the default case, and even though the comparison function will be function almost always. So I would think it more reasonable to add separate functions, add-to-listq, add-to-listql and add-to-list-whatever. That is verbose on obarray, but does not impact the general use case. Alternatively, the optimization could be done at compile time using macros. But I don't know whether there might be cases where add-to-list is required to be a function, and it seems like a bad idea to change such a frequently used function to a macro, in particular at the present point of time. Then I have qualms about the implementation: (defun add-to-list (list-var element &optional append compare-fn) [...] (if (cond ((null compare-fn) (member element (symbol-value list-var))) ((eq compare-fn 'eq) (memq element (symbol-value list-var))) ((eq compare-fn 'eql) (memql element (symbol-value list-var))) (t (let (present) (dolist (elt (symbol-value list-var)) (if (funcall compare-fn element elt) (setq present t))) present))) Note that this walks through the entire list even if the first comparison already establishes the presence of a list element. That is very bad, since that is likely the most common use case. It would make much more sense to do something like (t (let ((lst (symbol-value list-var))) (while (and lst (null (funcall compare-fn element (car lst)))) (setq lst (cdr lst))) lst))) instead. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum