help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: DynamicBindingVsLexicalBinding


From: Barry Margolin
Subject: Re: DynamicBindingVsLexicalBinding
Date: Sat, 12 Oct 2013 23:34:51 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <address@hidden>,
 Andreas Röhler <address@hidden> wrote:

> Hi,
> 
> in article
> 
> http://www.emacswiki.org/emacs/DynamicBindingVsLexicalBinding
> 
> it's said WRT lexical binding
> 
> "Because it's (1) much easier for the user [that is, programmer], because
> it eliminates the problem of which variables lambda-expressions use
> (when they attempt to use variables from their surrounding context)"
> 
> Unfortunately couldn't find a use-case where it is easier - while consenting 
> it might be easier for the compiler to swallow.
> 
> Could someone give an example, where lexical binding makes coding easier?
> 
> TIA,
> 
> Andreas

Here's one of the canonical examples:

(let ((i 'foo))
  (mapcar #'(lambda (x) (list i x))
          some-list))

Now suppose this were the definition of mapcar (I'm simplifying it to 
take just one list argument):

(defun mapcar (function list)
  (let ((result nil))
    (dolist (i list)
      (push result (funcall function i)))
    (nreverse result)))

Notice that mapcar also uses a variable "i". In a dynamically-scoped 
Lisp, this would shadow the variable in the above code.

-- 
Barry Margolin, address@hidden
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


reply via email to

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