Hi,

Patrick Bernaud <patri...@chez.com> writes:

> -%<---- when.scm ----%<-
> (define-macro (when cond exp . rest)
>   `(if ,cond
>        (begin ,exp . ,rest)))
> -%<---- when.scm ----%<-
>
> -%<---- test.scm ----%<-
> (load "when.scm")
> (when #t (display "Launching missiles!\n"))
> -%<---- test.scm ----%<-

[...]

> ERROR: In procedure catch-closure:
> ERROR: Wrong type to apply: #<syntax-transformer when>

This is because ‘when’ wasn’t expanded in ‘test.scm’, because its
definition wasn’t visible at the time ‘test.scm’ was compiled (remember
that ‘load’ is something that happens at run time.)

Thus the compiler assumed that ‘when’ is a global variable, leading to
the error above (compiling ‘test.scm’ with ‘guile-tools compile
-Wunbound-variable’ should have given a warning.)

The solution is to get rid of ‘load’: either use ‘(include "when.scm")’,
or turn ‘when.scm’ into a module and use it in ‘test.scm’.

Thanks,
Ludo’.


Reply via email to