[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

passing local bindings to eval'ed forms



Hello,

This is my first post to the list, so I wish to thank the mzscheme
development team for his great job...

I'm currently trying to eval a form which is using local bindings. Let
say I try to do something like:

	(display (let ([val "hello"])
		      (eval 'val)))
	==> reference to undefined identifier: val

I know it is not possible because of lexical scoping, so I wrote the
following macro:
	
	(define-syntax dynamic-let
	  (syntax-rules ()
	    ([_ ([symbol binding] ...) body ...]
	     (let ([symbol binding] ...)
	       (parameterize ([current-namespace (make-namespace)])
		 (namespace-variable-binding 'symbol symbol) ...
		 body ...)))))

Now, executing:

	(display (dynamic-let ([val "hello"])
			      (eval 'val)))
	==> hello

which is actually what I expected...

So my question is: is this correct ? And is there a more "portable" way
to achieve the same goal (assuming that namespaces are mzscheme
specific...) ?

TIA.
-- 
Philippe Giacinti
mailto:Philippe.Giacinti@sxb.bsf.alcatel.fr