emacs lisp if function's grammar

Emacs Lisp's “if” function has a annoying form.

One would expect it to take 3 arguments, no more and no less, like this:

(if ‹test›
 ‹expression for true›
 ‹expression for false›
)

But it's actually takes many more args. From the 3rd args onward are all expressions for false. Like this:

(if ‹test›
 ‹expression for true›
 ‹expression for false›
 ‹expression for false 2›
 ‹expression for false 3›
 …
)

Here's a test code you can check:

(if nil
  (message "false")

  (message "true")
  (message "so true")
  (message "yes really")
  )

You can run the code by selecting it, then call “eval-region” 【Alt+x】. You can switch to the “*Messages*” buffer by 【Ctrl+h e】.

Is Common Lisp and Scheme Lisp the same way?

I think i'd prefer the simpler, logical, form: (if test true false).

Popular posts from this blog

Browser User Agent Strings 2012

11 Years of Writing About Emacs

does md5 creates more randomness?