At Wed, 26 Apr 2017 15:04:15 -0700 (PDT), Dupéron Georges wrote:
> However, I'm not sure what operations can cause compile-time code to
> be run in this situation. My (possibly incorrect) understanding is
> that macros are executed only once (when expanding the code), but the
> code to the right-hand-side of a (define-syntax foo
> costly-operation), and the code within a (begin-for-syntax …) will
> both be run each time the module is required.

Each time a module is compiled, the compile-time code for any imported
modules is run in fresh compile-time instantiations of those modules.
("Compile" = "expand" in this context.)

So, given "a.rkt" as

 ;; a.rkt
 #lang racket
 (require "b.rkt")

and "b.rkt" as

 ;; b.rkt
 #lang racket
 (begin-for-syntax (displayln "b"))

if you use `racket a.rkt` leaving both modules as source, you'll see
printed "b" twice: once when compiling "b.rkt", and once when compiling
"a.rkt". If you use `raco make a.rkt`, you'll also see "b" printed
twice, but then `racket a.rkt` will not print "b".


If you have run `raco make a.rkt` already, then here's a potentially
confusing result:

 % racket
 Welcome to Racket
 > (require "a.rkt")
 > 1
 b
 1

In this case, no "b" is printed to load and execute the runtime part of
"a.rkt". Still, compile-time module instances have been created to
handle further evaluation in the REPL. So, as soon as `eval` is called
by the REPL for the expression `1`, the compile-time parts of "a.rkt"
and "b.rkt" are run. That's why "b" prints, and why it prints so late.


When you've compiled a program to bytecode and then run it, whether any
compile-time code is run depends on whether you use `eval` or
`dynamic-require` or similar.

Another part of the run time is just reading in bytecode, though. The
bytecode-loading part of Racket seems slower than it should be, and
that was one of the things I had planned to rebuild --- but now I'm
hoping that we'll get better load times by swapping Chez Scheme in
place of the current runtime system.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to