all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#37450: 26.3; `all-completions' PREDICATE for a hash table COLLECTION
@ 2019-09-18 18:02 Drew Adams
  2019-09-18 18:26 ` Drew Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2019-09-18 18:02 UTC (permalink / raw)
  To: 37450

`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''





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-30  7:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-18 18:02 bug#37450: 26.3; `all-completions' PREDICATE for a hash table COLLECTION Drew Adams
2019-09-18 18:26 ` Drew Adams
2021-01-30  7:23   ` Lars Ingebrigtsen

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.