unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: Defining functions within functions?
Date: Tue, 24 May 2016 09:13:41 +0200	[thread overview]
Message-ID: <864m9oj5cq.fsf@student.uu.se> (raw)
In-Reply-To: mailman.141.1464034180.1216.help-gnu-emacs@gnu.org

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 -                   


  parent reply	other threads:[~2016-05-24  7:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-23  5:13 Defining functions within functions? Marcin Borkowski
2016-05-23  5:34 ` Eric Abrahamsen
2016-05-24 21:28   ` Marcin Borkowski
2016-05-23 20:09 ` Michael Heerdegen
2016-05-24 21:31   ` Marcin Borkowski
2016-05-24 21:56     ` Drew Adams
2016-05-24 22:10       ` Carlos Konstanski
2016-05-25  6:21         ` Marcin Borkowski
     [not found]       ` <mailman.224.1464127813.1216.help-gnu-emacs@gnu.org>
2016-05-24 22:21         ` Emanuel Berg
2016-05-25  6:20       ` Marcin Borkowski
2016-05-25  8:36         ` Stefan Monnier
2016-05-25  8:43           ` Nicolas Petton
2016-05-25 19:30             ` Marcin Borkowski
2016-05-25  9:07           ` tomas
2016-05-25 15:41             ` Marcin Borkowski
2016-05-25 14:18         ` Drew Adams
2016-05-25 15:39           ` Marcin Borkowski
     [not found]           ` <mailman.255.1464190813.1216.help-gnu-emacs@gnu.org>
2016-05-26  7:52             ` Emanuel Berg
     [not found]     ` <mailman.223.1464127012.1216.help-gnu-emacs@gnu.org>
2016-05-24 22:17       ` Emanuel Berg
     [not found]   ` <mailman.222.1464125502.1216.help-gnu-emacs@gnu.org>
2016-05-24 21:46     ` Emanuel Berg
     [not found] ` <mailman.141.1464034180.1216.help-gnu-emacs@gnu.org>
2016-05-24  7:13   ` Emanuel Berg [this message]
2016-05-24 14:33     ` Barry Margolin
2016-05-24 15:43       ` Emanuel Berg
2016-05-24 16:15         ` Barry Margolin
2016-05-24 21:36           ` Emanuel Berg
     [not found] <mailman.94.1463980455.1216.help-gnu-emacs@gnu.org>
2016-05-23  7:47 ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=864m9oj5cq.fsf@student.uu.se \
    --to=embe8573@student.uu.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).