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

[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 10:33:37 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <address@hidden>,
 Emanuel Berg <address@hidden> wrote:

> What do you mean by "additional arguments" tho?
> What I can see (?) the only thing replaced (not
> added) is the let binding, by the
> function name!

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.

(defun foo1 (x)
  (flet ((local-bar (y)
           (+ x y)))
    (local-bar 3)))

(defun foo2 (x)
  (global-bar 3 x))
(defun global-bar (x y)
  (+ x y))

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.

-- 
Barry Margolin, address@hidden
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


reply via email to

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