help-gnu-emacs
[Top][All Lists]
Advanced

[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: Wed, 02 Aug 2023 19:53:59 +0000

------- Original Message -------
On Thursday, August 3rd, 2023 at 7:24 AM, uzibalqa <uzibalqa@proton.me> wrote:

> Sent with Proton Mail secure email.
> 
> ------- Original Message -------
> On Thursday, August 3rd, 2023 at 6:20 AM, Emanuel Berg incal@dataswamp.org 
> wrote:
> 
> > uzibalqa wrote:
> > 
> > > To be absolutely sure I understand. If I want to default
> > > a function optional argument if it is not used, the command
> > > to that that is
> > > 
> > > (defun dothis x ()
> > > (or x (setq x 8)) ; [...]
> > > (do-something x)
> > > )
> > > 
> > > And this would always work. In will work if I use the
> > > lexical-binding directive at the top of a file. And it would
> > > work if I use dynamic-binding directive at the top of
> > > a file.
> > 
> > Correct, as that wouldn't affect them because function formal
> > parameters (the argument placeholders) are always under
> > lexical/static scope.
> > 
> > > Calling the command (dothis) will always use x with value 8,
> > > and executing (do-something 8) .
> > 
> > Yes, you forgot about the &optional keyword in your example
> > but other than that it is correct.
> 
> 
> Right, it should have been (defun dothis (&optional x)

What had confused me initially was that descriptions customarily 
specified the difference in results between lexical and dynamic
binding.

What I did not immediately realise was that within the context of
function arguments, lexical binding is the default way to handle 
function arguments in Lisp and Emacs Lisp, notwithstanding the file
binding specification.  

Although one has to say that it is also possible to implement 
dynamic binding for function arguments in other languages.  Is 
it possible to impose dynamic binding for function arguments 
in Emacs Lisp though? 

Looks as if dynamic binding in Emacs Lips was affecting global 
variables.  And perhaps function arguments such as lists.




reply via email to

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