Matt Wette <[email protected]> writes:

> When a module is compiled to generate a .go file is it possible to know 
> (predict) what will be evaluated?
>
> For example
>
> (define-module (foo) #:export (bar))
>
> (define bar (+ 3 4))
>
> Is the “+” executed at compile time or at load time?

Nothing is really evaluated during compilation.  (Not counting
optimization like partial evaluation.)

The "top-level" of a module is evaluated once when the module is loaded
into the run-time, whether it's in source form or a compiled .go.

So the "(+ 3 4)" in your example is (theoretically) evaluated when some
piece of code containing e.g. (use-modules (foo)) is executed, and the
module was not already loaded into the running Guile process.  (Although
due to optimization, that "(+ 3 4)" will probably be turned into 7 at
compile-time.)

Note that there is a macro called 'eval-when' which can let you
explicitly evaluate expressions at compile-time.

And of course, all macro procedures get evaluated at compile-time to
transform the compiled code as desired.

Hope that helps,
Taylan

Reply via email to