#clojure logs

2009-03-30

00:24cooldude127damn irc is boring at night
00:30cmvkkeveryone's coding
01:14Rayneshttp://xkcd.com/289/
01:14slashus2What is the best way to represent a binary tree when coding in clojure?
02:33slashus2Most of the examples of zippers that I find are in haskell :-(.
03:17l_a_mi ve got a problem to setup Slime with clojure : http://paste.lisp.org/display/77765
03:17l_a_mSLIME works fine with my SBLC configuration but i can t setup clojure
03:17l_a_many help ?
03:29tsdhHi.
03:29tsdhIs it possible to use clojure and swank to override a static method in java.lang.StrictMath?
03:39antifuchsl_a_m: the error says it all: you need to set swank-clojure-binary (to a script that will start clojure) or swank-clojure-jar-path (to the path where the clojure.jar file is located)
03:39clojurebotit is too
03:45antifuchsl_a_m: are you referring to bill clementson's notes? these were pretty helpful for getting me up to speed (:
03:46MikeSethl_a_m: clojurebox has scripts to configure slime
03:46MikeSethdunno if that helps
04:04l_a_mantifuchs: yeah
04:04l_a_mantifuchs: but in my config i set the swank-clojure-jar-path
04:04l_a_mantifuchs: (setq swank-clojure-jar-path "/usr/local/src/clojure-language/clojure/clojure.jar") ?
04:04antifuchsoh, I think that's the same problem I ran into
04:04l_a_mso i don t really understand ...
04:04antifuchsyou might have to set this before you require 'swank-clojure-autoload
04:04l_a_mok
04:04l_a_mi try this one
04:04antifuchsI suppose you're loading slime before this block?
04:04l_a_mantifuchs: do you replace SBCL by Clojure ? :)
04:04antifuchsdefinitely not (:
04:04antifuchsboth have their place in my setup (:
04:04l_a_m:)
04:04l_a_mmy company wants only use Java ...
04:04l_a_mso Clojure could be a nice language :)
04:04antifuchsit is!
04:04RaynesIt's the best thing evar.
04:04antifuchslet's not get carried away here. bacon is still pretty excellent.
04:05RaynesOh yeah, I forgot about bacon.
04:14MikeSethis this a reddit convention now? all sins written off for the sake of bacon?
04:29antifuchsit is happening all over the internet. I doubt this is reddit's doing.
04:31antifuchsanyway, my point should have been: don't believe universal best-ness claims for a second. everything has trade-offs.
04:32clojurebotfor is not a loop
04:51MikeSethis clojurebot written in clojure?
04:51MikeSethclojurebot: status
04:51clojurebotIt's greek to me.
04:56HolcxjoMikeSeth: http://github.com/hiredman/clojurebot/tree/master
04:56HolcxjoMikeSeth: The higher levels are -- the IRC comms are done by some Java lib I believe
05:08MikeSethnice
05:11AWizzArdclojurebot: max people
05:11clojurebotmax people is 164
05:18rsynnottMikeSeth: that'd be inverse judaism?
05:18l_a_mantifuchs: thanks
05:18l_a_mnow i ve got this error : http://paste.lisp.org/display/77772
05:18l_a_mclojure repl seems working but not slime
05:20rsynnottl_a_m: recent versions of both clojure-swank and slime?
05:20msinghso is there a book to read to learn clojure?
05:22l_a_mrsynnott: i thought i updated them on friday ... i check
05:24l_a_mrsynnott: yes with git version of these 2 components
05:58l_a_many idea for this error ?
06:16hoeckl_a_m: looks like swank tries to execute some common lisp code in clojure (swank::read-motd)
06:16l_a_mhoeck: strange
06:16hoeckmaybe this comes from a slime extension package/module?
06:17l_a_mhoeck: i check ...
06:23hoeckl_a_m: they are activated with the slime-setup command
06:23l_a_mok thanks it works fine now
06:36MikeSethrsynnott: inverse judaism?
06:37MikeSethah you mean bacon
06:37MikeSethlol
06:37MikeSethnot really though, jewish sins get written off once a year unconditionally :P
06:37MikeSethis there a clojure port for smartphones?
06:40hoeckMikeSeth: there is remvee trying to run clojure on android: http://wiki.github.com/remvee/clojure
07:09antifuchshm, is there an analogue to common lisp's CASE form in clojure?
07:09antifuchshm, clojure.contrib.fcase, I suppose
07:13hoeckantifuchs: or condp
07:14hoeck,(condp = :b :a 'a :b 'b)
07:14clojurebotb
07:15antifuchsexcellent
07:15antifuchseven gives me an IllegalArgumentException for unknown clauses. so it's like ecase, which I was actually looking for :
07:15antifuchsthanks
07:20AWizzArdantifuchs: you can specify a last form in condp which is used as default of no other match is found. It should not be a pair of test and expression, but only an expression.
07:20antifuchsthat makes sense; for this case, the exception is better, though (:
07:51AWizzArdantifuchs: yesterday we were talking about defining a my-apply, and I mentioned your macro which can fake it for some cases of apply. Maybe we should try a clojure version of it?
07:55antifuchswhich of my macros? (-:
08:04AWizzArdyou once wrote a macro that can create apply like functions
08:17tsdhSorry for asking again, but is it possible to override a static method of a standard java class using swank and clojure?
08:19rhickey_tsdh: there's really no such thing as 'overriding' a static method. Do you want to replace it, or have a same-named function in a derived class?
08:19AWizzArdtsdh: I am not a Java man, but I would say that it is not possible to override any method. The official way to do that could be to derive a class and have a method there with the same name.
08:20tsdhrhickey_: Right, I want to replace it.
08:20rhickey_tsdh: not possible
08:20tsdhToo bad. Thanks anyway.
08:21AWizzArdtsdh: I think it is not bad, but instead extremly good. One should not be able to do that. Also one should not be able to replace 14 with a -3.
08:23tsdhAt least in my situation it would be handy. I have to use a component which is just a blackbox (jar), and profiling shows that most time is spent in StrictMath.floor(). But nothing relies on complience of StrictMath, so Math.floor() would be as good, but possibly much faster.
08:40in-code-we-trustis planned to port clojure to .net/mono framework?
08:50hoeckin-code-we-trust: http://code.google.com/p/clojure-contrib/source/browse/#svn/trunk/ClojureCLR is the beginning of a clojure port to .net
08:50in-code-we-trusthoeck: thnx
10:06hiredmanhttp://blogs.sun.com/CoreJavaTechTips/entry/closing_a_urlclassloader
10:10cemerickheh. I remember having to implement that sort of thing in my own home-baked classloader years ago. Nice to see it's going to be available in jdk *SEVEN*!
10:11AWizzArdWill jdk 7 also support tagged numbers?
10:11cemerickAWizzArd: I thought not, but I'll bet rhickey_ has the latest scoop there.
10:11clojurebotlatest is 1337
10:11rhickey_AWizzArd: nope
10:12AWizzArdI see.
10:12cemerickof course it's jdk *SEVEN*, which likely won't be released for another 9-12 months, nevermind usable for redistributed libraries, etc. :-/
10:13cemerickprobably brought on by grumpiness associated with being back in Swing-land
10:14AWizzArdah, but will they not have improvements for Swing in jdk 7?
10:14cemerickChouser: FYI, titanium isn't fully-baked yet, BTW.
10:14cemerickAWizzArd: you're just trying to bait me :-D
10:23danlarkinmorning clojurecrats!
10:23WizardofWestmarcmorning danlarkin
10:23WizardofWestmarcbtw finally got around to getting madison loadable in my repl last weekend
10:40gnuvinceIs anyone here knowledgeable about java.nio? Specifically, I need to know if I can have a view Buffer (for example, (.asIntBuffer byte-buf)) where change in the position of one affects the other?
10:41Carkgnuvince : if you find out let me know
10:41Carkmay i ask what you're doing with nio ?
10:41gnuvinceCark: http://bitbucket.org/gnuvince/clj-starcraft/src
10:42gnuvinceCark: I found that the program that is backed by the unpacking Java library that I use is more than an order of magniture faster than my Clojure implementation.
10:42gnuvinceI've been toying around for the past 2-3 weeks trying to find some way to give my program a boost
10:42gnuvinceI've been unsuccessful so far.
10:43Carkso you turning to nio ?
10:43gnuvinceI used nio, but I used getShort and getInt on the byte buffer
10:44gnuvinceI'm want to try with view buffers (which the documentation says could improve performance), but if I can't keep track of what's been read, I don't gain a lot.
10:45Carki see ... i'm working on a TCP server
10:45Carkwith ssl
10:45gnuvinceMore useful than what I'm doing :)
10:45Carkhaha well who cares =P
10:46Carkit's too ugly right now to let anybody see it
10:46clojurebotit is too
10:46antifuchsAWizzArd: (about the apply macro) omg, that was supposed to be humorous (:
10:46gnuvinceHmmm
10:46gnuvinceWell I guess I'll have to manually move the buffer :-/
10:48AWizzArdantifuchs: Was a nice hack anyway. And it even worked for several cases.
10:49Carki found this buffer business is all very imperative
10:49Carkclojure isn't so well suited for that
10:49antifuchsAWizzArd: you're starting to scare me ((-:
10:49antifuchsbut I'm glad that it works (:
11:08danlarkinWizardofWestmarc: sweet! Wish I had more (any) time to improve on it, work picked up as we near a launch
11:13duderdoHello!
11:13duderdoHow can I step through my clojure code to debug?
11:14hiredmanas far as debuggers go, most people use jswat
11:15hiredmanI think
11:15hiredmanI just write little functions and test them
11:15duderdoBut there's no step like in SBCL?
11:15duderdoHrm, okay thanks
11:16AWizzArdBtw, did anyone here use Maven for her Clojure projects?
11:17hiredmanwoa
11:31triddellFYI: I just posted links to some android/clojure tutorials I wrote to the google group.
11:31triddellandroid with emacs and clojure that is
11:31AWizzArdIs there a problem to have a namespace having the name of some Java class? Example (ns com.company.XmlRpcClient (:include (org.apache.xmlrpc.client XmlRpcClient)) (:gen-class))
11:32danlarkinAWizzArd: perhaps you meant :import instead of :include?
11:32AWizzArdright, :import
11:33danlarkinoh, thought that might've been in your actual code
11:33AWizzArdNo sorry, my thoughts were drifting away a bit while I typed that.
11:45WizardofWestmarcdanlarkin: understandable. At some point (not now, not at lappy w/the setup) I will probably need to pick your brain a bit to get it actually running a web page
11:45WizardofWestmarcand once I get going I may see about doing updates myself to help you out if need be.
11:45danlarkinrad
12:16kefkaI may have found a bug (?) in clojure.set/difference:
12:16kefka,(clojure.set/difference #{0 1 2} [0 2])
12:16clojurebot#{1}
12:16kefka,(clojure.set/difference #{0 2} [0 1 2])
12:16clojurebot#{}
12:16hiredman,(doc clojure.set/difference)
12:16clojurebot"([s1] [s1 s2] [s1 s2 & sets]); Return a set that is the first set without elements of the remaining sets"
12:16kefka,(clojure.set/difference #{"0" "2"} ["0" "1" "2]")
12:16clojurebotUnmatched delimiter: )
12:16kefka,(clojure.set/difference #{"0" "2"} ["0" "1" "2"])
12:16clojurebot#{"0" "2"}
12:16stuhoodhmm.
12:16kefkaIt worked fine for the difference of #{0 2} [0 1 2], returning the empty set.
12:16stuhood,(class #{"1"})
12:16clojurebotclojure.lang.PersistentHashSet
12:16hiredman,(clojure.set/difference #{"0" "2"} #{"0" "1" "2"})
12:16clojurebot#{}
12:16hiredmanif you are doing set operations, use sets
12:16kefkaYes, it works properly if you convert it into a set.
12:16kefkaIt's not a major issue, but it threw me off, because I had assumed that the 2nd element could be an arbitrary collection.
12:16hiredmanthe fact that it works on non-sets should be considered an accident
12:16AWizzArdThat could be easily done, but you need to be aware that this is potentially a very slow operation.
12:16hiredmanthe doc string only mentions sets
12:17kefkaIt's also awkward that this bug (as easy as it is to work around) works on integers but not strings.
12:17AWizzArdIt is very fast to loop up if X is an element of a set. But to test if X is an element of a vector is in general not a fast operation.
12:18hiredmanI fail to see how having undefined behaviour for something not covered by the docstring is a bug
12:18hiredman~def clojure.set/difference
12:18slashus2,(clojure.set/difference #{0 1 2} #{1})
12:18clojurebot#{0 2}
12:19slashus2,(clojure.set/difference #{0 1 2} [1])
12:19clojurebot#{0 2}
12:19slashus2That is what you are trying to do?
12:19slashus2You take the elements in the first set, and remove the elements in the remaining set.
12:28AWizzArdwhat this function could do is maybe throwing an exception
12:28AWizzArdif not both args are sets
12:28slashus2,(clojure.set/difference [0])
12:28clojurebot[0]
12:28AWizzArdEven better if it would throw a compile time exception. This could be done with Gradual Typing. See http://groups.google.com/group/clojure/browse_frm/thread/7a48f48e4b197a15
12:28hiredmanAWizzArd: if you want it, it would be great if you could write it :P
12:28AWizzArdUnrealistic, as I have no time for that. *sigh*
12:28hiredmanI think it would be nice, but I don't constantly bring it up, because I am not actively working/thinking about it
12:29AWizzArdI also think it would be nice, even very nice. As long it is optional.
12:30AWizzArdAnd I think it is also no problem at all to bring up an issue from time to time, even if one is not the right person for implementing it.
12:30hiredmansure
12:30AWizzArdWhat I can offer is to be an extensive tester for this.
12:34hiredman,(- 2176 - 2009)
12:34clojurebotjava.lang.ClassCastException: clojure.core$___3339 cannot be cast to java.lang.Number
12:34hiredman,(- 2176 2009)
12:34clojurebot167
13:45Lau_of_DKHey guys
13:47danlarkinHello to my favorite dane
13:48Lau_of_DKUh what an honor :)
14:02kefkaIs there a fast way O(log n) of getting the min. and max. elements from a sorted set?
14:04Lau_of_DK(apply max set)
14:04Lau_of_DK?
14:04kefkaI'm thinking that would call max with all the elements as args.
14:04kefka(first (seq set)) should work for the minimum.
14:04cgrandkefka: first and peek ?
14:04kefka(doc peek)
14:04clojurebotFor a list or queue, same as first, for a vector, same as, but much more efficient than, last. If the collection is empty, returns nil.; arglists ([coll])
14:04cgrandmaybe not
14:04hiredmanerm
14:04kefkapeek does not work on sorted-sets
14:04hiredman,(last (seq set))?
14:04clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: core$set__4299
14:04hiredman,(sort-set 1 4 3 2)
14:04clojurebotjava.lang.Exception: Unable to resolve symbol: sort-set in this context
14:04cgrand,(.last (sorted-set 1 4 3 2))
14:04clojurebotjava.lang.IllegalArgumentException: No matching field found: last for class clojure.lang.PersistentTreeSet
14:04kefka,(let [the-set (apply sorted-set (range 100000))] (time (first the-set)))
14:04clojurebot0
14:04clojurebot"Elapsed time: 0.111 msecs"
14:04kefka,(let [the-set (apply sorted-set (range 100000))] (time (last the-set)))
14:04clojurebot99999
14:04clojurebot"Elapsed time: 133.447 msecs"
14:04kefka,(let [the-set (apply sorted-set (range 100000))] (time (first (reverse the-set))))
14:04clojurebot99999
14:04clojurebot"Elapsed time: 160.627 msecs"
14:05cgrandclojure's sorted sets don't implement java.util.SortedSet !?
14:05kefka,(let [the-set (apply sorted-set (range 100000))] (time (first (subseq the-set > -1000))))
14:05clojurebot0
14:06clojurebot"Elapsed time: 2.758 msecs"
14:06durka42(doc subseq)
14:06clojurebotsc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true; arglists ([sc test key] [sc start-test start-key end-test end-key])
14:07cgrand,(first (rseq (sorted-set 2 4 3 1)))
14:07clojurebot4
14:07kefka,(let [the-set (apply sorted-set (range 100000))] (time (first (rseq the-set))))
14:07clojurebot99999
14:07clojurebot"Elapsed time: 0.065 msecs"
14:08kefkarseq is the trick.
14:08kefkaApparently rseq is smart enough re: sorted sets to read efficiently from the max-end.
14:11cgrandrseq works on anything that implements IReversible
14:59hiredmanI wonder if there is someway to make ring play with quercus
14:59hiredman~ring
14:59clojurebotring is http://github.com/mmcgrana/ring/tree/master
14:59durka42ick, why would you want to use php :)
14:59marklarHow do you call the super class constructor when you are extending a Java class with gen-class?
15:00marklarerm, sorry I meant a super class method, not constructor
15:02hiredmanyou would use :exposes-methods
15:02hiredmanhttp://clojure.org/API#gen-class
15:04marklarhiredman: thanks, I read that completely wrong
15:36Rayneshiredman: You're still my hero <3
16:07cemerickrhickey: it looks like AOT compilation hangs if a JFrame is created and .pack()'ed as a side effect of loading the file(s) being compiled. That's obviously not good in general (I hit this while mucking around casually), but perhaps some mechanism should exist so that the compilation process is safe from non-referentially-tranparent expressions being def'ed? This sort of thing would be a *bear* to debug in anything other than a trivial file.
16:26hiredman~ticker JAVA
16:29clojurebotJAVA; -7.54
16:29rsynnottsun still in its IBM-acquisition-possibility glow, I see
16:29danlarkinhaha
16:29rsynnott(they only want it for the ticker symbol)
16:29clojurebotit is too
16:29cemerickthe #1 thing that will come out of that acquisition will be the elimination of the JAVA ticker :-)
16:29danlarkinwhich exchanges does clojurebot know about?
16:29hiredmanthat is triggered far to often
16:29danlarkin~ticker CHINA
16:29clojurebotCHINA; -5.26
16:29danlarkin:( china
16:29rsynnottcemerick: nah, IBM will start using it for themselves
16:29rsynnottthey have a bit of a java fetish these days
16:29hiredmanI have no real idea how to read the json data from google for finance stuff
16:29cemericknot enough that they'd drop IBM...
16:29danlarkinhiredman: how do you mean? to get info other than the delta for the day?
16:29hiredmanyeah
16:29hiredmanhttp://www.google.com/finance/info?q=JAVA
16:30durka42~ticker GM
16:30clojurebotGM; -25.41
16:30hiredmanI remove junk at the begining and at the end of that and use your json parser on it
16:30danlarkinyeah this is oddly formatted
16:30danlarkin/ [
16:30danlarkiner double slash open bracket, wonder what that's about
16:30hiredmanand the closing bracket
16:30durka42a comment
16:30danlarkinjson doesn't have comments, but even if I were to accept it was supposed to be a comment... why is it in the production feed? and why is the closer still there? it's wacky!
16:30hiredman~ticker IDSGX
16:30clojurebotIDSGX; -2.17
16:52cooldude127do we already have a clojure library for writing CSV files?
16:53clojurebotclojure is the brand
16:53hiredmanI don't think so. I have used supercsv in the past with clojure http://supercsv.sourceforge.net/
16:53hiredmanit seems decent enough
16:53zakwilsoncooldude127: I wrote my own library to read/write CSV. It's simple, but it works.
16:53hiredmanwriting csv parses :(
16:53cooldude127zakwilson: you have a link to the code? i'm feeling lazy
16:53zakwilsonhttp://github.com/zakwilson/zutil-clj/tree/master
16:53zakwilsonMay be out of date.
16:53cooldude127we'll find out, i probably could write something on my own, but CSV is not my focus right now
16:55hiredmanwhy not supercsv?
16:56cooldude127just trying to get a job done, real quick for a project, so if i don't have to mess with the classpath right now, it's better
16:57zakwilsoncooldude127: if it's simple enough, my library will do.
16:58cooldude127yeah just generating some values in clj, need to plot them on a graph
16:59zakwilsonGive it a try. BSD license.
17:13danlarkinNIHsyndrome.com
17:13hiredmanI guess its not too bed if you are generating your own csv file
17:58duderdoWhat's the best way to figure out how to use swing components in clojure? Looking at the java docs is overwhelming to say the least
17:59danlarkinughhhh bitten again by not being able to give metadata to Strings
17:59danlarkingrrrrrrrrrrrrrrrrr
17:59zakwilsondanlarkin: if you're talking about my CSV library as NIH syndrome, that may be the case, but using the first couple Java libs I found looked harder than just writing one in Clojure.
17:59slashus2It may be useful to make it to where strings can accept metadata.
18:00danlarkinI would even accept (with-meta "foo" {:foo :bar}) returning a clojure.lang.String, which could implement IObj
18:00slashus2I guess it is for compatibility purposes.
18:00slashus2?
18:01danlarkinwell it's so strings can be java.lang.Strings
18:01AWizzArd_danlarkin: you could write your own with-meta macro which expands into with-meta for all data, but for strings it will write the data into your own hashmap
18:01danlarkinand metadata-able classes must implement IObj, which java.lang.String does not
18:02danlarkinAWizzArd_: but I don't want to return a hashmap, I want a string :/
18:02AWizzArd_the macro could return a string, but under the hood write into your own metadata container
18:03AWizzArd_instead of using the official getter/setter for metadata you write your own
18:03AWizzArd_and use those instead
18:03danlarkinexcept in the case that I want to ignore the metadata... I can't, because now I'm returning a hashmap instead of a string
18:03AWizzArd_(danlarkins-with-meta ...)
18:04danlarkinmight as well just return a hashmap with a :text attribute and whatever metadata I wanted, put it right in the hashmap
18:05AWizzArd_Yes, but then all your code needs to deal with a hashmap, and not a string
18:05danlarkinbut wouldn't that be the case with the way you're suggesting too, or am I missing something?
18:06AWizzArd_what i was thinking about was more: you have a (def string-metadata (ref {})) into which you put the metadata for your strings, when you use your (danlarkins-with-meta ...)
18:07danlarkinohhh. hm
18:07danlarkinthat's awful ugly :-/
18:07AWizzArd_why?
18:07hiredmanzakwilson: supercvs's CVSReader is very nice
18:08AWizzArd_danlarkin: instead of (meta ..) for reading metadata, you can use (danlarkins-meta ..). And instead of (with-meta ..) for attaching meta data, you will use danlarkins-with-meta.
18:09AWizzArd_It would look basically the same to what you have now, only the name changes.
18:09hiredman http://gist.github.com/87909 is kind of a bad example because the data I was reading was very, uh, dirty
18:10danlarkinAWizzArd_: sorta... except for some crucial areas, like two different "copes" of the same string couldn't have different metadata, which I need
18:11danlarkinsorry, "copies"
18:12danlarkininstances would actually be a better word
18:12danlarkinwelp... I guess I just have to return a map with :text
18:12hiredmanhaving a metadata slot is so nice, I wonder if sun would consider adding one to Object :P
18:12AWizzArd_danlarkin: if Java makes it possible to fetch the address of an object in ram, then you would have a unique key for your meta data store
18:13AWizzArd_makes it possible ==> allows
18:15AWizzArd_Also you could work around this and add all strings into a vector, which you traverse and then check for identity.
18:15danlarkinI think Java does... doesn't it? how does identical? work
18:15AWizzArd_The actual string + the index in that vector could be the key then
18:15AWizzArd_Of course it must be possible somehow, otherwise the GC couldn't work. I just don't know if Sun gives users access to that information.
18:16danlarkinI think I'm going with the path of least resistance
18:17AWizzArd_danlarkin: anyway, if you don't care strongly about amazing performance for retrieving metadata, and if you don't intend to have millions of copies of otherwise identical strings, then the trick with a hashmap + vector would be ok
18:17hiredman,(identical "a" "a")
18:17clojurebotjava.lang.Exception: Unable to resolve symbol: identical in this context
18:17hiredman,(identical? "a" "a")
18:17clojurebottrue
18:18AWizzArd_because those are constants
18:18hiredman,(identical? "a" (str \a))
18:18clojurebotfalse
18:18AWizzArd_good :)
18:18AWizzArd_so, make that macro store these strings in a vector
18:18hiredman,(identical? (str \a) (str \a))
18:18clojurebotfalse
18:19hiredman,({(str \a) 1 (str \a) 2} "a")
18:19clojurebot1
18:19hiredmanugh
18:19hiredmanhmmmm
18:19AWizzArd_when reading the metadata you make a lookup for that string. If that key does not exist, traverse your vector (filter #(identical? % s) vector-of-metadata-strings)
18:19clojurebotfor is a loop...in Java
18:19AWizzArd_if that returns something, then make another lookup in the hashmap for the vector ["String here" index]
18:20AWizzArd_and that will then return the metadata for you
18:20AWizzArd_even for copies
18:21AWizzArd_bah, my filter above misses the indexes of course
18:21hiredman~def c.l.IObj
18:21hiredmanhmmm
18:21hiredman~def c.l.IMeta
18:21danlarkinAWizzArd_: I think that's just too much hassle for what I'm doing
18:22AWizzArd_well, it first sounded as if you really want metadata for strings
18:22hiredmanyou could proxy String Imeta and IObj
18:22danlarkinI do... but not at the cost of totally uglifying the program
18:22AWizzArd_And Clojure is a Lisp, so for a lot of things you won't need its implementor to do work for you.
18:22AWizzArd_But where would that program become ugly?
18:22AWizzArd_We are talking here about writing two macros of 5-10 lines each
18:22hiredman,(proxy [String] [IMeta IObj] [])
18:22clojurebotjava.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
18:22hiredmanoh
18:23hiredmanString is final
18:23AWizzArd_yes
18:23hiredmanof course
18:23hiredmanJerks
18:23AWizzArd_hehe :)
18:23danlarkinhaving to use a ref to store metadata is ugly
18:23AWizzArd_Why?
18:23AWizzArd_It is state
18:24danlarkinnot really
18:24AWizzArd_mete data is about side effects / state change
18:24AWizzArd_Some memory cells in your computer change their electric charge
18:24danlarkinhaha cmon that's being silly
18:25AWizzArd_Why?
18:25clojurebotwhy not?
18:25AWizzArd_clever bot
18:25danlarkinqed
18:25hiredmanclojurebot: botsnack
18:25clojurebotthanks; that was delicious. (nom nom nom)
18:25AWizzArd_got too many botsnacks or what?
18:25hiredman~ticker GOOG
18:25clojurebotGOOG; -1.44
18:25AWizzArd_what is ticker?
18:25zakwilsonhiredman: superCSV looks quite usable. I'll probably use that next time I need CSV.
18:25stuhood~ticker RAX
18:25clojurebotRAX; -7.04
18:25AWizzArd_ah
18:26AWizzArd_~ticker CLJ
18:26hiredmanjava.io.IOException: Server returned HTTP response code: 400 for URL: http://www.google.com/finance/info?q=CLJ
18:26stuhoodhahaha
18:26AWizzArd_danlarkin: instead of a ref you can use a java.util.Hashmap
18:27AWizzArd_I mean, how does Clojure store its meta data?
18:27danlarkinAWizzArd_: but that'd still be state... but worse state
18:28hiredmana persistant map
18:28stuhoodclojure stores its metadata in a clojure datastructure
18:28clojurebotclojure is far closer to perfection then python
18:28AWizzArd_danlarkin: then how is Clojure doing it right now?
18:28hiredmanit sure is
18:28stuhoodthat's why (with-meta) doesn't modify the argument you give it
18:28hiredmanbut alter-meta! does
18:28stuhoodwell, yea... because namespaces are magical =(
18:28hiredman~def alter-meta!
18:28AWizzArd_thx hiredman
18:29hiredman,(meta *ns*)
18:29clojurebot{:killroy-was-here #<Date Sun Mar 29 14:41:43 PDT 2009>, :a 1}
18:29stuhoodhaha
18:29danlarkinha!
18:29AWizzArd_wtf? ;)
18:29hiredman,(alter-meta! *ns* update-in [:killroy-was-here] conj (Date.))
18:29clojurebotjava.lang.ClassCastException: java.util.Date cannot be cast to clojure.lang.IPersistentCollection
18:29hiredman,(alter-meta! *ns* update-in [:killroy-was-here] cons (Date.))
18:29clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: Date
18:30hiredman,(alter-meta! *ns* update-in [:killroy-was-here] list (Date.))
18:30clojurebot{:killroy-was-here (#<Date Sun Mar 29 14:41:43 PDT 2009> #<Date Mon Mar 30 15:28:43 PDT 2009>), :a 1}
18:31AWizzArd_oh
18:33lisppaste8hoeck pasted "danlarkins-with-meta" at http://paste.lisp.org/display/77793
18:33hiredman,(alter-meta! *ns* assoc :update (fn [] (alter-meta! *ns* update-in [:killroy-was-here] conj (Date.))))
18:33clojurebot{:update #<sandbox$eval__4753$fn__4755 sandbox$eval__4753$fn__4755@16aee36>, :killroy-was-here (#<Date Sun Mar 29 14:41:43 PDT 2009> #<Date Mon Mar 30 15:28:43 PDT 2009>), :a 1}
18:33AWizzArd_there you go
18:33AWizzArd_hoeck ist schnell
18:34hiredman,((:update (meta *ns*)))
18:34clojurebot{:update #<sandbox$eval__4753$fn__4755 sandbox$eval__4753$fn__4755@16aee36>, :killroy-was-here (#<Date Mon Mar 30 15:32:44 PDT 2009> #<Date Sun Mar 29 14:41:43 PDT 2009> #<Date Mon Mar 30 15:28:43 PDT 2009>), :a 1}
18:35stuhoodsomebody could probably run clojurebot out of memory like that, right?
18:35hiredmanI guess
18:35AWizzArd_yes, and hiredman would then ban her
18:35AWizzArd_:-)
18:35danlarkinwhy not add alter-meta! to the blocked forms?
18:36hiredmanbecause it's a drag
18:52devoIs there a way to defn a function with a name that is generated at runtime?
18:52devofor example, here's what I'm trying:
18:52devo(def f "foo")
18:52devo(defn (symbol f) [x] (+ x 1))
18:52Carkwhy do you want to do this ?
18:52hiredmansure
18:52hiredmanyou can use gensym
18:52hiredman(defmacro defnsym [& body] `(defn ~(gensym) ~@body))
18:52hiredmansomething along those lines
18:52Carkthat's generated at compile time
18:52hiredmanright
18:52AWizzArd_gensym is just an ordinary function
18:52hiredmanruntime
18:52AWizzArd_call it at runtime
18:53hiredmanyeah
18:53AWizzArd_And if you need many functions, then store them in a hashmap, with the name that you generate some time during runtime
18:53hiredmanI agree with Cark
18:53hiredmanwhy do you want to do this?
18:53Carkhum another question along the same line : how do you add a def to a namespace at runtime ?
18:53Carka var i mean
18:53hiredmanI would check the namespaces page on clojure.org
18:53Cark,(find-doc "ns-assoc")
18:53clojurebotnil
18:53dnolen,(doc intern)
18:53clojurebot"([ns name] [ns name val]); Finds or creates a var named by the symbol name in the namespace ns (which can be a symbol or a namespace), setting its root binding to val if supplied. The namespace must exist. The var will adopt any metadata from the name symbol. Returns the var."
18:53devoI'm reading in an XML file that represents database relationships, I was thinking I could essentially define a function for each table that contains its relationships
18:53devoso, if I have tables: A, B and C and I know A joins to B, and B joins to C, I could call something like (A (B C)) which would give me all the join info I need to dynamically build sql
18:53Carkah intern of course ><
18:53Carksot here you have it ... intern the name, then assicoate a lambda with it
18:53hiredmandevo: use a map
18:53clojurebotmap is *LAZY*
18:53hiredmanclojurebot: shut your pie hole
18:54clojurebotExcuse me?
18:54hiredmanclojurebot: you heard me
18:54clojurebotExcuse me?
18:54AWizzArd_*g*
18:55devoI'll try it. I'm still dusting the cobwebs off of my LISP.
18:55hiredmanyou most likely will want (def table-functions (ref {}))
18:57gnuvince_~seen cgrand
18:57clojurebotcgrand was last seen quiting IRC, 56 minutes ago
18:58Cark,(intern *ns* (symbol "bleh") (fn [] "bleh!"))
18:58clojurebot#'sandbox/bleh
18:58Cark,(bleh)
18:58clojurebot"bleh!"
18:59Carkhehe hiredman =P
18:59hiredman~you heard me is <reply>#who: I'm just giving you a second chance
18:59clojurebotAck. Ack.
18:59hiredman~you hear me!
18:59clojurebotexcusez-moi
18:59hiredman~you heard me!
18:59clojurebothiredman: I'm just giving you a second chance
19:00hiredmanCark: shhh
19:03Carkthough i can't imagine a single instance where creating a named function at run time would be usefull
19:04Carkmaybe creating the functional interface to an object system ...
19:05hiredmanyeah, but how would you use it?
19:05hiredmanyou need some kind of handle on the names
19:05Carkright
19:41hjleesomeone said contributors can't accept patchs from non-contributor.
19:42hjleeis that right?
19:43danlarkinthe clojure and clojure-contrib codebases cannot, yes
19:43hjleecan anyone be contributor, then?
19:43chessguyerr, is there a multi-line comment in clojure?
19:43dnolen,(doc comment)
19:43clojurebot"([& body]); Ignores body, yields nil"
19:43danlarkinhjlee: clojure.org/contributing
19:43chessguysorry, i'm new to clojure and i'm not sure how to read that
19:43clojurebotnew Class(x) is (Class. x)
19:43chessguywow, thanks clojurebot , that's helpful!
19:43chessguy:)
19:43Chousuke,(comment works like this)
19:43clojurebotnil
19:43chessguycute
19:43hjleedanlarkin: thank you.
19:44chessguyChousuke: thanks
19:46durka42,(+ #_3 4 5)
19:46clojurebot9
19:47durka42,(+ #_(this type of comment is ignored completely, not even nil) 4 5)
19:47clojurebot9
19:50gnuvince_How do I specify a type hint in a macro?
20:09chessguyso i'm looking at the macros page on clojure.org
20:10chessguyit has this example:
20:10chessguyuser=> (macroexpand '(-> {} (assoc :a 1) (assoc :b 2)))
20:10chessguy(assoc (clojure.core/-> {} (assoc :a 1)) :b 2)
20:10chessguyam i reading this right, that the -> is left in the result of the macro expansion?
20:10clojurebotthis is not a bug
20:10chessguy(macroexpand '(-> {} (assoc :a 1))
20:10chessguy,(macroexpand '(-> {} (assoc :a 1))
20:10clojurebotEOF while reading
20:10stuhoodchessguy: i think it is defined recursively
20:10chessguy,(macroexpand '(-> {} (assoc :a 1)))
20:10clojurebot(assoc {} :a 1)
20:10stuhoodso -> expands to calling itself if you give it multiple forms
20:10chessguystuhood: so the reader will automatically expand it again?
20:10chessguy(or whatever does the expansions)
20:10stuhoodi believe so... there might be another macroexpand that expands recursively like the reader would
20:10chessguyinteresting
20:10stuhood"Note neither macroexpand-1 nor macroexpand expand macros in subforms."
20:11stuhoodclojurebot was right... it wasn't a bug =x
20:11chessguyhaha
20:11chessguythat's one smart bot!
20:34gnuvince_,(let [x 0] (time (dotimes [_ 1000000] x)))
20:35clojurebot"Elapsed time: 87.759 msecs"
20:36gnuvince_,(time (dotimes [_ 1000000] map))
20:36clojurebot"Elapsed time: 103.385 msecs"
20:36stuhood,(map)
20:36clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$map
20:50hiredman,(let [x map] (time (dotimes [_ 1000000] x)))
20:53clojurebot"Elapsed time: 86.389 msecs"
20:53durka42so the 20ish ms comes from looking up vars?
20:53texodusIs there any way to check the metadata of a symbol passed as an argument to a macro?
20:53hiredmanyes
20:53hiredmanwould you like to know what it is?
20:53durka42#^symbol
20:53durka42that's not it
20:53durka42^#'symbol if you want the metadata of the var that the symbol names
20:53texodusreader metadata?
20:53dnolendurka: i don't think will work from the macro because it's a reader macro, you'll have to use (meta (var sym)), am I wrong?
20:53texodushmm - when I use ^#'symbol in a defmacro, it does not compile
20:53dnolen#' is a reader macro
20:53dnolenso it won't work from your macro definition.
20:53texodusah, makes sense, the symbol is not bound yet
20:54durka42(meta (var symbol))
20:54durka42maybe `(meta (var ~symbol))
20:55durka42,(let [s 'map] (macroexpand `(meta (var ~s))))
20:55clojurebot(clojure.core/meta (var map))
20:55durka42,(macroexpand '^#'map)
20:55clojurebot(clojure.core/meta (var map))
20:58slashus2ThreeBot: clj (print "Test\nQUIT :This bot has been hacked")
20:59slashus2Sorry, pasted it wrong.
20:59texodus(var symbol) causes this same problem
21:00dnolenyeah because var is a special form
21:00texodusic
21:08lisppaste8dnolen pasted "macro to grab meta on var" at http://paste.lisp.org/display/77797
21:11dnolentexodus: hopefully that will help, if anyone knows a better way please chime in.
21:11dnolenqualify-sym is Chouser's great handywork, lifted from error-kit
21:15slashus2hiredman: If you ran (print "Test\nQUIT :test") on your bot would it run the QUIT command? It did on mine :-( I had to strip out \n and \r to keep that from happening.
21:15hiredman,(print "Test\nQUIT :test")
21:15clojurebotTest QUIT :test
21:15hiredmanis there a QUIT command?
21:16hiredmanI am not aware of one
21:16durka42(.write *out* "Test\nQUIT :test")
21:16durka42,(.write *out* "Test\nQUIT :test")
21:16clojurebotTest QUIT :test
21:16slashus2The reason it worked on my bot is because it printed the lines by themselves.
21:16hiredmanwell, I strip newlines anyway
21:17slashus2I am doing that now.
21:17slashus2QUIT makes it leave the network.
21:17hiredman~quit is <reply>QUIT
21:18clojurebotc'est bon!
21:18slashus2Apparently. That is what it did to mine.
21:18hiredman~quit
21:18clojurebotQUIT
21:18slashus2If you turn off line stripping, and run that command, it will work.
21:18slashus2You can also make it send private messages that way too.
21:32texodusah, this works well, thanks dnolen
21:34dnolentexodus: cool.
21:48chessguyare there other code-as-data languages, besides lisps?
22:33danlarkinAw nuts:
22:33danlarkin,(instance? clojure.lang.IObj (delay))
22:33clojurebotfalse
22:33hiredman,(ancestors (class (delay)))
22:33clojurebot#{clojure.lang.IDeref java.lang.Object}
22:33hiredmanyou could proxy IDeref IMeta and IObj
22:35danlarkinyeah I could proxy clojure.lang.Delay
22:44hiredmanDelay takes a Fn
22:50hiredmanI guess you could just use a atom
23:29arohnerrhickey: can you please go into more detail about why (get ref :foo) should return nil?
23:32danlarkin(delay (println "foo"))
23:32danlarkin,(delay (println "foo"))
23:32clojurebotfoo #<Delay@1bce011: nil>
23:32danlarkinwhy does that print foo without the delay having force called upon it?
23:32hiredmanprint a delay drefs it
23:32danlarkindoh
23:33danlarkin,(let [d (delay (println "foo"))] 5)
23:33clojurebot5
23:33danlarkintada
23:38danlarkinwow... that was a really annoying bug to track down
23:39danlarkinand it was, of course, entirely my fault
23:39danlarkinclojurebot: map?
23:39clojurebotmap is *LAZY*
23:39danlarkinyes, yes it is
23:52gnuvince_-Xprof reports that 20% of my program is spent in java.lang.reflect.Array.set; I have a type hint for that array, is there anything else to avoid reflection?