[Top][All Lists]

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

Re: (interactive) and &optional

From: Philip Kaludercic
Subject: Re: (interactive) and &optional
Date: Fri, 24 Mar 2023 20:52:23 +0000

Jean Louis <> writes:

> * Dr Rainer Woitok <> [2023-03-23 22:12]:
>> Am I really expected in a function that is both,  callable from Lisp and
>> via "M-x", to code something along the lines of
>>    (cond ((or (null arg) (string-empty-p arg)) 'default-val)
>>          (arg))
>> to check whether or not an optional argument has been passed?  Are there
>> any more elegant ways to achieve this?
> I do not like involving `interactive' at all, so I do the handling by
> providing optional argument and telling function to check for it, or
> ask for it.
> (defun search-something (&optional query)
>   "Search something by using QUERY."
>   (interactive)
>   (let* ((query (or query (read-from-minibuffer "Query: "))))
>     (do-the-search query)))

The issue here is that the function is difficult to re-use from other
scripts.  If the interactive stuff is encapsulated within an
(interactive) form then you avoid the issue.

Philip Kaludercic

reply via email to

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