Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!herald.usask.ca!alberta!brazeau.ucs.ualberta.ca!unixg.ubc.ca!ubc-cs!uw-beaver!mit-eddie!mintaka!ai-lab!zurich.ai.mit.edu!markf From: markf@zurich.ai.mit.edu (Mark Friedman) Newsgroups: comp.lang.scheme Subject: Re: Simulating Environments with Continuations ? Message-ID: Date: 28 Jun 91 18:08:24 GMT References: <1991Jun27.192117.8609@jato.jpl.nasa.gov> Sender: news@ai.mit.edu Reply-To: markf@zurich.ai.mit.edu Organization: M.I.T. Artificial Intelligence Lab. Lines: 54 In-reply-to: norman@parc.xerox.com's message of 28 Jun 91 16:08:46 GMT In article norman@parc.xerox.com (Norman Adams) writes: Unless your interpreter is very smart, the environment of each instance will include a first class procedure for each method. You're quite right. I was thinking of something like: (define (let () (define ( ) ; reference ivars as free vars ) (define ( ) ; reference ivars as free vars ) ... (define ( [args]) (let (( ) ( ) ...) (define (self msg [args]) (case msg (msg1 ) (msg2 ) ...)) self)) )) which, of course, doesn't work. I think the right approach is to have the compiler support this idiom (or an equivalent one). It is not very hard, just a small twist in your closure analysis. The T compiler does this. But the original author wanted something which would work in a standard Scheme. Originally (before I came up my erroneous claim), I was going to respond to the original author by suggesting a macro (e.g. `WITH-INSTANCE-VARIABLES') which would take a class as an argument and walk over his method code replacing variables references (and settings) with appropriate access (and setting) procedures. In that scheme instance variables would probably become slots in some data structure held in the instance closure. It's hairy, but not unreasonable. Of course macros are not yet standard, but at least the RnRS authors are committed to putting them in R4RS. -Mark -- Mark Friedman MIT Artificial Intelligence Lab 545 Technology Sq. Cambridge, Ma. 02139 markf@zurich.ai.mit.edu