From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: sort needs a #:key argument Date: Tue, 20 Oct 2009 21:26:06 +0200 Message-ID: References: <87pr8impd0.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1256066803 32596 80.91.229.12 (20 Oct 2009 19:26:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 20 Oct 2009 19:26:43 +0000 (UTC) Cc: guile-devel@gnu.org To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Oct 20 21:26:32 2009 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N0KLS-0006Cq-2G for guile-devel@m.gmane.org; Tue, 20 Oct 2009 21:26:10 +0200 Original-Received: from localhost ([127.0.0.1]:33460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0KLR-00039x-G3 for guile-devel@m.gmane.org; Tue, 20 Oct 2009 15:26:09 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0KLK-00039j-5r for guile-devel@gnu.org; Tue, 20 Oct 2009 15:26:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0KLF-00037v-PA for guile-devel@gnu.org; Tue, 20 Oct 2009 15:26:01 -0400 Original-Received: from [199.232.76.173] (port=46624 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0KLF-00037q-Fd for guile-devel@gnu.org; Tue, 20 Oct 2009 15:25:57 -0400 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:65019 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0KLA-0003U8-Ba; Tue, 20 Oct 2009 15:25:52 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 2C9846073B; Tue, 20 Oct 2009 15:25:52 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=KJlvedph2y7D vbST+06DA1mjG8A=; b=MPz7i8At9YxEtQMa40A8tgnVF2Vrbv7J5HMePFJ2AGLs yhtTlElUeQNa8sSUnw95YTUeJJSxLff0yeg4Xn6yY/LAJNaiRK4P9gZpnMsFcDc8 oRUbpUepWZZvSq/Kjv7cbAyqx0xC2xF9pnd3gzxFkT996NRSBEx39aRVDvUW7VU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=sasl; b=msxhB0 Y5ZLl6jqJK5jaWETU6DBKW6Sy2sNOxVoKGx9uLsQnOSdCPF+LEgb7JMtIPQLz64/ JX+piuVeLFH/eaXm0LIS1asSm5MEyee+Jmlm14vevWmi0TEQmfnXVOGZ2YPPdBZv HE/puJnLxhmLjv88K0OuiLqSM0dCkcqMxNt0I= Original-Received: from a-pb-sasl-quonix. (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 12B476073A; Tue, 20 Oct 2009 15:25:51 -0400 (EDT) Original-Received: from unquote (unknown [83.34.240.150]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 615D760739; Tue, 20 Oct 2009 15:25:49 -0400 (EDT) In-Reply-To: <87pr8impd0.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Tue, 20 Oct 2009 10:38:51 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) X-Pobox-Relay-ID: 6098ECD2-BDAE-11DE-852C-1B12EE7EF46B-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:9542 Archived-At: Hi, On Tue 20 Oct 2009 10:38, ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Andy Wingo writes: > >> (sort '((a . 1) (b . -2) (c . 3)) < cdr) >> =3D> ((b . -2) (a . 1) (c . 3)) > > FWIW I find: > > (sort '((a . 1) (b . -2) (c . 3)) > (lambda (x y) > (< (cdr x) (cdr y)))) > > more in the spirit of not =E2=80=9Cpiling feature on top of feature=E2=80= =9D. (sort l < #:key cdr) is a bit contrived. But if your key takes time to compute, you need to use the decorate-sort-undecorate idiom, otherwise you compute the sort key O(n log n) times instead of O(n) times. It's part of our old Lisp tradition :) Plus.. it's for occupational safety. Less typing for the win! :) Andy --=20 http://wingolog.org/