From: Heime <heimeborgia@protonmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: [External] : Re: function arguments optional default values
Date: Sat, 06 Jul 2024 21:48:57 +0000 [thread overview]
Message-ID: <B98W4iih2v70x8dvoI345GR1MrAs8ukzyKd5jsWf-3FzSdmh7L4GDDifDOhljWI07y2dk0_vyMDiU7JhW0vM8d0bPelFTArqnaiiUTZXTpE=@protonmail.com> (raw)
In-Reply-To: <jwvjzhya6je.fsf-monnier+emacs@gnu.org>
On Saturday, July 6th, 2024 at 3:55 PM, Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> > > > Does elisp support function arguments optional default values ?
> > > > I solve that problem with following:
> > > > (defun my-function (arg &optional other-arg)
> > > > (let* ((other-arg (or other-arg my-default)))
> > > > other-arg))
> > > > Simpler - no reason for another binding,
> > > > just change the value (it's a local var).
> >
> > (defun my-function (arg &optional other-arg)
> > (setq other-arg (or other-arg my-default))
> > ...)
>
>
> FWIW, assuming you're using `lexical-binding` (which you should), this
> tends to result in less efficient byte-code.
>
> The difference is marginal in most cases (and efficiency of ELisp code
> is irrelevant in most cases as well), but the point is that bindings
> don't "cost" as much as mutation.
Does the mutation occur with 'setq' ? And the binding is about the use of
'let' and 'let*' ? Then using the 'let' version would be preferred, right?
prev parent reply other threads:[~2024-07-06 21:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-03 21:21 function arguments optional default values Heime
2024-07-03 21:51 ` Stephen Berman
2024-07-03 21:56 ` Heime
2024-07-03 22:04 ` Stephen Berman
2024-07-03 22:24 ` Stephen Berman
2024-07-06 12:43 ` Jean Louis
2024-07-06 15:03 ` [External] : " Drew Adams
2024-07-06 15:55 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-07-06 16:06 ` Drew Adams
2024-07-06 19:04 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-07-06 21:48 ` Heime [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='B98W4iih2v70x8dvoI345GR1MrAs8ukzyKd5jsWf-3FzSdmh7L4GDDifDOhljWI07y2dk0_vyMDiU7JhW0vM8d0bPelFTArqnaiiUTZXTpE=@protonmail.com' \
--to=heimeborgia@protonmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).