From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: space leak from `values' Date: 20 Aug 2004 14:51:32 +0200 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1093006283 16287 80.91.224.253 (20 Aug 2004 12:51:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 20 Aug 2004 12:51:23 +0000 (UTC) Cc: emacs-devel@gnu.org, d.love@dl.ac.uk, monnier@iro.umontreal.ca, miles@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 20 14:51:09 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1By8rM-0004PT-00 for ; Fri, 20 Aug 2004 14:51:09 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1By8vf-0003HJ-OY for ged-emacs-devel@m.gmane.org; Fri, 20 Aug 2004 08:55:35 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1By8vW-0003H6-NV for emacs-devel@gnu.org; Fri, 20 Aug 2004 08:55:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1By8vU-0003Go-Ve for emacs-devel@gnu.org; Fri, 20 Aug 2004 08:55:26 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1By8vU-0003Gl-T8 for emacs-devel@gnu.org; Fri, 20 Aug 2004 08:55:24 -0400 Original-Received: from [212.88.64.25] (helo=mail-relay.sonofon.dk) by monty-python.gnu.org with smtp (Exim 4.34) id 1By8qv-0002gQ-Cc for emacs-devel@gnu.org; Fri, 20 Aug 2004 08:50:42 -0400 Original-Received: (qmail 39626 invoked from network); 20 Aug 2004 12:50:38 -0000 Original-Received: from unknown (HELO kfs-l.imdomain.dk.cua.dk) (213.83.150.2) by 0 with SMTP; 20 Aug 2004 12:50:38 -0000 Original-To: rms@gnu.org In-Reply-To: Original-Lines: 41 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 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: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:26341 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:26341 Referring to my proposal for adding setnthcdr, and the number of places where a list is currently truncated in the lisp files, Richard Stallman writes: > I did not realize there were so many places where this was done. > However, (setcdr (or (nthcdr N LIST) (list nil)) nil) is pretty > simple. I am not sure we need a new function to replace that > even if that is done 20 times in Emacs. Since the only practical use of the "setnthcdr" function is to simply truncate a list to a specific length, I suggest a new function truncate-list (to be defined in subr.el): (defun truncate-list (list n) "Truncate list LIST to have a maximum of N elements. If LIST has less than N element, do nothing." (if (setq list (nthcdr (1- n) list)) (setcdr list nil))) Using that function is both clearer and more efficient than how it's done currently. e.g. instead of (setq kill-ring (cons string kill-ring)) (if (> (length kill-ring) kill-ring-max) (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))) just write (truncate-list (setq kill-ring (cons string kill-ring)) kill-ring-max) Also, it is much simpler to document truncate-list than the more generic setnthcdr. -- Kim F. Storm http://www.cua.dk