unofficial mirror of bug-gnu-emacs@gnu.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

* bug#37450: 26.3; `all-completions' PREDICATE for a hash table COLLECTION
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2019-09-18 18:26 UTC (permalink / raw)
  To: 37450

> (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))))

I shouldn't have been so definitive about that "fix".
It apparently didn't work - the user now reports a
different error message, saying "Something like two
arguments but expected one."  I don't use BBDB, so
I'm flying a bit blind on this.

Hope my bug report makes some sense in any case.
My question seems reasonable, at least in my relative
ignorance: why must the PREDICATE take also a VALUE
arg when COLLECTION is a hash table?  Why isn't KEY
lookup sufficient?





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

* bug#37450: 26.3; `all-completions' PREDICATE for a hash table COLLECTION
  2019-09-18 18:26 ` Drew Adams
@ 2021-01-30  7:23   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2021-01-30  7:23 UTC (permalink / raw)
  To: Drew Adams; +Cc: 37450

Drew Adams <drew.adams@oracle.com> writes:

> Hope my bug report makes some sense in any case.
> My question seems reasonable, at least in my relative
> ignorance: why must the PREDICATE take also a VALUE
> arg when COLLECTION is a hash table?  Why isn't KEY
> lookup sufficient?

Presumably because it's more convenient sometimes?  In any case, this
interface can't be changed, because that would break a lot of code.
Closing.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ 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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).