[Top][All Lists]

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

Re: optional argument defaults in `cl-defun' vs old way - warning, discr

From: Emanuel Berg
Subject: Re: optional argument defaults in `cl-defun' vs old way - warning, discrepancy!
Date: Sat, 07 Oct 2023 15:01:42 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Adam Porter wrote:

> Yes, this is how CL optional and keyword arguments work.
> See (info "(cl) Argument Lists") and search for "SVAR".
> It does require a bit more diligence in some cases, but it
> also provides more flexibility. And FWIW, I think I actually
> have to check the SVAR something like 1% of the time [...]

Okay, but how does one know when that has to be checked?
Because after writing the `cl-defun', certain use which one
didn't plan for, still cannot be allowed to break it. And if
one has to check SVAR for every cl-defun, I don't see the
advantage with the &optional arg default syntax being big
enough to prefer cl-defun to `defun' for the use case of
optional args.

At least with `defun' and &optional, nil always means the
default has to be used - even if nil was submitted explicitely
by a programmer or a program - or rather, that doesn't exist
as a special case so one doesn't have to care about it.

In practice, with defun, it would me to always check if
&optional args ar set, and if not, set each of them to
a default value. But not having to do that with `cl-defun' is
not a clear advantage anymore, since one sometimes (or
always?) has to check SVAR instead.

Note that this, i.e. having to check for nils with defun,
doesn't mean nil can't be used as the default. It would only
amount to

  (or arg (setq arg nil))

underground experts united

reply via email to

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