[plt-scheme] Confused about requiring and prefixing SRFIs

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Mon Mar 24 21:26:45 EDT 2008

Here I assume you are using v3xx of PLT Scheme.

If you read the "SRFI documents inside PLT" doc from Help Desk (i.e. the main entry of SRFI docs), there is a part "NOTE on SRFIs with name conflicts" (in RED), which says:

Certain SRFIs (currently SRFIs 1, 5, 13, 17, 19, 43, 45, 48, 61, 63, 69 and 87) provide names which conflict with names provided by the 'mzscheme' language. Attempting to require one of these SRFIs in a module written in the 'mzscheme' language will result in an error.
To address this problem, the PLT implementations of these SRFIs provide a different module which renames the problematic exports to avoid these conflicts. For SRFI 1, this library is called list.ss, and should be required like this:
     (require (lib "list.ss" "srfi" "1"))
which supplies the colliding names with a prefix of 's:' (e.g. "s:map", "s:reverse!") and is therefore suitable for requires in a module.
For SRFI 19, this library is called time.ss, and should be required like this:
     (require (lib "time.ss" "srfi" "19"))
which supplies the colliding names with a prefix of 'srfi:' (e.g. "srfi:date?", "srfi:date-second") and is therefore
suitable for requires in a module.

For srfi 13 case, mzscheme already provides string-upcase. So (lib "string.ss" "srfi" "13") provides s:string-upcase (you can also read the source code of SRFI 13 to find out); while (lib "13.ss" "srfi") provides "string-upcase".



Grant Rettke wrote:
> Hi folks,
>
> The recommended approach to requiring SRFIs is to use the approach:
>
>       (require (lib "NAME.ss" "srfi" "N"))
>
> I tried that in a module where I wanted to prefix everything from SRFI
> 13 with 'srfi/13:' so I first tried:
>
>      (require (lib "string.ss" "srfi" "13"))
>
> which works and then changed it to
>
>   

Actually you are using string-upcase from mzscheme in this case.

>      (require (prefix srfi/13: (lib "string.ss" "srfi" "13")))
>
> resulting in the error
>
>      expand: unbound variable in module in: srfi/13:string-upcase
>
>   

Yes. But you can try to use srfi/13:s:string-upcase here.

> So I changed it back to the form of:
>
>      (require (prefix srfi/13: (lib "13.ss" "srfi")))
>
> At which point the prefix works correctly.
>
>   
Yes. That's another way to require (lib "13.ss" "srfi") in a module.

> Why does one form work but not the other? (What am I doing wrong?)
>
> Best wishes,
>
> Grant Rettke
>
>   

Chongkai


Posted on the users mailing list.