#clojure logs

2008-05-04

08:45leafwhi. I'd appreciate an example on how to use the (bean *obj*)
09:15leafwhi all. I'd appreciate very much an example on how to use the (bean *obj*) -particularly on how to retrieve then the values/pointers
09:17rhickeyuser=> (bean (java.util.Date.))
09:17rhickey{:year 108, :class class java.util.Date, :seconds 52, :time 1209906832244, :day 0, :minutes 13, :timezoneOffset 240, :hours 9, :date 4, :month 4}
09:21leafwmy problem is then how to access the map
09:22leafw(let [b (bean java.util.Date.))] (println (b :year))) ??
09:23leafw[that fails, of course)
09:34rhickey(:year b)
09:34rhickeyor (get (bean (java.util.Date.)) :year)
09:50rhickeyI made bean extend APersistentMap so implements IFn like other maps
09:51rhickeyso ((bean (java.util.Date.)) :year) now works
10:14meredydd(moving from #enclojure for keeping-on-topic reasons)
10:14meredyddrhickey: What's your reasoning behind disallowing wildcard imports?
10:14rhickeymeredydd: there is no programmatic way to enumerate packages. IDEs do it by parsing all the jar files, Clojure doesn't read the jar files
10:15meredyddUh-huh - I've looked up how it's done. So, you just don't want a hack that nasty in the language core?
10:15rhickeyno
10:15rhickeyIt would bring a tom of names into Clojure namespaces
10:15meredydd(uhhh...was that a 'no, that's not it', or a 'yes, I dont')
10:15rhickeytn
10:15rhickeyton
10:15meredydduh-huh...
10:16meredydd(pretty much the point, isn't it?)
10:16rhickeymaking a mess is the point?
10:16rhickeyNamespaces are reified things, having unused cruft in there is not productive
10:16rhickeyit's not merely a lookup list for the compiler
10:17meredydd?
10:17meredydd(ahh...which it pretty much is for Java, as far as I can see)
10:17meredydd(or do you object to the same in Java?)
10:18rhickeyIn Java there's no way for the programmer to interact with the 'namespace' in use in a module, in Clojure there is
10:18rhickey(ns-imports *ns*)
10:18rhickey(ns-imports (find-ns 'clojure)) etc
10:19meredydduh-huh
10:20meredyddI see. And you want that to be a useful tool for introspection, rather than a great big dumping-ground full of all of java.util, java.io...
10:20rhickeyright, I don't want to see an entire package because someone was too lazy and used *
10:20rhickeyso for now only java.lang and a couple of util things are auto-imported
10:20rhickeyeverything else must be explicit
10:21meredyddOkay.
10:21meredyddAnd people like me who want to start using Clojure to swing around big bits of our own applications are either going to write a lot of manual imports, or write hackity macros while you're not looking.
10:22rhickeythat's okay, it's still important for Clojure to have a recommended approach
10:23meredyddYep. And you have a coherent reason for wanting it that way.
10:24meredyddAnd, of course, the obligatory fanboyism - I am truly impressed with what you've done here, and I anxiously await more.
10:24meredydd(hmm. Although right now, 'more' is more a matter of a working Enclojure than anything else.)
11:27ChouserWith my sparse Java experience, I very much prefer reading code that has no wildcard imports. That way I have a fighting chance of finding the classes that are being used.
11:28ChouserI wonder if "refer" (and or the stuff from lib.clj) would be better off also not doing wildcards.
11:29rhickeythat stuff's about loading Clojure code - are you suggesting naming each imported function?
11:30Chouseryeah, I tend to use :only on refer for the same reason I don't use wildcard imports in Java.
11:30rhickeyGranularity-wise a clojure lib is roughly equal to a java class
11:30rhickeybut hey, more power to you!
11:36Chouserheh
11:37ChouserI just don't like referring to an unusual name with no suggestion of where it came from.
11:38Chouser(refer 'bing) (refer 'bang) (refer 'boom) (optimise {...}) ; go fish!
11:38rhickey(resolve 'optimise)
11:39rhickeynot arguing your point, it's a good practice :)
11:42Chouserwell, there is that. As long as you can get a REPL with the same context as the code you're reading. ...which is rather easier to do in Clojure than Java.
11:43ChouserHm, any reason someone couldn't create a Java REPL, compiling Java source on the fly just like you do with Clojure?
11:43ChouserI guess if I ever wanted to write Java code, I might care.
11:44rhickeysee: http://www.janino.net/
11:46jteothe verboseness of java code makes that an effort.
11:56leafwChouser: bean shell is essentially that. Java on the fly and without the static type verbosity
11:57leafw(but a very poor scripting language compared to clojure)
12:09rhickeyI've added docs for gen-class - feedback welcome!
12:29leafwanother one about beans: can one not just get but also set?
12:29rhickeyleafw: no set yet
12:29leafwoks
12:30leafwis it planned?
12:31rhickeythe semantics are muddy - maps are immutable and logically the altering operations produce new values
12:31rhickeywhereas I think people may expect changes to flow through to the underlying object
12:32rhickeybean is not meant for that
12:32leafwok
12:32leafwI am just used to jython
12:33leafwwhere beans are direct for both get/set
12:33leafwand change the underlying object.
12:34rhickeyit would be, IMO, be desirable to have the map alter ops produce new maps, but no flow-through alteration
12:35lisppaste8aking pasted "recursive shootyout" at http://paste.lisp.org/display/60211
12:35akingrhickey: to practice Clojure, I thought I'd convert some of the shootout benchmark progs. Here's the recursive one
12:35akingIt seems to run about 16x slower then the java server one
12:36leafwI hope I haven't said anything silly: http://pacific.mpi-cbg.de/wiki/index.php/Clojure_Scripting
12:36leafwthe wiki is just starting, more to come soon.
12:36akingThat includes removing the startup time
12:36akingANything (other than changing the algorithm) I missed?
12:37rhickeyThat's the arithmetic, not the recursion. Not sure the declarations are useful - you should avoid them unless proven to be so
12:37akingrhickey: yeah.. I noticed there was almost no difference in speed with or without them
12:38rhickeyaking: clojure looks much better without in that case
12:38akingalso - the println seems to put an extra space before and after a number?
12:39rhickeyThe algorithms seem fine
12:39rhickeyaking: yes, pr functions put spaces between multiple args, use str first if you want to avoid that
12:40akingok - thanks
12:43akingrhickey: Is there an example of getting command line arguments into clojure?
12:43rhickeyaking: *command-line-args*
12:45rhickeyleafw: looks fine
12:47akingrhickey: thanks - found a reference to it in the Feb 25th news :)
12:48rhickeyaking: yeah, there are a few non-fn vars like that undocumented, sorry
12:49akingrhickey: no prob - I should generally look in the clojure source first before asking
12:50jteorhickey: on a scale of 1 to 10, where you are with regards to stability of the clojure "core" language?
12:51rhickeyjteo: I'm probably the wrong one to ask :) - anyone else want to chime in?
12:51rhickeyor are you talking about feature stability?
12:52jteofeature?
12:52jteotechnically, anything doable in the jvm or java libs is already a feature. ;)
12:55rhickeyI haven't run out of ideas, but I don't have anything significant about what I've already done that I'm looking to change. Clojure is pretty small and that is also a feature IMO.
12:57rhickeyFor instance, I just added gen-class, which doesn't alter anything that already exists in Clojure, but is a pretty big enhancement
12:59jteotrue.
12:59akingrhickey: where's the docs for gen-class? I've checked website "Java Interop", "news" and "API" - and svn
12:59Chouserare you going to rename "for" "doseq" and friends?
13:00rhickeyaking: (doc clojure/gen-class)
13:00rhickeyaking: when I get some feedback I'll do a news item. The rest of the site documents the release, so it won't appear there until the next release.
13:00akingheh - didn't think of that :)
13:02rhickeyChouser: I thought only "for" to "from" was on the table, doseq stays the same and doseqs would be new
13:03rhickeyChouser: I realize that's not an answer :)
13:04akingrhickey: hmm.. not in boot.clj - had do (load-file "src/genclass.clj") first
13:04rhickeyaking: right, it's in incubation right now
13:05rhickeybleeding edge svn stuff :)
13:06akingheh - I'll go play with gen-class for a bit. I see it will reduce the amount of enclojure java source required.
13:08rhickeyaking: the idea is to eliminate the need for Java stubs, as well as provide a general class extension mechanism. Looking for feedback as to the comprehensibility of the docs...
13:31leafwis there any way to list all vars in the current namespace?
13:32leafwthat would help in finding things like *out* and *command-line-args*
13:32leafwns-amp
13:32leafwlooks like it
13:33rhickeyyup
13:34leafwI still lack an intuitive knowledge on clojure ... (apply ns-map (all-ns)) doesn't work, and was the first thing that came to lind
13:34leafws/lind/mind/
13:34leafwaha, so (map ns-map (all-ns)
13:34leafwthat works.
13:45akingrhickey: after doing a 'gen-and-load-class' it looks like you have to then import it into namespace you were in?
13:46akingalso, maybe a comment about it being a one time only operation in the docs?
13:48leafwthanks for help and hints. Out
13:50rhickeyaking: good point, yes, one-time only is the tricky part
13:54akingDoes clojure use a classloader per namespace?
13:54akingOr just a root classloader?
13:57akingIf it was a classloader per namespace, couldn't you do a gen-class in that namespace's classloader - and if you wanted to recreate a gen-class, jsut delete the namespace, recreate it then call gen-class again?
13:58akingIt's been a few years since I played with java classloaders, so my memory might be a bit fuzzy on it..
14:02rhickeyI'm not going to take on same-named class reloading, there are all kinds of issues, esp. since you might want to use the class from multiple namespaces. Right now there is a root namespace and a bunch of tear-offs which are per compilation (load/eval), not per namespace
14:03rhickeythe idea behind gen-class is that, since it is implementation-free, the gen-class declaration should be fairly stable
14:03rhickeythe Clojure side of gen-class is completely dynamic and supports iterative development
14:04akingrhickey: ok - just thought I'd check - forgot about the cross namespace usage - that would be ugly to handle.
14:21jtraHello
14:21rhickeyhi
14:22jtraI'm new to clojure, I know both Java and Common Lisp well, and after reading documentation I think I like the clojure :-)
14:23rhickeygreat!
14:23jtraI have also bit of Haskell experience, so paradigm suits me well
14:31bagglesthe world is crying out for clojure.
14:31bagglesor if it isn't, it should be.
14:31bagglesplease save us all
14:32rhickey:) blogging about Clojure is welcome...
14:32bagglesyeah... if only i had enough energy for this stuff. i've been running around outside in the hazy sun today :)
14:33bagglesgetting a real job recently, i now have lot of admiration of wthose who manage to keep up on the FLOSS stuff and work aswell....
14:35jtraI played with repl and simple JPanel in JFrame, it works as expected but when I run it as script, it exits despite AWT thread is running (which would not exit when such code would be written in Java itself). What is proper way to prevent exiting main thread in Clojure when GUI is active?
14:38rhickeyjtra, I'm going to take the System.exit call out of Script.java - seems to trip a lot of people up...
14:40rhickeyjtra: that's up if you're on SVN
14:41jtraok, I will remove it from Script.java and recompile - I have 20080329 release
14:44jtrait works as expected now
15:44rhickeyServlets in Clojure - no Java required:
15:44rhickey(clojure/gen-and-save-class "/Users/rich/dev/clojure/gen/"
15:44rhickey 'org.clojure.ClojureServlet
15:44rhickey :extends javax.servlet.http.HttpServlet)
15:44rhickeyClojureServlet.clj:
15:44rhickey(in-ns 'org.clojure.ClojureServlet)
15:44rhickey(clojure/refer 'clojure)
15:44rhickey(defn doGet [this req resp]
15:44rhickey (let [out (. resp (getOutputStream))]
15:44rhickey (. out (println (str "Hello World at " (new java.util.Date))))))
15:45rhickeydrop into Tomcat/Glassfish
22:53Chouserbpattison: welcome!
22:56bpattisonthanks
22:58bpattisonmaking a concerted effort to learn clojure
23:21Chouseranyone here have gen-and-load-class working?
23:22bpattisonwhy does (println "hello world") produce "hello world"\n nil -- what's the extra nil for?
23:22Chouserbpattison: that's the return value from println
23:22Chouserthe REPL prints return values for you.
23:23bpattisonoh! thanks
23:38ChouserAh! It helps to have rebuilt clojure instead of just updating the sources.