Generate static methods at runtime?

63 views
Skip to first unread message

vemv

unread,
Mar 16, 2013, 7:49:42 PM3/16/13
to clo...@googlegroups.com
All class-generating Clojure constructs that one can use at runtime such as proxy, reify, or defrecord, seem to generate instance methods only.

gen-class can emit static methods, but one cannot leverage its functionality at runtime.

Any way to accomplish this?

James Reeves

unread,
Mar 16, 2013, 8:09:30 PM3/16/13
to clo...@googlegroups.com
Out of curiosity, why would you want to?


--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Víctor M. Valenzuela

unread,
Mar 16, 2013, 8:21:22 PM3/16/13
to clo...@googlegroups.com
Interop, what else :)

the lib is called Nailgun, several Clojure projects use it. You feed its Java server with classes that have a static main() method, and then C clients can call those main() methods via sockets. The point is to avoid JVM startup time.

An example: https://gist.github.com/vemv/5178570

You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/Hu-oOlSccPc/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

Marko Topolnik

unread,
Mar 17, 2013, 2:34:20 AM3/17/13
to clo...@googlegroups.com

gen-class can emit static methods, but one cannot leverage its functionality at runtime.

But since compile-time is also a kind of runtime in Clojure, shouldnt't you be able to dynamically create an appropriate .clj file with the ns form and main- form, and have it compiled? 

Víctor M. Valenzuela

unread,
Mar 17, 2013, 3:31:24 AM3/17/13
to clo...@googlegroups.com
Yeah I guess it could work, did you have in mind something like programmatically running `lein compile`?

Can the JVM handle .class files written on the fly?

Anyway, for my particular problem I don't need runtime-compiled static methods anymore.

On Sun, Mar 17, 2013 at 7:34 AM, Marko Topolnik <marko.t...@gmail.com> wrote:

gen-class can emit static methods, but one cannot leverage its functionality at runtime.

But since compile-time is also a kind of runtime in Clojure, shouldnt't you be able to dynamically create an appropriate .clj file with the ns form and main- form, and have it compiled? 

--

Marko Topolnik

unread,
Mar 17, 2013, 4:36:39 AM3/17/13
to clo...@googlegroups.com
On Sunday, March 17, 2013 8:31:24 AM UTC+1, vemv wrote:
Yeah I guess it could work, did you have in mind something like programmatically running `lein compile`?

Yes, just about, but even simpler: you just call compileload, load-file or similar while binding *compile-files* to true (compile does that itself, others leave you the choice).
 

Can the JVM handle .class files written on the fly?

Yes, the JVM can load a .class file at any time, and in fact it does so in the routine operation. Unloading a class is not as simple, though. 
Reply all
Reply to author
Forward
0 new messages