[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how far does eval go when module gets compiled?
From: |
Taylan Ulrich Bayırlı/Kammer |
Subject: |
Re: how far does eval go when module gets compiled? |
Date: |
Tue, 12 Jan 2016 08:56:49 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Matt Wette <address@hidden> 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