[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
Re: Functions with multiple optional arguments,
Emanuel Berg <=
- Re: Functions with multiple optional arguments, Jean Louis, 2022/10/17
- Re: Functions with multiple optional arguments, Emanuel Berg, 2022/10/18
- Re: Functions with multiple optional arguments, Jean Louis, 2022/10/20
- Re: Functions with multiple optional arguments, Emanuel Berg, 2022/10/22
- Re: Functions with multiple optional arguments, Jean Louis, 2022/10/23
- Re: Functions with multiple optional arguments, Emanuel Berg, 2022/10/24
- Re: Functions with multiple optional arguments, Emanuel Berg, 2022/10/25
Re: Functions with multiple optional arguments, Emanuel Berg, 2022/10/17