From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: IWAKI Hidekazu Newsgroups: gmane.emacs.help Subject: Re: Can free variable refers to a lexical environment? Date: Tue, 9 Mar 2010 20:47:52 -0800 (PST) Organization: http://groups.google.com Message-ID: <2cd62b37-0bf3-4be8-af40-7af7be815758@f17g2000prh.googlegroups.com> References: <180666d9-2ecb-4d99-a419-739650a8fb3d@c37g2000prb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1273053814 18895 80.91.229.12 (5 May 2010 10:03:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 5 May 2010 10:03:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 05 12:03:33 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 1O9bS0-00064o-HD for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 12:03:32 +0200 Original-Received: from localhost ([127.0.0.1]:42783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9bRz-00035d-Vi for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 06:03:32 -0400 Original-Path: usenet.stanford.edu!postnews.google.com!f17g2000prh.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 60 Original-NNTP-Posting-Host: 61.44.209.236 Original-X-Trace: posting.google.com 1268196472 7801 127.0.0.1 (10 Mar 2010 04:47:52 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 10 Mar 2010 04:47:52 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f17g2000prh.googlegroups.com; posting-host=61.44.209.236; posting-account=iUZ-UQoAAABBomqNC7xoL4MG0peobLpM User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.2 Safari/533.2, gzip(gfe), gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:177423 X-Mailman-Approved-At: Tue, 04 May 2010 16:45:53 -0400 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:73340 Archived-At: On Mar 10, 3:21=A0am, Barry Margolin wrote: > In article > <180666d9-2ecb-4d99-a419-739650a8f...@c37g2000prb.googlegroups.com>, > =A0IWAKI 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: > > =A0(defun mk-table-instance () > > =A0 (let ((table nil)) ;; create a lexical value `table` > > =A0 =A0 (defun __temp__ (msg &rest value) > > =A0 =A0 =A0 ;; some operation changes the lexical variable `table` > > =A0 =A0 =A0 (case msg > > =A0 =A0((push) (push (car value) table)) > > =A0 =A0(otherwise table))) > > =A0 =A0 (function __temp__))) > > ;; return the `__temp__` =A0procedure 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 =3D> operate an unique `table` variable which was created by > > involving `mk-table-instance` > > ;; real =A0 =A0 =A0 =A0=3D> "Debugger entered--Lisp error: (void-variab= le > > 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, bar...@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 *** Oh, it's just nice. I can use lexical binding in elisp programs. I've tried some, this macro can not solve labeled procedures("defun"ed procedures), but only no labeled procedures (lambda expressions). I'll rewrite my programs in the match style. thank you for your advice.