unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Xiyue Deng <manphiz@gmail.com>
Cc: 67669@debbugs.gnu.org
Subject: bug#67669: 29.1; Drop text suggesting using `and' to replace `if'
Date: Fri, 08 Dec 2023 08:25:16 +0200	[thread overview]
Message-ID: <83o7f11a9f.fsf@gnu.org> (raw)
In-Reply-To: <8734wdu4t5.fsf@debian-hx90.lan> (message from Xiyue Deng on Thu,  07 Dec 2023 12:37:58 -0800)

> From: Xiyue Deng <manphiz@gmail.com>
> Cc: 67669-done@debbugs.gnu.org
> Date: Thu, 07 Dec 2023 12:37:58 -0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> I was referring to whether we care about and use the result of the
> >> statement/function call.  In `and' we do, in `if' we don't and we just
> >> use the side effect.
> >
> > But that's not true.  'if' does return a value, and we do use it.
> > Consider this random example:
> >
> >   (defsubst posn-area (position)
> >     [...]
> >     (let ((area (if (consp (nth 1 position))
> > 		    (car (nth 1 position))
> > 		  (nth 1 position))))
> >       (and (symbolp area) area)))
> >
> > Here we bind 'area' to the value returned by 'if'.
> 
> Well if we use `if' with else then yes.

No.  When 'if' has no 'else' clause, and the test fails, 'if' returns
nil.  This is used in many places in our code.  Like this:

  (let (baz)
    (setq foo (concat "bar" (if (stringp baz) baz))))
    => "bar"

Here 'if' returns nil, and we use the feature of 'concat' to ignore
nil arguments.





  parent reply	other threads:[~2023-12-08  6:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06 21:47 bug#67669: 29.1; Drop text suggesting using `and' to replace `if' Xiyue Deng
     [not found] ` <handler.67669.B.170189926211616.ack@debbugs.gnu.org>
2023-12-06 22:08   ` Xiyue Deng
2023-12-07  6:28 ` Eli Zaretskii
2023-12-07  9:08   ` Xiyue Deng
2023-12-07 10:16     ` Eli Zaretskii
2023-12-07 17:49       ` Xiyue Deng
2023-12-07 17:56         ` Eli Zaretskii
2023-12-07 19:54           ` Xiyue Deng
2023-12-07 20:22             ` Eli Zaretskii
2023-12-07 20:37               ` Xiyue Deng
2023-12-07 21:29                 ` Drew Adams
2023-12-08  9:11                   ` Xiyue Deng
2023-12-08  6:25                 ` Eli Zaretskii [this message]
2023-12-08  9:07                   ` Xiyue Deng
2023-12-08 15:37                   ` Drew Adams
2023-12-07 19:37         ` Drew Adams
2023-12-07 20:00           ` Xiyue Deng
2023-12-08 10:45         ` Sean Whitton
2023-12-08 22:41           ` Xiyue Deng

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=83o7f11a9f.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=67669@debbugs.gnu.org \
    --cc=manphiz@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).