[plt-scheme] Macros and modules

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Fri Jun 11 06:05:10 EDT 2004

Due to a discussion on modules and macros and the tricky aspects of
separate compilation I decided to write down the goals of the PLT
module system as described in Flatt's "Composable and Compilable
Macros". To demonstrate the problem I wrote a small example that uses
the portable syntax-case, so it will be easy for users of other
compilers than the PLT one to both read and test the code.

The result can be found in

     <http://www.scheme.dk/macros-and-modules.txt>

and the source files in

     <http://www.scheme.dk/macros-and-modules.tar.gz> .


I am trying to make two points:

    1) the problems of separate compilation occur in real life
       situations

    2) the PLT module system provides one solution

Point 1) is nicely demonstrated, but I can't figure out to compile my
program with mzc. I am hoping I am simply using mzc wrongly, but it
is also quite possible my PLT solution is wrong (this is tricky stuff).


The program runs nicely in MzScheme:

   [soegaard at commander plt]$ mzscheme main.scm
   Welcome to MzScheme version 205, Copyright (c) 1995-2003 PLT
   > (require "main.scm")
   3.141592653589793
   1.4142135623730951
   4.555806215962888
   >

But when compile I get this:

   [soegaard at commander plt]$ mzc --exe main main.scm
   MzScheme compiler (mzc) version 205, Copyright (c) 1996-2003 PLT
   [output to "main"]
   [soegaard at commander plt]$ ./main
   reference to undefined identifier: constant

Given "A key feature of the MzScheme module system is that compiling
Metrics [example module] will fail /even when the modules are compiled
in the same session", I had expected this to compile without
problems.

In one particular place in "constants.scm" I wanted to use

   (begin-for-syntax (register-constant 'name
       (eval (expand (syntax-object->datum (syntax exp))))))

but since begin-for-syntax isn't implemted yet, I used this
in stead:

(with-syntax  (((compile-time-register)
                 (generate-temporaries '(compile-time-register))))
   (syntax (define-syntax compile-time-register
             (register-constant 'name
                (eval (expand (syntax-object->datum (syntax exp))))))))))))))

I hope this has the same semantics ?

-- 
Jens Axel Søgaard



Posted on the users mailing list.