[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Defining functions within functions?
From: |
Barry Margolin |
Subject: |
Re: Defining functions within functions? |
Date: |
Tue, 24 May 2016 12:15:18 -0400 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article <864m9nihrn.fsf@student.uu.se>,
Emanuel Berg <embe8573@student.uu.se> wrote:
> Barry Margolin <barmar@alum.mit.edu> writes:
>
> > If you have a local function, it can access
> > variables in the calling function directly.
> > If you move it out to a top-level function,
> > you have to pass those variables
> > as arguments.
>
> Right, I didn't think of that but actually it
> is even more confusing.
>
> It is more clear to call the function at top
> level, and pass it all it needs to do its job.
>
> > And if the function being called needs to
> > reassign the variable, you need to do that in
> > the caller if you use a top-level function.
>
> "reassign the variable"?
(defun foo-local (a)
(flet ((bar ()
(incf a)))
(bar))
a)
vs.
(defun foo-global (a)
(setq a (bar a))
a)
(defun bar (a)
(+1 a))
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
- Re: Defining functions within functions?, Emanuel Berg, 2016/06/02
- Re: Defining functions within functions?, Emanuel Berg, 2016/06/02
- Re: Defining functions within functions?, Emanuel Berg, 2016/06/02
- Re: Defining functions within functions?, Emanuel Berg, 2016/06/02
- Re: Defining functions within functions?, Emanuel Berg, 2016/06/02
- Re: Defining functions within functions?, Emanuel Berg, 2016/06/02