If I have an optional function argument, how can I determine if name has been supplied. And if it has been supplied, how can I test its validity (not nil or not empty string).

    (defun myfunc (&optional name)
      (if name

Does the if statement only check for name being nil?

2 Answers 2


Does the if statement only check for [its first arg] being nil?


And you can just ask Emacs: C-h f if.

if is a special form in C source code.


If COND yields non-nil, do THEN, else do ELSE...

Returns the value of THEN or the value of the last of the ELSE's.

THEN must be one expression, but ELSE... can be zero or more expressions.

If COND yields nil, and there are no ELSE's, the value is nil.


if switches on nil or non-nil so something like

(if (and name (not string-empty-p name))

will do the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.