From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#45539: 26.3; `add-to-ordered-list': Add optional arg for :test predicate for hash table Date: Tue, 29 Dec 2020 23:01:03 -0800 (PST) Message-ID: <64015d41-a84f-4ff6-a5a1-ab5d92aa20e5@default> References: <1af7f2ac-0e6c-4c8a-860b-22148265d8aa@default> <87y2hgosxo.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30068"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 45539@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 30 08:02:15 2020 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 1kuVUs-0007iE-Oc for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 08:02:14 +0100 Original-Received: from localhost ([::1]:60114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kuVUr-0004Aj-7o for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 02:02:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kuVUg-0004AD-5R for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 02:02:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57471) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kuVUf-0007uK-Sk for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 02:02:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kuVUf-0002fI-PK for bug-gnu-emacs@gnu.org; Wed, 30 Dec 2020 02:02:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Dec 2020 07:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45539 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 45539-submit@debbugs.gnu.org id=B45539.160931167910194 (code B ref 45539); Wed, 30 Dec 2020 07:02:01 +0000 Original-Received: (at 45539) by debbugs.gnu.org; 30 Dec 2020 07:01:19 +0000 Original-Received: from localhost ([127.0.0.1]:40784 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kuVTz-0002eM-CE for submit@debbugs.gnu.org; Wed, 30 Dec 2020 02:01:19 -0500 Original-Received: from userp2130.oracle.com ([156.151.31.86]:44910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kuVTv-0002e6-CH for 45539@debbugs.gnu.org; Wed, 30 Dec 2020 02:01:17 -0500 Original-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BU6n7MU085448; Wed, 30 Dec 2020 07:01:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=hXQWAgOewnxqQ3EvnPdsh1aqDz+ZfYOErTsQ7h/UuFU=; b=rZW4mVJElWgvB6QY6gHDHJ6GbBEZV2Q/mJXP1qEe4Hiytk7+F1m5iXwjB8oXoip5kxoZ 5r6r1VHQ7HZy+3XayVQPhUvovv9P5KmkIh9iesjnvGbxvmht/qooRJw3tJ15x/Zri3St x24opahQYwJGdrcdxM4sNpAiZp6E0tfe4oXi/4je6S1zG5VmK4uRc79CKuGJPUg2F+7v 09K5psoq5auopxydq1/n+SgyeJLwtZFjQvHCsKS1MIKDI+OoMjwnXYhlWZhMi2XbTrMR GqOF4jYc4rF4KbH+jdSG1YCeFALjjwj5U5apsGi/B5Zpbwfnob0mSeOVZu58sMgTh6fY Sg== Original-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 35nvkqr1dv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 30 Dec 2020 07:01:08 +0000 Original-Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BU6oxA7079784; Wed, 30 Dec 2020 07:01:08 GMT Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 35pf3xmneb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Dec 2020 07:01:07 +0000 Original-Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0BU714XN016130; Wed, 30 Dec 2020 07:01:05 GMT In-Reply-To: <87y2hgosxo.fsf@gnus.org> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5095.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9849 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=753 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012300040 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9849 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 suspectscore=0 mlxlogscore=748 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012300040 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" Xref: news.gmane.io gmane.emacs.bugs:197008 Archived-At: > > Please consider adding an optional arg TEST-PREDICATE, which will be > > passed to the hash table (and which will default to `eq'). >=20 > Since the ordering is hard-coded to `<', allowing the things being > compared are presumably all numbers, so allowing specifying the > comparison function doesn't make much sense. >=20 > However, using `eq' for numbers doesn't make much sense, either -- `eql' > would be better. Looking at the in-tree usages, switching to `eql' > shouldn't make much difference, so I've done the daring thing and > switched to `eql'. I don't understand. One of us is confused, I think. What does the :test predicate for the hash table have to do with the order = of elements in the list? This is about letting you specify how the hash table is configured, by pass= ing a TEST predicate arg to `add-to-ordered-list', which is just passed to = the code implementing the hash table. The purpose of the hash table's :tes= t predicate is only to determine whether a hash-table item is already prese= nt, and if so, get its value using the item as key. The code is currently hard-coded to use `eq' for :test, which works fine fo= r symbol hash-table data, hence for symbol elements of the list. But it do= esn't work fine for, say, string list elements. (And it wouldn't work well= for numeric list elements, for which a :test of `eql' would be better.) But in all cases, :test is about comparing the list elements, not their ass= ociated "order" in the list. The things being compared are not numbers, they are the list elements. The= hash table is not used in any way for ordering the list. The hash table h= ashes list elements (which can be anything) as the hash-table keys, and the= order of those elements in the list (which are numeric) as the "order" val= ues of the list elements. When an entry is added to a hash table, it's the= key, not the value, that's compared against other keys, using :test. (elisp) `Creating Hash' says, for example: ':test TEST' This specifies the method of key lookup for this hash table. The default is 'eql'; 'eq' and 'equal' are other alternatives: 'eql' Keys which are numbers are the same if they are 'equal', that is, if they are equal in value and either both are integers or both are floating point; otherwise, two distinct objects are never the same. 'eq' Any two distinct Lisp objects are different as keys. 'equal' Two Lisp objects are the same, as keys, if they are equal according to 'equal'. In my understanding, :test is all about comparing hash-table keys, not valu= es. The hash table implements an association of ordered-list elements (the= keys) with their orders in the list (the values). This is about letting any kind of list elements to be in an "ordered list".= In the case of the example question, the list elements would be strings. = (Their orders in the list would be numbers.) For string elements a :test = of `equal' (or even `string=3D') makes sense and `eq' makes no sense.