[plt-scheme] namespace-attach-module

From: Jakub Piotr Cłapa (jpc at pld-linux.org)
Date: Sun Feb 4 17:52:06 EST 2007

I'm trying to load an external file and execute it in the namespace of a 
required module as a means of UI for my simple commandline app.

I'm doing something like this:

(module avrp mzscheme
   (require "avr-isp.scm")


   (with-handlers ([exn:fail:user? (lambda (exn)
                              (send-request 'disconnect)
                              (printf "~A~n" (exn-message exn)))])

     (let ([new-ns (make-namespace)])
       (define (module-path->symbol module-path)
         ((current-module-name-resolver) module-path 'avr-isp #f #f))

       (namespace-attach-module (current-namespace) (module-path->symbol 
"avr-isp.scm") new-ns)
       (parameterize ([current-namespace new-ns])
         (namespace-require '(file "avr-isp.scm"))
         (load "script.avrp")))

And it works (also with different combinations of parameters to the 
resolver or even without the resolver) in

mzscheme -tvm- avrp.scm

When the code gets compiled by

mzc --exe avrp avrp.scm

it raises an exception upon running:

[jpc at ibook-jpc ~/Projects/avr] ./avrp ../spektrometr/linijka/adc_1.hex
Programming: ATmega128
namespace-attach-module: unknown module (in the source namespace): 

  === context ===
#f::352: loop

The alternative (when I remove the last #f in module resolver) is:
namespace-attach-module: module not instantiated (in the source 
namespace): |,/Users/jpc/Projects/avr/avr-isp|

Thanks in advance for any suggestions you may have. :-)

Jakub Piotr Cłapa

Posted on the users mailing list.