From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] master 1691a51: * lisp/emacs-lisp/map.el: Make the functions generic Date: Thu, 13 Dec 2018 14:25:24 +0000 Message-ID: <87o99p1p2j.fsf@tcd.ie> References: <20181211225418.14641.49501@vcs0.savannah.gnu.org> <20181211225420.1E3692092C@vcs0.savannah.gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1544711094 18934 195.159.176.226 (13 Dec 2018 14:24:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Dec 2018 14:24:54 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Stefan Monnier To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 13 15:24:50 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gXRuz-0004pz-U1 for ged-emacs-devel@m.gmane.org; Thu, 13 Dec 2018 15:24:50 +0100 Original-Received: from localhost ([::1]:52900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXRx6-0002CX-OG for ged-emacs-devel@m.gmane.org; Thu, 13 Dec 2018 09:27:00 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXRvj-0001Vl-QC for emacs-devel@gnu.org; Thu, 13 Dec 2018 09:25:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXRvj-0007gE-1e for emacs-devel@gnu.org; Thu, 13 Dec 2018 09:25:35 -0500 Original-Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]:38904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXRvh-0007aV-0i for emacs-devel@gnu.org; Thu, 13 Dec 2018 09:25:33 -0500 Original-Received: by mail-ed1-x52d.google.com with SMTP id h50so2181205ede.5 for ; Thu, 13 Dec 2018 06:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=Vm1BHaTsZynmcVgSMbv/HUF/w9BL9HPfVu6QChcR7tc=; b=WUDDVkNnl0jSCUx/kfzsBLttQ5zb7rr2cTZj+UUNJs6fDhwuAt53mYnmHj+slGmvKc oZJdaXjmsiBbegB0gO76kkSavY39vjmeF0t4UB3/2PqwskuBiWjUa0sRso4q24YE9fSX A2h8i36yGkPU5lLJ0vAXvCk64czALHoMHihDqsXKrzi5hy7kOypo2tqNrq2YSy3mB4Bp j3r8oPsJKQW76xPtNKHB9DCxKJ+amC0P12fsO0Z1WZWuOfiNy8QBLl2mOw8pXDCL/cDm Im1FhGK5e1GfSVbAGSLlbisRZfH7Vq0hfBGA7ovnNrxkcaCjP/2Cbm6GvO6CSRgEO9j5 mycg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=Vm1BHaTsZynmcVgSMbv/HUF/w9BL9HPfVu6QChcR7tc=; b=uZ23OUBcrKHYyUFCvL9scNNpMRjKbI/xSDJ0PRA7IwYxb493Klb+hgfZBIna8hZ6NE 2Q7t8sjFeuF3mV9MtNTe9s2C4tO1b0eN6ES8vMNMEEYLfi7oWLkq3sZr9pWg9+ntkpXd 8KABoezSi8URmWEIbjpzqm1s/nerFhk3RRE6HW0+WcuUgictTEwmMMri38KMvCE+frfK HvvOlOYPXyBm88sJ0w2q1RcabwdPFoj5YYD7BHbRtwma5w9h1Bz1TEjd46BES/EqJnSm lnWl6MhoeO9WUhimMi/VjShqO07c5GarJRNpxuHBt/FkGTXLQb14Q9BdvEYbIhXgvgcK emew== X-Gm-Message-State: AA+aEWbBodQDXzI8+4vCT+A1jm6oO+MrcnY25FvqxRkb/nLY26/Dpd+R YPfqKjBcmZO7v566Bj4Ed8uErZvzTcE= X-Google-Smtp-Source: AFSGD/XuXsUNzFmd76bousMB6S0Z55/Daekjui80am6VN44bWHFXEClYqaqnfp9cIo6TKKgnpBkCtw== X-Received: by 2002:aa7:c0d0:: with SMTP id j16mr22137955edp.173.1544711126617; Thu, 13 Dec 2018 06:25:26 -0800 (PST) Original-Received: from localhost ([2a02:8084:20e2:c380:f786:805d:f4ab:1006]) by smtp.gmail.com with ESMTPSA id y17-v6sm349577ejj.43.2018.12.13.06.25.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 06:25:25 -0800 (PST) In-Reply-To: <20181211225420.1E3692092C@vcs0.savannah.gnu.org> (Stefan Monnier's message of "Tue, 11 Dec 2018 17:54:19 -0500 (EST)") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::52d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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 Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:231795 Archived-At: monnier@iro.umontreal.ca (Stefan Monnier) writes: > -(defun map-empty-p (map) > +(cl-defgeneric map-empty-p (map) > "Return non-nil if MAP is empty. > +The default implementation delegates to `map-length'." > + (zerop (map-length map))) > -MAP can be a list, hash-table or array." > - (map--dispatch map > - :list (null map) > - :array (seq-empty-p map) > - :hash-table (zerop (hash-table-count map)))) Why not continue to check whether lists are null, rather than traversing their entire length: (cl-defmethod map-empty-p ((map list)) (null map)) Is it not worth it? > +(cl-defmethod map-contains-key ((map list) key &optional testfn) > + (alist-get key map nil nil (or testfn #'equal))) I think this should get the same treatment as the hash table method, which checks whether DEFAULT was returned: (cl-defmethod map-contains-key ((map list) key &optional testfn) (let ((v '(nil))) (not (eq v (alist-get key map v nil (or testfn #'equal)))))) Thanks, -- Basil