From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#69709: `sort` interface improvement and universal ordering predicate Date: Sun, 10 Mar 2024 17:48:34 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16603"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 69709@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 10 16:49:49 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rjLQq-00043S-BR for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Mar 2024 16:49:49 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rjLQc-0003Yc-4q; Sun, 10 Mar 2024 11:49:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjLQY-0003Tx-3I for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 11:49:31 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rjLQX-0002nN-RT for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 11:49:29 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rjLR4-000554-Bg for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 11:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Mar 2024 15:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69709 X-GNU-PR-Package: emacs Original-Received: via spool by 69709-submit@debbugs.gnu.org id=B69709.171008575919302 (code B ref 69709); Sun, 10 Mar 2024 15:50:02 +0000 Original-Received: (at 69709) by debbugs.gnu.org; 10 Mar 2024 15:49:19 +0000 Original-Received: from localhost ([127.0.0.1]:37736 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjLQN-00051E-3Y for submit@debbugs.gnu.org; Sun, 10 Mar 2024 11:49:19 -0400 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:43707) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjLQK-00050N-Fc for 69709@debbugs.gnu.org; Sun, 10 Mar 2024 11:49:17 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id C03365C0049; Sun, 10 Mar 2024 11:48:37 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 10 Mar 2024 11:48:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1710085717; x=1710172117; bh=TEfyrcB3yogkQ6gCGD8glF1Kg5kAHoYG26IOpMnuaz4=; b= juFVkyH/f0l0tN9enI5fn5nPImjNViVVxyq/SMJgnUC1cdNgvHk3p91WQC/7bg39 M1wD9n6/l9rL+0bpiim+YB7ypHyuhk2nIbbBL4BRiRB+H2IYlbQMKQJRV4Iwuq7z qbyGoXYk8iC/sFUGMuRg5KfkdH6Ym1HkxLiKexLgsOjdk5g4zfEFhHuVrP9iE50x KdE47gNPywEulkPFYxxf/Wq83ilh2sYm82AHUV6ezo4lWlkWLAeBHcZaoZ+k8d+D JnSnELVXGws/bT75gUSk+POa1nD0bl3HwYdxIl5rvJI4oR6/oFkvxJwUvrHu/fcW SHxvnTNAfP6iYUdgkaqCRA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710085717; x= 1710172117; bh=TEfyrcB3yogkQ6gCGD8glF1Kg5kAHoYG26IOpMnuaz4=; b=Z YN2CYuqNAU021BsiNZajR3nDC/TuYmvKQltMufdiJDVZaR7CTD6jSdxlgva1HDoa 2xgJhuer7Zqz0Hjja9TMs8u0dVIxbvIHOBDY5G0LitNSwkbyjeCaL2Me55iOaZCX QsHVJtb/AxKeq6KlMomj/dS7lUvRcqyhPfAhO2rDGdsUnMtqFycQ3pNIAHi9U0/q nmRj34ar2HWdMf53xMo3KDMuRpgyE/7v42Ye31ScBE+ntStOR6CjIk3EpvvbV134 XOtfqR8fA/53Iuiv0WwdAaaqrGxihP3CKUjvIteEKmSWZ7o2Q1K+jXqjVUgR4jmj 4t/+RdOTqOKTX5Y2ES1Jg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrieelgdektdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeffmhhithhr hicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrthhtvg hrnhepgeeugeetffduvdejvedvleeliedtfedtudfhfeefffejudekveejvdeffffgveeg necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepughmih htrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 10 Mar 2024 11:48:36 -0400 (EDT) Content-Language: en-US In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:281402 Archived-At: On 10/03/2024 15:28, Mattias EngdegÄrd wrote: > 2. Mutability by default is a bug magnet as well. > > To deal with the first problem, we could: > > * Add a universal ordering predicate that will compare two values of the > same type for many built-in types: numbers, strings, symbols, markers, > lists, vectors, records, and a few more. > * Make this ordering the default. > * Add a key (accessor) function argument, like that in the recent > `sort-on` interface, but built-in. This is important. > > These work very well together: the user does not need to write or even > choose an ordering predicate in most cases. Key functions are much less > error-prone to write, and with the lexicographic ordering of lists, > vectors and records, multi-key sorting is made much easier. > > A key function combined with a standard ordering can also be used to > optimise comparisons since we have all key values up front along with > how they should be compared. The original timsort code that we stole > from Python did this. > > As a starting point, a patch implementing a universal ordering predicate > is attached below. > > The proposed sorting function interface would be > > (new-sort seq &key key lessp destructive) Here's a concern: a lot of existing code is written with either mutability in mind (the source list is a throwaway one, owned by the caller), or coupled with copy-sequence already. If the new 'sort' default to non-destructive, wouldn't that make those existing callsites slower? Or at least some of them.