[plt-scheme] Evaluation in local environment?

From: dsj22 (dsj22 at nau.edu)
Date: Wed Apr 2 17:23:43 EDT 2008

Well, in that sense, I was referring to the object itself (which is actually a 
function that checks the first argument - a "method name" - against a list of 
possibilities and carries out the appropriate actions), since allowing 
functions to be recursive meant allowing the object to be recursive, which 
meant giving the object a label. The "new" function turns the class definition 
into a function and returns it, rather than defining it with a label (so 
proper sytanx is "(define foo (new point '8 '3))" for a point at (8,3). So my 
thinking was, since I'm returning this function and not defining it 
immediately, and it must be able to have several instances exisiting 
simultaneously, I can't assign a label to it at creation (if I defined 
anything, it would be global, and so every instance trying to recurse would 
refer to the same function name).
The reason I felt silly is that I'm already using let to create locally-bound 
variables, which can have the same name but exist in different instances. I 
just needed to use the same technique - just with a letrec (made for exactly 
this purpose) instead of let.
Because the syntax for reccursion is "(*this* <methodname> <argument>)", all I 
had to do was define the function I'd return like so:
(letrec ((*this* (lambda msg (<object function>)))

The syntax to recurse by calling *this* works naturally, and the only contents 
of the letrec is to return the function that *this* was bound to - which can 
then be bound to anything else after returned by (new). The real trick, of 
course, is that new is given the object definition and uses quasi-quoting to 
construct the nested let statements, then evals the whole thing.
I know my professor does this assignment annually, so I don't want to post my 
whole program, but I hope that sates your curiosity.

>===== Original Message From "Grant Rettke" <grettke at acm.org> =====
>On Tue, Apr 1, 2008 at 8:23 AM, dsj22 <dsj22 at nau.edu> wrote:
>>  Mostly, thanks for asking me "Why can't you give it a label?" - that got 
>>  going (after making me feel stupid for trying to provide an answer).
>I'm interested in your solution for OO. In regards to that, what does
>that mean "provide a label"? For the class functions?

Posted on the users mailing list.