unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* how far does eval go when module gets compiled?
@ 2016-01-12  4:52 Matt Wette
  2016-01-12  7:56 ` Taylan Ulrich Bayırlı/Kammer
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Wette @ 2016-01-12  4:52 UTC (permalink / raw)
  To: guile-user

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?

Matt




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how far does eval go when module gets compiled?
  2016-01-12  4:52 how far does eval go when module gets compiled? Matt Wette
@ 2016-01-12  7:56 ` Taylan Ulrich Bayırlı/Kammer
  2016-01-12 19:52   ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Taylan Ulrich Bayırlı/Kammer @ 2016-01-12  7:56 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

Matt Wette <matthew.wette@verizon.net> 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how far does eval go when module gets compiled?
  2016-01-12  7:56 ` Taylan Ulrich Bayırlı/Kammer
@ 2016-01-12 19:52   ` Ludovic Courtès
  0 siblings, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2016-01-12 19:52 UTC (permalink / raw)
  To: guile-user

taylanbayirli@gmail.com (Taylan Ulrich "Bayırlı/Kammer") skribis:

> 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.)

Right:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,optimize (lambda (x) (+ 3 4))
$2 = (lambda (x) 7)
--8<---------------cut here---------------end--------------->8---

Ludo'.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-12 19:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-12  4:52 how far does eval go when module gets compiled? Matt Wette
2016-01-12  7:56 ` Taylan Ulrich Bayırlı/Kammer
2016-01-12 19:52   ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).