From: "Drew Adams" <drew.adams@oracle.com>
To: "'Dmitry Gutov'" <dgutov@yandex.ru>,
"'Gauthier Östervall'" <gauthier@ostervall.se>
Cc: help-gnu-emacs@gnu.org, 'Stefan Monnier' <monnier@iro.umontreal.ca>
Subject: RE: sending function arguments to recursive function calls
Date: Fri, 17 May 2013 07:31:24 -0700 [thread overview]
Message-ID: <2AC6E6871319483CABA0387DEF8B39CC@us.oracle.com> (raw)
In-Reply-To: <87mwrt7py6.fsf@yandex.ru>
> This is the ugly side of dynamic scoping.
> (defun foo () (let ((bar 42)) (baz)))
> (defun baz () bar)
> (foo) ; => 42
> baz ; => void-variable error
Huh? I guess you meant to write
(baz) ; => "void-variable bar" error
There is nothing ugly about that behavior.
The `let' binds variable `bar' for the dynamic extent of the call to `foo'.
There is no other binding of `bar' or assignment to it here, so `(baz)' refers
to an unbound variable `bar'.
What happens with lexical scoping?
(foo) ; => "void-variable bar" error
(baz) ; => "void-variable bar" error
Which is also not ugly and not unusual. There is no binding of `bar' lexically
visible in `baz'.
Dynamic and lexical binding are very different. That's all. Each has its
advantages.
Lexical binding is generally cleaner (correct for funargs etc.), so it is
simpler to understand (WYSIWYG, where the `S' is all about lexical scope). As
such, it can often allow compilation to more efficient code. And it can
facilitate program proving and transformation, but mainly for "pure"
(referentially transparent) languages, not full Lisp.
Dynamic binding facilitates user extension ("monkey patching"). And yes, this
is particularly important for a dynamic user environment like Emacs.
It is easy to find references lauding the benefits of lexical binding (most
languages use only lexical binding). Stallman explains well why dynamic binding
is important for Emacs:
http://www.gnu.org/software/emacs/emacs-paper.html#SEC17.
--
Some other background/discussion:
http://www.emacswiki.org/emacs/DynamicBindingVsLexicalBinding
http://en.wikipedia.org/wiki/Static_scoping#Dynamic_scoping
http://stackoverflow.com/questions/321000/what-are-the-advantages-of-dynamic-sco
ping
http://stackoverflow.com/questions/2979428/uses-for-dynamic-scope
http://c2.com/cgi/wiki?DynamicScoping
http://academic.udayton.edu/saverioperugini/courses/cps343/lecture_notes/scope.h
tml
http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node43.html
http://www.codinghorror.com/blog/2008/07/monkeypatching-for-humans.html
http://devblog.avdi.org/2008/02/23/why-monkeypatching-is-destroying-ruby/
next prev parent reply other threads:[~2013-05-17 14:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-04 13:01 sending function arguments to recursive function calls Gauthier Östervall
2013-05-04 15:30 ` Drew Adams
2013-05-07 11:25 ` Gauthier Östervall
2013-05-07 14:04 ` Drew Adams
2013-05-08 12:21 ` Stefan Monnier
2013-05-09 8:35 ` Gauthier Östervall
2013-05-09 12:23 ` Stefan Monnier
2013-05-12 13:19 ` Gauthier Östervall
2013-05-13 14:55 ` Stefan Monnier
2013-05-17 12:20 ` Gauthier Östervall
2013-05-17 12:26 ` Dmitry Gutov
2013-05-17 14:31 ` Drew Adams [this message]
2013-05-19 16:57 ` Dmitry Gutov
2013-05-21 16:34 ` Drew Adams
[not found] ` <mailman.70.1368982677.22516.help-gnu-emacs@gnu.org>
2013-05-19 20:59 ` Pascal J. Bourguignon
2013-05-20 19:31 ` Dmitry Gutov
[not found] ` <mailman.94.1369078320.22516.help-gnu-emacs@gnu.org>
2013-05-20 19:55 ` Pascal J. Bourguignon
2013-05-07 14:32 ` Pascal J. Bourguignon
[not found] ` <mailman.25279.1367935468.855.help-gnu-emacs@gnu.org>
2013-05-07 14:55 ` Pascal J. Bourguignon
2013-05-08 12:25 ` Stefan Monnier
2013-05-05 1:22 ` Stefan Monnier
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=2AC6E6871319483CABA0387DEF8B39CC@us.oracle.com \
--to=drew.adams@oracle.com \
--cc=dgutov@yandex.ru \
--cc=gauthier@ostervall.se \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).