[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Compilation problem ?
Quoting Mr KING:
> Why mzc don't want to compile to .zo a program like that :
>
> (require-library "synrule.ss")
> (define-syntax $define
> (syntax-rules ()
> (($define nom val) (define nom val))))
The short answer is that mzc isn't good for compiling syntax
definitions. Try `compile-file' instead.
Long answer:
First of all, the fact that syntax extensions and code can be mixed
together is the source of many problems in Scheme. In this case, `mzc'
has no way to know that you mean to load "synrule.ss" at compile time
(to get `define-syntax') rather than at run time.
You could tell mzc to load "synrule.ss" at compile time by using
`begin-elaboration-time':
(begin-elaboration-time
(require-library "synrule.ss"))
(define-syntax $define
(syntax-rules ()
(($define nom val) (define nom val))))
But that may be only half the problem. The `$define' macro could be
used for compiling subsequent expressions in the source file, but it
doesn't stick around in the .zo file. So if your intent was to get a
.zo file that defines `$define', it still won't work.
Instead of using mzc, you could try using `compile-file' directly to
create .zo files. (It's defined by the "compile.ss" library in MzLib.)
`compile-file' accepts many flags to control the way macro definitions
and `require-library' expressions are handled. By default, unlike mzc,
`compile-file' preserves macro definitions in the .zo output.
mzc uses `compile-file' with the flag list '(use-current-namespace
strip-macro-definitions ignore-require-library), which makes it compile
for .zo output in the same way that mzc can compile for .dll/.so
output.
Matthew