From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Deniz Dogan Newsgroups: gmane.emacs.devel Subject: Re: Why aren't there functions such as filter, take-while, etc. "by default"? Date: Mon, 26 Apr 2010 01:10:14 +0200 Message-ID: References: <87fx2j5wle.fsf@lola.goethe.zz> <90A0FD191C5F4D1A9F844EC734695D49@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1272237047 31234 80.91.229.12 (25 Apr 2010 23:10:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 25 Apr 2010 23:10:47 +0000 (UTC) Cc: David Kastrup , emacs-devel@gnu.org To: Drew Adams Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Apr 26 01:10:46 2010 connect(): No such file or directory Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O6AyJ-0004Vd-C9 for ged-emacs-devel@m.gmane.org; Mon, 26 Apr 2010 01:10:43 +0200 Original-Received: from localhost ([127.0.0.1]:46664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6AyI-00034Y-LI for ged-emacs-devel@m.gmane.org; Sun, 25 Apr 2010 19:10:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O6AyE-00034T-CE for emacs-devel@gnu.org; Sun, 25 Apr 2010 19:10:38 -0400 Original-Received: from [140.186.70.92] (port=55450 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6AyC-00034L-Sa for emacs-devel@gnu.org; Sun, 25 Apr 2010 19:10:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O6AyB-0000yk-79 for emacs-devel@gnu.org; Sun, 25 Apr 2010 19:10:36 -0400 Original-Received: from mail-ww0-f41.google.com ([74.125.82.41]:56623) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O6AyB-0000yZ-2M; Sun, 25 Apr 2010 19:10:35 -0400 Original-Received: by wwb13 with SMTP id 13so74858wwb.0 for ; Sun, 25 Apr 2010 16:10:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=Kh7yWlRFCNxNsJFaPv7K7hR9PEEjPMBA0acsji9/4uI=; b=a+zeNDfRFhlN56fpc+gefHW2Yobw3kRUv70OnbfxzQbWKA2CRyyecfwlzMy0lcScni zGJRwZMkei2w/EAwTFCQymK5eLhvKcEmTVurNLEQ45X2XNbhD3Al8YZOda4XhVkh33mR GafryGn475j+8+wftKlScm7yEXkPldjVhJEF4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=NGJF/mHM9e3GwTkr8lTpVh1kUOxwK8emWnAMZ7LSHXva/lRiRCAg8PqlEtjAMwV5l+ CeIDL/h4rrRK8t5Xvrj9vzKqnzvD9Ki6MpZevW3DDIFkG/SVGGt2EqdeAY6wMqAeorgJ h+7YrDH4MdmaI6IGgurc9MsKzj3NCfxrcaPBk= Original-Received: by 10.216.86.203 with SMTP id w53mr670640wee.71.1272237034104; Sun, 25 Apr 2010 16:10:34 -0700 (PDT) Original-Received: by 10.216.229.83 with HTTP; Sun, 25 Apr 2010 16:10:14 -0700 (PDT) In-Reply-To: <90A0FD191C5F4D1A9F844EC734695D49@us.oracle.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:124209 Archived-At: 2010/4/26 Drew Adams : >> `sort' which given a list and a predicate sorts the list >> destructively (rendering the original list useless) and then returns a >> sorted copy of the original list. > > `sort' does not return a copy. It returns the sorted list, that is, the m= odified > list. > > ,---- > | sort is a built-in function in `C source code'. > | > | (sort LIST PREDICATE) > | > | Sort LIST, stably, comparing elements using PREDICATE. > | Returns the sorted list. =A0LIST is modified by side effects. > =A0 =A0 =A0 =A0 =A0^^^^^^^^^^^^^^^ =A0 =A0 =A0 =A0 =A0 ^^^^^^^^ > | PREDICATE is called with two elements of LIST, and should return non-ni= l > | if the first element should sort before the second. > | > | [back] > `---- > >> (let* ((my-list (list 3 2 1)) >> =A0 =A0 =A0 =A0(sorted (sort my-list '<))) >> =A0 my-list) ;; returns (3) > > The sorted list is (1 2 3). If your sexp returned `sorted' instead of `my= -list' > then that is what you would get. > > Your sexp returns (3) because `my-list' points to the cons cell whose car= is 3, > and after sorting that same cons cell is the last one in the sorted list.= If > `sort' returned a complete copy, then its result (`sorted') would not sha= re any > list structure with the original list. Try this, and you will see that `s= orted' > is (1 2 5). The last cons cell in `sorted' is the cons cell pointed to by > `my-list'. > > (let* ((my-list (list 3 2 1)) > =A0 =A0 =A0 (sorted (sort my-list '<))) > =A0(setcar my-list 5) > =A0(message "sorted: %S" sorted) (sit-for 3) ; (1 2 5) > =A0my-list) ; returns (5) > > Thank you for the explanation. However, I can't help but feel that this is just proving my point... :-) --=20 Deniz Dogan