[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#67669: 29.1; Drop text suggesting using `and' to replace `if'
From: |
Xiyue Deng |
Subject: |
bug#67669: 29.1; Drop text suggesting using `and' to replace `if' |
Date: |
Fri, 08 Dec 2023 01:07:27 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Eli Zaretskii <eliz@gnu.org> writes:
>> 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.
Ah I see. So it looks like in Elisp `and' and `if' are actually used
interchangeably. This was not very obvious at first for me who's more
familiar with other imperative languages. TIL. Thanks!
--
Xiyue Deng
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', (continued)
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Xiyue Deng, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Eli Zaretskii, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Xiyue Deng, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Eli Zaretskii, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Xiyue Deng, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Eli Zaretskii, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Xiyue Deng, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Drew Adams, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Xiyue Deng, 2023/12/08
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Eli Zaretskii, 2023/12/08
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if',
Xiyue Deng <=
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Drew Adams, 2023/12/08
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Drew Adams, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Xiyue Deng, 2023/12/07
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Sean Whitton, 2023/12/08
- bug#67669: 29.1; Drop text suggesting using `and' to replace `if', Xiyue Deng, 2023/12/08