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: Emanuel Berg
Subject: Re: Defining functions within functions?
Date: Tue, 24 May 2016 09:13:41 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de>
writes:

> Personally, I use `let' with lambdas most of
> the time for local function definitions.
> When things get too complicated (seems you
> are at that point), instead of using lexical
> closures as local functions, you can use
> top-level defuns accepting additional
> arguments, or higher-level functions (also as
> top-level defuns) that take the essential
> values as arguments and return a closure.

Here is some terminology to wade thru - let's
see if I get it right:

"lexical closures as local functions" are the
same as `let' and lambdas with the lexical
scope enabled, which is the same as what is
normally thought of as local functions,
invisible and unavailable from anywhere else
but from within the function where they are
defined...

"top-level defuns" are normal defuns as they is
only one level in Elisp. (By the way, this is
the reason for the elaborate, prefixed naming
conventions, some-package-yada-yada-do-it, and
the like.)

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!

"higher-level functions" aren't at the level of
the long-lost High Ones, but on the same level
as the mere "top-level" Wolfrider defuns,
because "higher-level" refers to those function
accepting functions as arguments, as they are
not on any other level scope-wise than
the defuns.

What do you mean "return a closure" tho?
A closure is an association between a function
and its scope - but higher-level functions can
just as well return a normal value, e.g.

    (defun eat-list (operator &rest args)
      (apply operator args) )

    (eat-list '+ 1 2 3 4) ; 10
    (eat-list '* 1 2 3)   ; 6
    (eat-list '+)         ; 0 <-- cool, btw
    (eat-list '*)         ; 1 <--

Perhaps if you provide an example, it'll be
easier grasp the "scope" of it :)

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 40 Blogomatic articles -                   


reply via email to

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