all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 37450@debbugs.gnu.org
Subject: bug#37450: 26.3; `all-completions' PREDICATE for a hash table COLLECTION
Date: Wed, 18 Sep 2019 11:02:03 -0700 (PDT)	[thread overview]
Message-ID: <140d4456-6455-4e48-b3a4-db9b13d6787a@default> (raw)

`C-h f all-completions' says this for this case:

  If COLLECTION is a hash-table, predicate is called with two arguments:
  the key and the value.

Why does the PREDICATE function need to accept a VALUE argument, as well
as a KEY argument?  When an alist or obarray is used, the only thing
PREDICATE needs is the KEY to look up.  I would think that that's the
only thing needed for a hash table also, logically.

I had this in one of my functions, back when `bbdb-complete-mail' used
an alist, before it changed to using hash-table `bbdb-hashtable':

(all-completions orig 
                 THE-BBDB-ALIST
                 (lambda (sym)
                    (when (bbdb-completion-predicate sym)
                      (push sym all-comps))))

I had to change that to this, adding an (unused?) arg for the PREDICATE:

(all-completions orig 
                 bbdb-hashtable'
                 (lambda (sym __)
                    (when (bbdb-completion-predicate sym)
                      (push sym all-comps))))

Why should the PREDICATE function need to change, now that a hash table
is used?  The VALUE arg for the PREDICATE isn't necessary for hash-table
lookup, right?  If that's right then why not have the PREDICATE accept
the KEY as a minimum?  If some code wants to additionally include a
VALUE arg, it could do that.  Can't just `all-completions' DTRT,
applying the PREDICATE to the provided KEY and VALUE if provided, else
nil for VALUE?

If `all-completions' were coded in Lisp I might take a look, to see
whether there's a good reason for PREDICATE to require 2 args when the
second arg to `all-completions' is a hash table.  So far, I'm just
wondering.  If all that's logically required is a KEY lookup, why make
an exception for hash tables, forcing the PREDICATE to accept also an
(unused?) VALUE?

In GNU Emacs 26.3 (build 1, x86_64-w64-mingw32)
 of 2019-08-29
Repository revision: 96dd0196c28bc36779584e47fffcca433c9309cd
Windowing system distributor `Microsoft Corp.', version 10.0.17763
Configured using:
 `configure --without-dbus --host=x86_64-w64-mingw32
 --without-compress-install 'CFLAGS=-O2 -static -g3''





             reply	other threads:[~2019-09-18 18:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18 18:02 Drew Adams [this message]
2019-09-18 18:26 ` bug#37450: 26.3; `all-completions' PREDICATE for a hash table COLLECTION Drew Adams
2021-01-30  7:23   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=140d4456-6455-4e48-b3a4-db9b13d6787a@default \
    --to=drew.adams@oracle.com \
    --cc=37450@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.