unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35206: [PATCH] Misleading `list-get' argument description
@ 2019-04-09 10:34 Mattias Engdegård
  2019-04-09 11:00 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2019-04-09 10:34 UTC (permalink / raw)
  To: 35206

[-- Attachment #1: Type: text/plain, Size: 320 bytes --]

The doc string for `list-get' says

  Use TESTFN to lookup in the alist if non-nil.  Otherwise, use `assq'.

which is misleading since it's an equality predicate, not a look-up function, and the default is `eq', not `assq'.
How about changing it to

  Equality is defined by TESTFN or by `eq' if nil or omitted.

[-- Attachment #2: 0001-Clarify-the-TESTFN-argument-to-alist-get.patch --]
[-- Type: application/octet-stream, Size: 1088 bytes --]

From 0bdfa84e6c55ff97286818b42ed3e6f035d47151 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Tue, 9 Apr 2019 12:27:30 +0200
Subject: [PATCH] Clarify the TESTFN argument to `alist-get'

* lisp/subr.el (alist-get): Clarify the meaning of the TESTFN argument.
It's an equality predicate, not a look-up function.
---
 lisp/subr.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 45b3916196..5eb6a53f78 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -781,7 +781,7 @@ Elements of ALIST that are not conses are ignored."
 (defun alist-get (key alist &optional default remove testfn)
   "Return the value associated with KEY in ALIST.
 If KEY is not found in ALIST, return DEFAULT.
-Use TESTFN to lookup in the alist if non-nil.  Otherwise, use `assq'.
+Equality is defined by TESTFN or by `eq' if nil or omitted.
 
 You can use `alist-get' in PLACE expressions.  This will modify
 an existing association (more precisely, the first one if
-- 
2.20.1 (Apple Git-117)


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

* bug#35206: [PATCH] Misleading `list-get' argument description
  2019-04-09 10:34 bug#35206: [PATCH] Misleading `list-get' argument description Mattias Engdegård
@ 2019-04-09 11:00 ` Eli Zaretskii
  2019-04-09 11:26   ` Mattias Engdegård
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2019-04-09 11:00 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 35206

> From: Mattias Engdegård <mattiase@acm.org>
> Date: Tue, 9 Apr 2019 12:34:09 +0200
> 
> The doc string for `list-get' says
> 
>   Use TESTFN to lookup in the alist if non-nil.  Otherwise, use `assq'.
> 
> which is misleading since it's an equality predicate, not a look-up function, and the default is `eq', not `assq'.
> How about changing it to
> 
>   Equality is defined by TESTFN or by `eq' if nil or omitted.

IMO, this has a problem similar to the original text: it has nothing
to "connect" it to the main part of the doc string, which is this:

  Return the value associated with KEY in ALIST.

Neither "look up" nor "equality" is directly and obviously related to
"associated with".  E.g., you probably like "equality" better because
your mental model of "associated with" is a test for equality;
however, someone else might prefer the current text because they think
of "looking up" in the same situation.  But the text doesn't make the
relation explicit, and that is IMO its main problem.

Can you think of a change that would resolve this problem?

Thanks.





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

* bug#35206: [PATCH] Misleading `list-get' argument description
  2019-04-09 11:00 ` Eli Zaretskii
@ 2019-04-09 11:26   ` Mattias Engdegård
  2019-04-09 11:45     ` Mattias Engdegård
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2019-04-09 11:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 35206

9 apr. 2019 kl. 13.00 skrev Eli Zaretskii <eliz@gnu.org>:
> 
> Neither "look up" nor "equality" is directly and obviously related to
> "associated with".  E.g., you probably like "equality" better because
> your mental model of "associated with" is a test for equality;
> however, someone else might prefer the current text because they think
> of "looking up" in the same situation.  But the text doesn't make the
> relation explicit, and that is IMO its main problem.

Good point. What about:

Comparison of KEY against the car of each ALIST element
is made using TESTFN, or `eq' if nil or omitted.






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

* bug#35206: [PATCH] Misleading `list-get' argument description
  2019-04-09 11:26   ` Mattias Engdegård
@ 2019-04-09 11:45     ` Mattias Engdegård
  2019-04-09 14:41       ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2019-04-09 11:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 35206

> 
> Comparison of KEY against the car of each ALIST element
> is made using TESTFN, or `eq' if nil or omitted.

If no knowledge whatsoever of alists can be assumed on the part of the reader, perhaps this would be better:

   "Return the value associated with KEY in ALIST.
+The value is the cdr of the first element in ALIST whose car is equal to KEY.
 If KEY is not found in ALIST, return DEFAULT.
-Use TESTFN to lookup in the alist if non-nil.  Otherwise, use `assq'.
+Equality is defined by TESTFN or by `eq' if nil or omitted.






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

* bug#35206: [PATCH] Misleading `list-get' argument description
  2019-04-09 11:45     ` Mattias Engdegård
@ 2019-04-09 14:41       ` Eli Zaretskii
  2019-04-09 14:59         ` Mattias Engdegård
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2019-04-09 14:41 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 35206

> From: Mattias Engdegård <mattiase@acm.org>
> Date: Tue, 9 Apr 2019 13:45:34 +0200
> Cc: 35206@debbugs.gnu.org
> 
> > 
> > Comparison of KEY against the car of each ALIST element
> > is made using TESTFN, or `eq' if nil or omitted.
> 
> If no knowledge whatsoever of alists can be assumed on the part of the reader, perhaps this would be better:
> 
>    "Return the value associated with KEY in ALIST.
> +The value is the cdr of the first element in ALIST whose car is equal to KEY.
>  If KEY is not found in ALIST, return DEFAULT.
> -Use TESTFN to lookup in the alist if non-nil.  Otherwise, use `assq'.
> +Equality is defined by TESTFN or by `eq' if nil or omitted.

This is much better, IMO.  It is better than your previous proposal,
because the text is simpler and thus more clear.

However, a slight rewording would improve it even more:

  Find an element of ALIST whose `car' equals KEY and return its `cdr'.
  ...
  Equality with KEY is tested by TESTFN, defaulting to `eq'.

IMO, this isn't about assuming knowledge, this is about being as
explicit as reasonably possible about what the function does.
(Strictly speaking, both your suggestion and mine still assume some
knowledge about alists, because we never explain what is an alist, nor
what is an "element" of an alist.)

Thanks.





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

* bug#35206: [PATCH] Misleading `list-get' argument description
  2019-04-09 14:41       ` Eli Zaretskii
@ 2019-04-09 14:59         ` Mattias Engdegård
  0 siblings, 0 replies; 6+ messages in thread
From: Mattias Engdegård @ 2019-04-09 14:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 35206-done

9 apr. 2019 kl. 16.41 skrev Eli Zaretskii <eliz@gnu.org>:
> 
>  Find an element of ALIST whose `car' equals KEY and return its `cdr'.
>  ...
>  Equality with KEY is tested by TESTFN, defaulting to `eq'.

Thank you, I pushed that change (except that I used "the first element" instead of "an element" for precision).

> IMO, this isn't about assuming knowledge, this is about being as
> explicit as reasonably possible about what the function does.
> (Strictly speaking, both your suggestion and mine still assume some
> knowledge about alists, because we never explain what is an alist, nor
> what is an "element" of an alist.)

That's all right -- I was mainly concerned with the quite misleading TESTFN description, and looked at the docs of similar functions (assq, assoc).






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

end of thread, other threads:[~2019-04-09 14:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-09 10:34 bug#35206: [PATCH] Misleading `list-get' argument description Mattias Engdegård
2019-04-09 11:00 ` Eli Zaretskii
2019-04-09 11:26   ` Mattias Engdegård
2019-04-09 11:45     ` Mattias Engdegård
2019-04-09 14:41       ` Eli Zaretskii
2019-04-09 14:59         ` Mattias Engdegård

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