[plt-scheme] (require... ) expanded from a macro

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sat Oct 21 09:52:44 EDT 2006

Dan Muresan skrev:
> Hi,
> 
> I'm trying to port some of my software to PLT. I thought I could
> emulate SRFI-55 using
> 
> (define-syntax require-extension
>  (lambda (stx)
>    (syntax-case stx (srfi)
>      ((_ (srfi n))
>       (with-syntax ((nstr (string-append
>                                        (number->string
>                                         (syntax-object->datum (syntax
> n))) ".ss")))
>         (syntax (require (lib nstr "srfi"))))))))

Due to hygiene

   If a macro transformer inserts a binding for an identifier (variable
   or keyword), the identifier will in effect be renamed throughout its
   scope to avoid conflicts with other identifiers.

the names bound by the require are renamed.

To break hygiene use syntax-local-introduce:

   (define-syntax (require-extension stx)
     (syntax-case stx (srfi)
       ((_ (srfi n))
        (number? (syntax-e #'n))
        (let ([n (syntax-e #'n)])
          (with-syntax ([name (format "~a.ss" n)])
            (syntax-local-introduce
             #'(require (lib name "srfi"))))))))

   (require-extension (srfi 1))
   every

 > Aside from the surprising decision to exclude SRFI-0 and SRFI-55 from
 > PLT, why does this not work?


SRFI-55 is the new kid on the block.

   <http://srfi.schemers.org/srfi-55/mail-archive/msg00058.html>
   <http://srfi.schemers.org/srfi-55/mail-archive/msg00006.html>

SRFI-0 is only a partial solution.

    <http://srfi.schemers.org/srfi-0/mail-archive/msg00032.html>

Consider the module system in R6RS as an answer to these problems.

-- 
Jens Axel Søgaard



Posted on the users mailing list.