On Jan 9, 2:00 am, lpetit <laurent.pe...@gmail.com> wrote:
> On 9 jan, 07:54, lpetit <laurent.pe...@gmail.com> wrote:
>
> > On 9 jan, 04:03, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:
> > > > Later on, if I call (load) (from a fresh clojure environment) from the
> > > > compiled classes, the top level (println)s are not executed, since not
> > > > compiled.
>
> > > Yes, that's the expected behavior.   "compile" only saves the things
> > > defined in the namespace.
>
> > Well, I easily understand that it is the compiled behaviour. And in
> > the same time, I don't feel it "right" that loading the same lib from
> > source file or from compiled files can have different results.
>
> Because then, it's not correct to say that we can interchange a source
> version and a compiled version of a lib.
> So maybe it should be expressed that libs should not do anything but
> define things in the namespace (maybe it's also stated in the doc and
> I skipped it, if so, my apologies).
> -> And that could be a distinction between libs and plain namespaces.
> And in that case, do you think it could be interesting to mark the
> namespace with a "is-a-lib" meta-data to (for example) :
> - prevent the compiler to compile it by default (or emit a warning, or
> compile only if some :force flag is set)
> - allow automatic tools to explicitly see the difference between a lib
> and a PON (plain old namespace)
>
> Thanks in advance for your answers,
>
> --

Your initial presumption is not correct. All top-level expressions are
compiled and will be evaluated on load. It is true that compilation
supports a same-world model, and evaluates the file while compiling
(in order to ensure declarations and macro definitions are available
for subsequent code). You can avoid evaluation of expressions during
compilation conditionally using *compile-files*:

Given this .clj:

(ns clojure.examples.foo)
(println 42)
(when-not *compile-files* (println "runtime!"))

Compilation produces:

Clojure
user=> (compile 'clojure.examples.foo)
42
clojure.examples.foo

Subsequent loading in fresh REPL produces:

Clojure
user=> (require 'clojure.examples.foo)
42
runtime!
nil

So I'm not sure how you concluded that expressions aren't evaluated -
they are. If you are not seeing that please try to isolate for a bug
report. But, you must note that loading (and thus its effects) will
happen only once, and that loading might not be happening when you
think, i.e. load/require are not "run":

;later in the same session
user=> (require 'clojure.examples.foo)
nil

Rich

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to