[plt-scheme] Problems with dynamic-require and eval

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Nov 2 11:32:56 EST 2005

Matthew Flatt wrote:
> At Wed, 02 Nov 2005 16:37:36 +0100, Jens Axel Søgaard wrote:
> 
>>The documentation for dynamic-require states that
>>the the name is imported into the current namespace,
> 
> 
> The docs for `namespace-require' say that, but I don't see what you're
> seeing in the `dynamic-require' docs. Maybe you can quote the
> misleading part, so I know what to fix?

It's section 5.5 in the MzScheme language manual:

   5.5  Dynamic Module Access

   (dynamic-require module-path-v provided-symbol) dynamically invokes
   the module specified by module-path-v in the current namespace's
   registry if it is not yet invoked. If module-path-v is not a symbol,
   the current module name resolver may load a module declaration to
   resolve it. For example, the default module-name resolver accepts a
   path value as module-path-v. The path is not resolved with respect to
   any other module, even if the current namespace corresponds to a
   module body.

   If provided-symbol is #f, then the result is void. Otherwise, when
   provided-symbol is a symbol, the value of the module's export with the
    given name is returned. If the module has no such exported variable
   or if the variable is protected (see section 9.4), the
   exn:fail:contract exception is raised. The expansion-time portion of
   the module is not executed.

Ah! I am supposed insert the returned value into the namespace my self:

   > (let ((n (make-namespace)))
       (parameterize ([current-namespace n])
         (namespace-set-variable-value!
            'mergesort (dynamic-require '(lib "list.ss") 'mergesort))
       (eval '(mergesort (list 1 2) <))))
   (1 2)

What I didn't get initially, was that

   (dynamic-require module-path-v provided-symbol) dynamically invokes
   the module specified by module-path-v in the current namespace's
   registry if it is not yet invoked.

means that the module name is bound in the current namespace - and
nothing more. For some peculiar reason I thought the provided name
would be available in the current namespace as well.

-- 
Jens Axel Søgaard,
a little less confused




Posted on the users mailing list.