chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Problem accessing macro from module


From: Abdulaziz Ghuloum
Subject: Re: [Chicken-users] Problem accessing macro from module
Date: Tue, 23 Jan 2007 05:31:45 -0500


On Jan 23, 2007, at 2:28 AM, felix winkelmann wrote:

On 1/22/07, Abdulaziz Ghuloum <address@hidden> wrote:

For compilable macros to work, a few minor changes need to be made to
the psyntax implementation (egg) in chicken. Mainly, the ctem and rtem values need to be set to appropriate values when evaluating in the repl
and when compiling a file. (described in psyntax.ss under
 /Initial mode sets/.)


The problem lies somewhere else: The "load" of "pfn.so" is a run-time
operation - it is evaluated at run-time and the compiler can not (and should not) try to infer compile-time operation (i.e. syntax) from code that only has a
meaning at run-time ("load" might be redefined).
This example works in ikarus because
it is interactive by nature and a in-core compiler (not a batch compiler as
chicken is). There is nothing wrong with the psyntax implementation of
chicken per se. Chicken just follows a different compiler model.

Both ikarus and chez can batch-compile as well (the procedure compile- file does what it's name suggests). In the running scenario, "pfn.scm" can be compiled to the binary file "pfn.so" which contains both the compile- time and run-time bindings of "pfn.scm" (with procedural macros, you need both
anyways).  So, we should load "pfn.so" before compiling "weird.scm" to
"weird.so" (to initialize the compile-time bindings). We also need to load "pfn.so" before loading "weird.so" (to initialize the run-time bindings).

$ cat pfn.scm
(define-syntax fn
  (syntax-rules ()
    ((fn (p ...) body)
     (lambda (p ...) body))
    ((fn name (p ...) body)
     (define (name p ...)
       body))))
(fn hello-world ()
  (display "Hello, world!\n"))

$ cat weird.scm
(hello-world)
(fn goodbye-world ()
  (display "Goodbye, cruel world!\n"))
(goodbye-world)

$ ikarus
> (compile-file "pfn.scm" "pfn.so")
> ^D

$ ikarus pfn.so
> (compile-file "weird.scm" "weird.so")
> ^D

$ ikarus pfn.so weird.so
Hello, world!
Goodbye, cruel world!
> ^D

** I see how this could be hard if you cannot load extensions into
the compiler.  Chicken can load ".so" files at compile time, no? **

Aziz,,,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]