Re: cond-expand and import

Matthias Radestock <[email protected]>
Newsgroups gmane.comp.java.sisc.user
Message-ID <[email protected]>
Dan,

Dan <[email protected]> writes:

> the (module) and (import) macros, or whatever they
> are, have never ceased to surprise me, with issues
> ranging from compilation problems to (define-macro)
> behavior inside a module.

We are waiting for the R6RS module system to rescue us.

> netcafe:~# cat >x.scm
> (module x (f)
>   (define (f x) x)
> )
>
> netcafe:~# sisc
> SISC (1.13.7)
> #;> (cond-expand (sisc (require-library 'x) (import
> x)))
> Error: import from unknown module x
>
> However,
>
> netcafe:~# sisc
> SISC (1.13.7)
> #;> (cond-expand (sisc (require-library 'x)))
> (x)
> #;> (cond-expand (sisc (import  x)))
> #;> f
> #<procedure |@x::f|>

require-library is a *function* that when *evaluated* loads the
specified library. By contrast, import is a *macro* that when *expanded*
makes the specified module bindings available. Therefore it is not
surprising that the first example doesn't work because at the time the
import happens - which is macro expansion time - the library has not
been loaded yet.

> #;> (define-syntax reqimp (syntax-rules ()
> ((_ lib)
> (begin (require-library 'lib) (import lib)))))
> #;> (reqimp x)
> Error: import from unknown module x
>
> does not work.

require-extension does the above and gets it right, e.g.

   (cond-expand (sisc (require-extension (srfi 1))))

works just fine. If you look at the implementation of require-extension
you'll see that it calls require-library at macro expansion time.


Matthias.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.