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

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

Re: Functions with multiple optional arguments


From: Emanuel Berg
Subject: Re: Functions with multiple optional arguments
Date: Mon, 17 Oct 2022 06:18:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Jean Louis wrote:

>> Have been writing a function that has two optional
>> arguments. It is turning out to be a difficult task in
>> situations when one in missing an argument. Anybody has
>> experience about this, as I have not seen much code with
>> multiple optional arguments.
>
> If argument is optional but required by your function, I use
> this method:
>
> (defun my-fun (&optional title description)
>   (let ((title (or title "Best Movie"))
>       (description (or description "Description")))
>     (message "%s: %s" title description)))
>
> (my-fun)

Yes, and to set 'description' (and not 'title') you'd do

  (my-fun nil "Poor movie IMO")

CL has another way, more practical probably, to assign default
values to optional arguments and that can be used in Elisp as
well with `cl-defun' ...

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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