[plt-scheme] Best way to limit/understand what libraries I'm using in DrScheme?

From: Daniel Yoo (dyoo at cs.wpi.edu)
Date: Tue Apr 3 13:45:06 EDT 2007


> Pretty new to Scheme I'm just now learning how MzScheme is structured 
> with its libraries. I would like to understand what libraries I am using 
> in each language level. Or alternately, I would like to specify exactly 
> the libraries I want to use.
>
> Right now I think this means that I would use the language "PLT: Textual 
> MzScheme" and then import any additional libraries I wanted to use.
>
> Is this the right way to use DrScheme?


Hi Grant,

I usually run DrScheme in the "module" language level.  Modules allow us 
to define the base language for the module's contents.  I usually stick 
with "mzscheme", which is the textual mzscheme that you mentioned earlier, 
and then REQUIRE the libraries I want to use.

In the module language level, when we press Run, the module we write in 
the definition window gets invoked, and all the definitions within that 
module are available to us.


One thing about using modules, compared to using Textual mzscheme, is that 
modules disallow namespace collision.  That is, if we run the following in 
the Textual mzscheme language level:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   (require (lib "1.ss" "srfi"))
   (define mylist (reverse! '(hello world)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

no warning shows up.  But if we run the equivalent in the Module language 
level:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(module show-collision mzscheme
   (require (lib "1.ss" "srfi"))
   (define mylist (reverse! '(hello world))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

then we'll get an error at compile time: we find that the 1.ss library 
provides something that's already defined in mzscheme!

We can prefix all the things that 1.ss provides us to disambiguate:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(module show-collision-fixed mzscheme
   (require (prefix list: (lib "1.ss" "srfi")))
   (define mylist (reverse! '(hello world))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

and now this works out ok.  So using modules forces us to be a bit more 
aware of possible namespace collisions.


There's a nice tutorial on the module system here:

    http://www.htus.org/Book/Staging/how-to-use-modules/


And I wrote something a while back while learning the module system; I do 
need to go back and revise it, but it still might be useful for you.

    http://hkn.eecs.berkeley.edu/~dyoo/plt/modules.text


Best of wishes!


Posted on the users mailing list.