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: Can free variable refers to a lexical environment? Date: Tue, 09 Mar 2010 13:21:01 -0500 Organization: A noiseless patient Spider Message-ID: References: <180666d9-2ecb-4d99-a419-739650a8fb3d@c37g2000prb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1272991467 10525 80.91.229.12 (4 May 2010 16:44:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 May 2010 16:44:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 04 18:44:26 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9LEP-0000GK-ST for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 18:44:26 +0200 Original-Received: from localhost ([127.0.0.1]:54793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9LEP-0005it-2I for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 12:44:25 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news-2.dfn.de!news.dfn.de!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!barmar.motzarella.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 45 Injection-Date: Tue, 9 Mar 2010 18:21:01 +0000 (UTC) Injection-Info: barmar.motzarella.org; posting-host="+bxBiZT/p0ZLLuDb5H+JCw"; logging-data="1863"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NIUzORINWx7fqlh3+ztSe" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:CjFLF6XJTorTTOIYRh6xtIxawxM= Original-Xref: usenet.stanford.edu gnu.emacs.help:177419 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:72943 Archived-At: In article <180666d9-2ecb-4d99-a419-739650a8fb3d@c37g2000prb.googlegroups.com>, IWAKI Hidekazu wrote: > Hello, > > I need to make a table factory function in emacs with cl extension. > but I'm scheme user. I'm confusing emacs lisp behavior. > will you please tell me the emacs lisp's free variable issue. > > my table factory function is following code: > (defun mk-table-instance () > (let ((table nil)) ;; create a lexical value `table` > (defun __temp__ (msg &rest value) > ;; some operation changes the lexical variable `table` > (case msg > ((push) (push (car value) table)) > (otherwise table))) > (function __temp__))) > ;; return the `__temp__` procedure with the lexical variable `table` > ;; i.e. return a closure. > > (fset 'table-object (mk-table-instance)) > ;; 'table-object is an unique procedure object. > (table-object 'push 13) > ;; my plan => operate an unique `table` variable which was created by > involving `mk-table-instance` > ;; real => "Debugger entered--Lisp error: (void-variable > table)"!!!!!!! > > I researched this code. I guess the lexical binded variable `table` in > `mk-table-instance` procedure refer to the global environment. > In scheme, the variable refer to the lexical environment. > > How to refer to a lexical environment? Emacs Lisp implements dynamic scoping, not lexical scoping. You can use lexical-let to emulate lexical binding. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***