Hi Manuel,

I guess the loading of the code is required at least because you need it if
you don't want to get rid of the macro system.

Macros need to be loaded if you want to compile code that uses them (they
are executed in order to produce the final code that must be compiled).

Regards,

-- 
Laurent

2009/10/14 Manuel Woelker <[email protected]>

>
> Hi all,
>
> after digging around a bit in the clojure code, trying to get the
> compile to work, I found out that classes used by the compiled code
> actually classloaded by the compiler.
>
> I can totally get behind the idea that code is data. But in this case
> data is considered code, and is immediately executed. This leads to
> all kinds of fun.
>
> fun.clj:
>
> (defn foo [] (new mostly.Harmless))
>
> mostly/Harmless.java:
>
> package mostly;
>
> public class Harmless {
>        static {
>                System.exit(42);
>        }
> }
>
> Try compiling these two files. The clojure compiler just silently
> exits. I admit the example is a bit extreme and needlessly malicious,
> but there are valid uses for class initializers. I guess clojure files
> might suffer from the same problems.
>
> I sort of understand that for clojure compile time is runtime, but I
> still find it quite odd that a language that puts so much emphasis on
> avoiding side-effects would allow code to be executed as a side-effect
> of compilation. Shouldn't compilation be a theoretically pure function
> transforming a set of source files into a set of class files?
>
> I guess one way to achieve this would be to use "Class handles",
> instead of raw Class objects. Depending on situation these class
> handles could either delegate to Class instances or use asm to get the
> required information. This might be a best of both worlds solution.
>
> Especially for IDE's and build tools like ant or maven these
> compilation side effects can wreak havoc to the surrounding execution
> context.
>
> Cheers
>  - Manuel Woelker
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to