From: "Kai Großjohann" <kai.grossjohann@gmx.net>
To: help-gnu-emacs@gnu.org
Cc: "help-gnu-emacs@gnu.org List" <help-gnu-emacs@gnu.org>
Subject: Re: DynamicBindingVsLexicalBinding
Date: Sun, 13 Oct 2013 15:46:19 +0200 [thread overview]
Message-ID: <525AA42B.6030006@gmx.net> (raw)
In-Reply-To: <525A51BD.5040903@easy-emacs.de>
Andreas Röhler wrote:
>
> That's interesting, but can hand-over functions also with dynamic binding.
>
> Do you have a real use-case where lexical-binding is superior?
>
> Can't see goodies from lexical binding beside a simplification for the
> compiler.
I think the key benefit is that lexical binding allows you to support
closures, and with closures you can do cool things.
In Node.js, you need to use closures for everything, due to its
programming model. For example, when you query a DB in Node.js, you
call a function passing it the query and another function to process the
results: queryDb(sql, callback);
Here, it is incredibly useful for "callback" to have access to local
variables at the point where queryDb is called. (I mean variables that
are local to where queryDb is called.)
Some GUI frameworks allow you to specify a function to be called when
the user presses a button, and here, too, it's nice for the function to
have access to local variables from where the button was created.
In Emacs, you write functions to be called when the user presses a key,
and here the solution is that all the variables that the function needs
are buffer-local.
Of course, with dynamic binding you can do other cool things (you can
let-bind a variable, then call a function which calls a function which
calls yet other functions, and the innermost function will reference the
value you just bound -- so you can pass parameters around without
actually having to mention them on every function call). So each of the
styles has their own advantage.
I find that the idea that variables declared specially (e.g. with
defvar) can be dynamically bound whereas everything else is lexically
bound by default -- this idea is quite useful. For if you want to
dynamically bind something to influence another function, you need to
know which variables that other function uses -- and defvar is a good
way to document this.
Kai
next prev parent reply other threads:[~2013-10-13 13:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-12 17:56 DynamicBindingVsLexicalBinding Andreas Röhler
2013-10-12 18:35 ` DynamicBindingVsLexicalBinding Dmitry Gutov
2013-10-12 20:53 ` DynamicBindingVsLexicalBinding Drew Adams
2013-10-13 5:09 ` DynamicBindingVsLexicalBinding Thien-Thi Nguyen
2013-10-13 7:54 ` DynamicBindingVsLexicalBinding Andreas Röhler
2013-10-13 13:46 ` Kai Großjohann [this message]
2013-10-13 16:21 ` DynamicBindingVsLexicalBinding Drew Adams
2013-10-14 11:21 ` DynamicBindingVsLexicalBinding Phillip Lord
2013-10-14 13:45 ` DynamicBindingVsLexicalBinding Drew Adams
2013-10-14 16:05 ` DynamicBindingVsLexicalBinding Phillip Lord
2013-10-14 21:32 ` DynamicBindingVsLexicalBinding Kai Großjohann
2013-10-15 11:27 ` DynamicBindingVsLexicalBinding Phillip Lord
2013-10-15 20:43 ` DynamicBindingVsLexicalBinding Kai Großjohann
2013-10-16 12:57 ` DynamicBindingVsLexicalBinding Phillip Lord
[not found] ` <mailman.4127.1381928277.10748.help-gnu-emacs@gnu.org>
2013-10-16 14:26 ` DynamicBindingVsLexicalBinding Barry Margolin
[not found] ` <mailman.3929.1381681317.10748.help-gnu-emacs@gnu.org>
2013-10-14 11:27 ` DynamicBindingVsLexicalBinding Rustom Mody
2013-10-14 11:15 ` DynamicBindingVsLexicalBinding Phillip Lord
[not found] <mailman.3891.1381600459.10748.help-gnu-emacs@gnu.org>
2013-10-13 3:34 ` DynamicBindingVsLexicalBinding Barry Margolin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=525AA42B.6030006@gmx.net \
--to=kai.grossjohann@gmx.net \
--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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.