[plt-scheme] syntax to load an SRFI library in MzScheme

From: Daniel Yoo (dyoo at cs.wpi.edu)
Date: Thu Mar 1 16:42:22 EST 2007

On Thu, 1 Mar 2007, Bill Wood wrote:

> On Thu, 2007-03-01 at 16:06 -0500, Jon Zeppieri wrote:
>> (require (lib "13.ss" "srfi"))
> There's also (lib "string.ss" "srfi" "13"), and I am a little unclear as 
> to what the difference is and which is preferred.  Elucidation, anyone?

Hi Bill,

The module (lib "13.ss" "srfi") provides a few symbols that collide with 
mzscheme primitives.  In particular:


So if we're in a module in the 'mzscheme' language, we'll hit an error 
precisely because the module system will detect multiple sources for a 
symbol.  Something like:

     (module foo mzscheme
       (require (lib "13.ss" "srfi"))
       (printf "~s~n" (string-pad "hello" 10)))

will fail because the mzscheme language primitives and the stuff provided 
in 13.ss aren't disjoint.  It's a defensive measure by the module system.

To get around this, there's an alternative module that does everything 
that srfi-13 does, but renames the colliding functions to


so that:

     (module foo mzscheme
       (require (lib "string.ss" "srfi" "13"))
       (printf "~s~n" (string-pad "hello" 10)))

does work.

There are other workarounds: we can use more features of the module 
system, like prefixing the imported symbols with some unique identifier:

     (module foo mzscheme
       (require (prefix str: (lib "13.ss" "srfi")))
       (printf "~s~n" (str:string-pad "hello" 10)))

Another approach is to pull only the stuff we want (which is probably 
better, since it's easier to see where symbols are coming from):

     (module foo mzscheme
       (require (only (lib "13.ss" "srfi") string-pad))
       (printf "~s~n" (string-pad "hello" 10)))

So we've got a lot of options.  The section on Module Bodies in the 
mzscheme reference manual covers the options we can take when we're 
requiring other modules:


Best of wishes!

Posted on the users mailing list.