GNU bug report logs - #67669
29.1; Drop text suggesting using `and' to replace `if'

Previous Next

Package: emacs;

Reported by: Xiyue Deng <manphiz <at> gmail.com>

Date: Wed, 6 Dec 2023 21:48:01 UTC

Severity: normal

Found in version 29.1

Done: Xiyue Deng <manphiz <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #46 received at 67669 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Xiyue Deng <manphiz <at> gmail.com>
Cc: 67669 <at> debbugs.gnu.org
Subject: Re: bug#67669: 29.1; Drop text suggesting using `and' to replace `if'
Date: Fri, 08 Dec 2023 08:25:16 +0200
> From: Xiyue Deng <manphiz <at> gmail.com>
> Cc: 67669-done <at> debbugs.gnu.org
> Date: Thu, 07 Dec 2023 12:37:58 -0800
> 
> Eli Zaretskii <eliz <at> 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.




This bug report was last modified 1 year and 224 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.