unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Usefulness of (t nil) as the last sexp in (cond ...) constructs?
@ 2012-08-19  7:07 Bastien
  2012-08-19 10:23 ` Jeremiah Dodds
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bastien @ 2012-08-19  7:07 UTC (permalink / raw)
  To: emacs-devel

There are many places in *.el elisp files where we have this construct

(cond (...)
      (...)
      (t nil))

My understanding is that (t nil) is useless, since the ̀t' condition 
is only tested if other conditions are `nil'.

What is the purpose of (t nil)?

Can we safely remove it?

-- 
 Bastien




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

* Re: Usefulness of (t nil) as the last sexp in (cond ...) constructs?
  2012-08-19  7:07 Usefulness of (t nil) as the last sexp in (cond ...) constructs? Bastien
@ 2012-08-19 10:23 ` Jeremiah Dodds
  2012-08-19 11:29 ` Achim Gratz
  2012-08-19 12:06 ` Juanma Barranquero
  2 siblings, 0 replies; 6+ messages in thread
From: Jeremiah Dodds @ 2012-08-19 10:23 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-devel

Bastien <bzg@altern.org> writes:

> There are many places in *.el elisp files where we have this construct
>
> (cond (...)
>       (...)
>       (t nil))
>
> My understanding is that (t nil) is useless, since the ̀t' condition 
> is only tested if other conditions are `nil'.
>
> What is the purpose of (t nil)?

IIRC, it's mostly there to make it explicit that "this cond is expected
to return nil sometimes".

> Can we safely remove it?

Again, IIRC, it shouldn't affect behaviour to do so, but it might not be
preferable. 

-- 
Jeremiah Dodds

blog       : http://jdodds.github.com
github     : https://github.com/jdodds
freenode   : exhortatory
twitter    : kaens



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

* Re: Usefulness of (t nil) as the last sexp in (cond ...) constructs?
  2012-08-19  7:07 Usefulness of (t nil) as the last sexp in (cond ...) constructs? Bastien
  2012-08-19 10:23 ` Jeremiah Dodds
@ 2012-08-19 11:29 ` Achim Gratz
  2012-08-19 12:00   ` Thien-Thi Nguyen
  2012-08-19 12:45   ` Bastien
  2012-08-19 12:06 ` Juanma Barranquero
  2 siblings, 2 replies; 6+ messages in thread
From: Achim Gratz @ 2012-08-19 11:29 UTC (permalink / raw)
  To: emacs-devel

Bastien writes:
> There are many places in *.el elisp files where we have this construct
>
> (cond (...)
>       (...)
>       (t nil))
>
> My understanding is that (t nil) is useless, since the ̀t' condition 
> is only tested if other conditions are `nil'.
>
> What is the purpose of (t nil)?

It's a nice (redundant) reminder that "if none of the other conditions
is true, this form returns nil".

> Can we safely remove it?

I don't know if any checkers rely on it.  I'd expect it is optimized
away when the byte-compiler gets to it anyway, so why would you want to
remove it?


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Wavetables for the Terratec KOMPLEXER:
http://Synth.Stromeko.net/Downloads.html#KomplexerWaves




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

* Re: Usefulness of (t nil) as the last sexp in (cond ...) constructs?
  2012-08-19 11:29 ` Achim Gratz
@ 2012-08-19 12:00   ` Thien-Thi Nguyen
  2012-08-19 12:45   ` Bastien
  1 sibling, 0 replies; 6+ messages in thread
From: Thien-Thi Nguyen @ 2012-08-19 12:00 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 207 bytes --]

() Achim Gratz <Stromeko@nexgo.de>
() Sun, 19 Aug 2012 13:29:52 +0200

   I'd expect it is optimized away when the byte-compiler [...]

Well, no (not yet, until Someone teaches the byte-compiler about it):


[-- Attachment #1.2: cond-t-nil --]
[-- Type: application/x-emacs-lisp, Size: 722 bytes --]

[-- Attachment #1.3: Type: text/plain, Size: 377 bytes --]


-- 
Thien-Thi Nguyen ..................................... GPG key: 4C807502
.                  NB: ttn at glug dot org is not me                   .
.                 (and has not been since 2007 or so)                  .
.                        ACCEPT NO SUBSTITUTES                         .
........... please send technical questions to mailing lists ...........

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: Usefulness of (t nil) as the last sexp in (cond ...) constructs?
  2012-08-19  7:07 Usefulness of (t nil) as the last sexp in (cond ...) constructs? Bastien
  2012-08-19 10:23 ` Jeremiah Dodds
  2012-08-19 11:29 ` Achim Gratz
@ 2012-08-19 12:06 ` Juanma Barranquero
  2 siblings, 0 replies; 6+ messages in thread
From: Juanma Barranquero @ 2012-08-19 12:06 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-devel

On Sun, Aug 19, 2012 at 9:07 AM, Bastien <bzg@altern.org> wrote:

> Can we safely remove it?

Yes.

Should we?

No, IMHO.

    Juanma



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

* Re: Usefulness of (t nil) as the last sexp in (cond ...) constructs?
  2012-08-19 11:29 ` Achim Gratz
  2012-08-19 12:00   ` Thien-Thi Nguyen
@ 2012-08-19 12:45   ` Bastien
  1 sibling, 0 replies; 6+ messages in thread
From: Bastien @ 2012-08-19 12:45 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-devel

Achim Gratz <Stromeko@nexgo.de> writes:

> It's a nice (redundant) reminder that "if none of the other conditions
> is true, this form returns nil".

Okay.  In many cases, this reminder is not useful, as it is obvious from
the code.  I've removed (t nil) in such cases in org-mode git repo.

-- 
 Bastien



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

end of thread, other threads:[~2012-08-19 12:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-19  7:07 Usefulness of (t nil) as the last sexp in (cond ...) constructs? Bastien
2012-08-19 10:23 ` Jeremiah Dodds
2012-08-19 11:29 ` Achim Gratz
2012-08-19 12:00   ` Thien-Thi Nguyen
2012-08-19 12:45   ` Bastien
2012-08-19 12:06 ` Juanma Barranquero

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