[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing optional arguments for use with internal functions
From: |
uzibalqa |
Subject: |
Re: Passing optional arguments for use with internal functions |
Date: |
Sun, 30 Jul 2023 16:09:14 +0000 |
------- Original Message -------
On Saturday, July 29th, 2023 at 5:11 AM, Emanuel Berg <incal@dataswamp.org>
wrote:
> Heime wrote:
>
> > > Optional arguments defaults to nil, if that is an
> > > acceptable value you can use it as you do, if not you can
> > > check if it is nil first thing in the function and if it
> > > is, set it to something that works, e.g.
> > >
> > > (or arg (setq arg 0))
> >
> > Does the condition you specified work whether the binding is
> > lexical or dynamic ?
>
>
> If there is an optional argument with that name yes, since
> formal parameters (function arguments) are always lexical.
Yes, I am discussing (or arg (setq arg 0)) in the context of
an optional argument by that name, for the purpose of setting
a default if it was not specified.
> ;;; -- lexical-binding: nil --
>
> (defvar arg)
> (setq arg 2)
>
> (defun echo-arg (&optional arg)
> (or arg (setq arg 1))
> (message "%s" arg) )
>
> ;; (echo-arg)
>
> This will still echo 1.
Now that there has been a change from dynamic to lexical binding,
this becomes a problem. What command should one use to set a default
value to an optional argument for the current lexical binding files ?
> --
> underground experts united
> https://dataswamp.org/~incal