help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function passing flag


From: Corwin Brust
Subject: Re: Function passing flag
Date: Tue, 8 Mar 2022 14:09:51 -0600

On Tue, Mar 8, 2022 at 1:36 PM goncholden <goncholden@protonmail.com> wrote:
>
> How does one do it with an optional argument?  Where can I read about this?
>

A function with an optional argument ARG might look like this:

(defun my:own-fun (&optional arg)
  "Do something. When ARG is non-nil do it a lot."
  (if arg
      ;; when ARG is true we run this
      (do-stuff)
    ;; else we run this
    (do-more-or-different-stuff)))

Note, if you are defining a command (a function you will bind to a key
or otherwise use interactively), you will want to to use
(interactive), usually placed at the start of the function definition,
so just after the docstring.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]