[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: sending function arguments to recursive function calls
From: |
Drew Adams |
Subject: |
RE: sending function arguments to recursive function calls |
Date: |
Fri, 17 May 2013 07:31:24 -0700 |
> 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/
- RE: sending function arguments to recursive function calls, (continued)
- RE: sending function arguments to recursive function calls, Drew Adams, 2013/05/04
- Re: sending function arguments to recursive function calls, Gauthier Östervall, 2013/05/07
- RE: sending function arguments to recursive function calls, Drew Adams, 2013/05/07
- Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/08
- Re: sending function arguments to recursive function calls, Gauthier Östervall, 2013/05/09
- Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/09
- Re: sending function arguments to recursive function calls, Gauthier Östervall, 2013/05/12
- Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/13
- Re: sending function arguments to recursive function calls, Gauthier Östervall, 2013/05/17
- Re: sending function arguments to recursive function calls, Dmitry Gutov, 2013/05/17
- RE: sending function arguments to recursive function calls,
Drew Adams <=
- Re: sending function arguments to recursive function calls, Dmitry Gutov, 2013/05/19
- RE: sending function arguments to recursive function calls, Drew Adams, 2013/05/21
- Message not available
- Re: sending function arguments to recursive function calls, Pascal J. Bourguignon, 2013/05/19
- Re: sending function arguments to recursive function calls, Dmitry Gutov, 2013/05/20
- Message not available
- Re: sending function arguments to recursive function calls, Pascal J. Bourguignon, 2013/05/20
- Re: sending function arguments to recursive function calls, Pascal J. Bourguignon, 2013/05/07
- Message not available
- Re: sending function arguments to recursive function calls, Pascal J. Bourguignon, 2013/05/07
- Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/08
Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/04