[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Defining functions within functions?

From: Drew Adams
Subject: RE: Defining functions within functions?
Date: Wed, 25 May 2016 07:18:10 -0700 (PDT)

> > A suggestion: Post a concrete example of what you need, and
> > see what concrete suggestions you get.
> >
> > Typically, this stuff is not complicated.  The first thing
> > to do, IMO, is to determine whether you really need/want to
> > do something special/complicated.  Why do you think you want
> > a nested defun or other form of local function definition?
> The reason is simple: I have this long, almost 60-lines function, with
> three levels of lambdas nested.  (I'm using request.el, and I have to
> make two requests sequentially, so I have a callback inside a callback.
> I could probably use deferred or something, this is one of the ideas.)
> It's just pretty complicated, and changing anything in this code is
> a headache.  Also, edebugging is simpler with separate instrumentable
> defuns.

I repeat the suggestion above, in case it helps: _concrete_ example.

And preferably try to show the problem using a simplified version of
your code (maybe 60 lines of code is not needed to point out your
problem(s)/question).  Show just what you need to show to indicate
the problem/question.

My guess is that you might get more help in this way than with only
an abstract characterization of what you think you need, or an
abstract description of the problem or of your code.  Maybe
continuation-passing is really the best approach in your case; but
maybe it is not (needed)...

You can do lots of things with Emacs Lisp that the language is not
necessarily best designed for.  Emacs Lisp is not Scheme or Haskell,
even if you can (sort of) fake doing some of what you do all the
time with such languages.  Over time, Elisp has gotten a little
closer (e.g. closures/lexical binding in general, better compiling),
but it is still quite a different beast.

And though it is hard (for me) to consider your question at only
an abstract level, that does not mean that it won't help _you_
to look at it abstractly.

Finally (in case it helps), when I see an Emacs-Lisp question
"Defining functions within functions?", I wonder first whether it
might be an X-Y question/problem: asking about a tried solution
when the more useful question might be about the problem you are
trying to solve.  It is not super common in Emacs Lisp to define
functions within other function definitions.  My first (admittedly
reflex) question is whether that is really what you need/want.

Just a suggestion.

reply via email to

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