From: Drew Adams <drew.adams@oracle.com>
To: Eli Zaretskii <eliz@gnu.org>, Lars Ingebrigtsen <larsi@gnus.org>
Cc: lekktu@gmail.com, emacs-devel@gnu.org
Subject: RE: master 2bb0703 1/2: lisp/*.el: Force non-nil result to t, to match docstring
Date: Thu, 17 Oct 2019 15:15:39 +0000 (UTC) [thread overview]
Message-ID: <b628134c-c924-48cd-8276-a99d70a25906@default> (raw)
In-Reply-To: <<8336frdcs9.fsf@gnu.org>>
> > > Depends. When the function is a predicate, t/nil makes more sense
> > > (generally speaking, there are exceptions) that non-nil/nil.
> >
> > I thought it was kinda opposite: When it's a predicate, we only care
> > about nil/non-nil.
>
> No, predicate returns a boolean result. Recall the recent discussion
> of using -p in function and variable names.
That begs the question of what "boolean result"
means. Is the number 42 or the string "Bernie"
or "false" a Boolean value (true), or not?
In Lisp, in general (e.g., other than Scheme),
Boolean values include so-called "generalized
booleans", which means nil (for false) and
any non-nil value (for true).
That some particular function (predicate) might
want to always return t as the non-nil value to
indicate true is up to that function, and if
the fact that it does so is important to its
behavior then it should be documented that it
does so.
If there's no good reason for a predicate to
return something other than t to represent
true, then it should typically just use t.
But in general there should be no requirement
for a predicate to return t for true. Any
non-nil value means true, a priori.
I agree with this general and longstanding
Lisp convention. So +1 for not, in general
depending on t to be the only true value.
So IIUC, I agree with Lars on this general
question.
There's nothing wrong with a predicate always
returning only t for true, of course. That
doesn't affect how other predicates handle
generalized Boolean values. t is non-nil,
after all, even if non-nil is not necessarily
t.
(Not saying anything about whether this or
that particular predicate is better "fixed"
by ensuring that it uses only t for true or
changing its doc to say that t is the only
true value. Not saying anything about the
"fixes" Juanma made.)
Node (elisp) `nil and t' says it very well:
In contexts where a truth value is expected,
any non-'nil' value is considered to be TRUE.
However, 't' is the preferred way to represent
the truth value TRUE. When you need to choose
a value that represents TRUE, and there is no
other basis for choosing, use 't'. The symbol
't' always has the value 't'.
I agree with every bit of that text.
If there is no good reason not to use t, use t.
But something TESTING a value as a truth value
should, in general, consider any non-nil value
to be true.
("In general", because sometimes the value to
test can be either a truth value or something
else. In such a case, different non-nil values
can mean different things.)
And there is often a good reason for a given
predicate to return some other non-nil value
than t for true. Why is this true so often?
Because it lets the predicate be, secondarily,
more than a predicate, returning secondary
information along with truth value t.
Common Lisp is also a good reference in this
regard. "In Common Lisp, as in most Lisp
dialects..."
https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node9.html
http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_g.htm
next parent reply other threads:[~2019-10-17 15:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <<20191017004602.22269.2935@vcs0.savannah.gnu.org>
[not found] ` <<20191017004604.866DF20BC2@vcs0.savannah.gnu.org>
[not found] ` <<875zkonpqm.fsf@gnus.org>
[not found] ` <<CAAeL0SSg8_9vELEeH9BtC02Bpf26AVCgLhpsBSAgQ0nLzXtrMw@mail.gmail.com>
[not found] ` <<871rvcnmg1.fsf@gnus.org>
[not found] ` <<8336frdcs9.fsf@gnu.org>
2019-10-17 15:15 ` Drew Adams [this message]
2019-10-17 15:43 ` master 2bb0703 1/2: lisp/*.el: Force non-nil result to t, to match docstring Juanma Barranquero
2019-10-17 18:02 ` Stefan Monnier
2019-10-17 18:18 ` Juanma Barranquero
2019-10-17 18:31 ` Stefan Monnier
2019-10-17 18:37 ` Eli Zaretskii
2019-10-17 19:29 ` Stefan Monnier
[not found] <20191017004602.22269.2935@vcs0.savannah.gnu.org>
[not found] ` <20191017004604.866DF20BC2@vcs0.savannah.gnu.org>
2019-10-17 1:08 ` Lars Ingebrigtsen
2019-10-17 1:44 ` Juanma Barranquero
2019-10-17 2:19 ` Lars Ingebrigtsen
2019-10-17 2:26 ` Juanma Barranquero
2019-10-17 2:49 ` Ergus
2019-10-17 3:45 ` Juanma Barranquero
2019-10-17 3:47 ` Lars Ingebrigtsen
2019-10-17 3:59 ` Juanma Barranquero
2019-10-17 7:57 ` Eli Zaretskii
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b628134c-c924-48cd-8276-a99d70a25906@default \
--to=drew.adams@oracle.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=larsi@gnus.org \
--cc=lekktu@gmail.com \
/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 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).