Gmail Calendar Documents Web Reader more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Can free variable refers to a lexical environment?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Barry Margolin  
View profile  
 More options Mar 9, 6:21 pm
Newsgroups: gnu.emacs.help
From: Barry Margolin <bar...@alum.mit.edu>
Date: Tue, 09 Mar 2010 13:21:01 -0500
Local: Tues, Mar 9 2010 6:21 pm
Subject: Re: Can free variable refers to a lexical environment?
In article
<180666d9-2ecb-4d99-a419-739650a8f...@c37g2000prb.googlegroups.com>,
 IWAKI Hidekazu <i.hidek...@gmail.com> 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, 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 ***


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google