Dear all,

I am quite new to clojure, and I can't find any good way to generate
code at runtime.

Of course, there is eval, but eval is not very competent in manipulating
namespace and bindings at runtinme.

For example, this:

- (binding [*ns* *ns*]
      (eval '(do (ns Blop (:gen-class))
               (println (def x 0))
               ))
      (eval '(do (ns Blip (:use Blop))  (println Blop/x)))

    )

is unhappy because it can't see any .class for Blop.

- (binding [*ns* *ns*]
      (eval '(do (ns Blop (:gen-class))
               (println (def x 0))
               ))
      (eval '(println clojure.core/x))

    )

works in a compiled .class but not in the REPL

- (binding [*ns* *ns*]
      (eval '(do (ns Blop (:gen-class))
               (println (def x 0))
               ))
      (eval '(println user/x))

    )

Works in the REPL but not in a compiled .class.

I tried also to play a bit with load-string, but without any luck.

It must be possible to generate new bindings or even namespaces at
runtime, as the REPL does just that. 

Is there a deep reason why it is difficult?
Is there a lot of magic in the REPL?

Would it be possible to pull this magic out in a reusable way?
Can I try to do it or it is really difficult/impossible?

I think, it would quite Lispy for Clojure to have very few differences
between REPL and compiled runtime.
 
Thanks a lot for your help,

Best regards,

Nicolas.


--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
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