From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: DynamicBindingVsLexicalBinding Date: Sat, 12 Oct 2013 23:34:51 -0400 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1381635314 10030 80.91.229.3 (13 Oct 2013 03:35:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 13 Oct 2013 03:35:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 13 05:35:19 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VVCSd-0007JN-Gs for geh-help-gnu-emacs@m.gmane.org; Sun, 13 Oct 2013 05:35:19 +0200 Original-Received: from localhost ([::1]:60109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VVCSd-00087G-35 for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Oct 2013 23:35:19 -0400 Original-Path: usenet.stanford.edu!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!barmar.motzarella.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 46 Injection-Info: barmar.motzarella.org; posting-host="2be9e9f5dd9af768b8861af71b85fc28"; logging-data="12502"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19FaBC9WF12QYlc4Vw7Yak3" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:Jt8nm1qE6WWceWKzheXuFUvQCj8= Original-Xref: usenet.stanford.edu gnu.emacs.help:201709 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:93978 Archived-At: In article , Andreas Röhler 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, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***