On Mon, Sep 7, 2009 at 3:10 AM, Phil Hagelberg<p...@hagelb.org> wrote: > > Stuart Sierra <the.stuart.sie...@gmail.com> writes: > >> The problem is, I think, that everyone will have a slightly different >> definition of "interactive environment." If I run >> java ... clojure.main path/to/file.clj >> does that count? What about >> java ... my.compiled.namespace >> ? Or what about a REPL thread inside another application? Or a >> Clojure function invoked from Java code? > >> I think the solution is to define your own *environment* var and bind >> it where you see fit, wrapping clojure.main if necessary. > > That's not really helpful for my purposes; I want by code to behave the > same way whether started from slime, an IDE, or the REPL; to do that I'd > have to either maintain my own list of heuristics for each possible > environment or get some sort of buy-in from the developers of each > environment. But now that I think about it, I don't suppose it's likely > to get enough consensus/buy-in for such a thing to actually be a > reliable heuristic, so I'll just code it against SLIME and let users of > the other environments patch it themselves. =)
Mmh, I don't know why you have the requirement (see Meikels answer about whether you really need it or not), but if you really have it then I'm not sure whether you actually need all the patching. Your approach is that the calling side is setting a global var (probably only going to happen for the dynamic environments, as the other ones are clojure agnostic). What you can always do (non-portable and confined to your code) is to rely on a environment variable (JVM -D cmdline, java.lang.System.getProperty(String)) which can be set for your different scenarios. Alternatively, if you want something which doesn't require the commandline to change but also doesn't involve a change in the actual code of the containers, you can try to 'query' your environment. E.g. try to load a signature class for Swank, and if it succeeds you figure you're running inside an Emacs session. Or for the servlet containers, they all publish stuff in JMX, so you can find out whether it's Tomcat, JBoss, etc. That deducing is going to be brittle to a certain extent, but it's also less intrusive, as you don't require anyone else to change their code. And you have more control over what is actually going to be the 'real' user agent when you're running multiple strategies at once (REPL inside Tomcat etc.) by inspecting results from different calls. HTH -D --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---