[plt-scheme] Difference between 'send' and 'send' in an eval?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 28 12:01:46 EDT 2003

At Wed, 23 Apr 2003 22:01:05 -0400 (EDT), Sarino Suon wrote:
> Why does "(send obj method)" within an eval fail when it works fine
> outside of it, though they refer to the same object?
> 
> I'm guessing that the two environments have different transformer
> environments. Is this right? If so, how do I make the namespace's
> transformer environment the same as that outside of it?

It's not the transformer environments, exactly. Probably your two
namespaces have different instances of '(lib "class.ss")', so there are
two different notions of "object".

The solution is to use `namespace-attach-module' to attach an existing
instance of '(lib "class.ss")' to a newly created namespace, something
like this:

(define (make-namespace-with-class)
    (let ([orig (current-namespace)]
	  [mod-name ((current-module-name-resolver)
		      '(lib "class.ss") #f #f)]
	  [ns (make-namespace 'initial)])
      (parameterize ([current-namespace ns])
	(namespace-attach-module orig mod-name)
      ns)))

Matthew



Posted on the users mailing list.