#clojure logs

2009-06-23

00:10ninjuddcan anyone here answer a question about zippers and clojure.zip?
00:12ninjuddspecifically, i'm wondering why clojure.zip/down will descend into non-branches, while clojure.zip/next obeys the branch? function that is passed into zipper
01:01cp2hi there
01:01cp2local barns and noble has stuart's book
01:01cp2i flipped through it
01:02cp2pretty good for a new clojure programmer
01:02cp2good style etc
01:10lowlycoderin clojure, can i have threads that don't share haeaps?
01:10lowlycoderi.e. shared nothing, that can communicate only via message passing?
01:36justin`Anyone know how I can change the directory my REPL is looking in with slime?
01:37justin`or at least how to find out where it's looking
01:37Lau_of_DKJava has a userDir variable as I recall, that'll tell you where you are
01:38justin`ehh sorry how do I phrase that in clojure? I'm still really new at this
01:42xenoLau_of_DK: I don't remember if it has, but if not, it should be as easy as new File('.').getCanonicalPath();
01:42xenoonly needs to be performed once, since there's no chdir
01:43justin`hmm so how would I say that in clojure?
01:44xenoI don't know, got my clojure book yesterday :)
01:44justin`lol k
01:44Lau_of_DK(.getCanonicalPath (java.io.File. "."))
01:44justin`I ordered mine today heh
01:44Lau_of_DK(usually you'll want to import java.io File though)
01:45justin`ok sweet that worked thanks a lot
01:46Lau_of_DKnp
03:13combas3dsorry if this gets asked a lot, but I see that richhicky and kevinoniel both have clojure-contrib packages on github which do I use?
03:16combas3drich package is only 1mb and kevins is 2.9mb and the documents on installing clojure say to use kevins but that seems strange to me, can anyone explain the difference?
03:21combas3d*crickets*
03:25hiredmancombas3d: use richs
03:26hiredmankevin's was an unofficial github mirror of the svn repo, but now clojure and contrib have moved to github
03:26hiredmanso outdated instructions my refer to kevin's mirror
03:27combas3dthanks that makes sense, just the difference in file size worried me and both seemed to be active so I was confuzled
06:45frodefI need to capitalize a string, but I'm not sure what's a good way to iterate over a string while building a new one..?
06:47AWizzArdfrodef: strings are immutable. There is no other option that that.
06:48frodefSurely there's an option of building a new string that is a capitalized version of the old one?
06:48mccraigfrodef: u no want the java method ? : (.toUpperCase "foo")
06:48mccraigor u mean just cap the first letter
06:48frodefmccraig: right, first letter only, possibly first letter of each word.
06:49AWizzArdI was looking for this some days ago. I did not find a built in method to do that.
06:50AWizzArdfor code that does not need to be very time efficient you could call .split and .toUpperCase
06:50frodefbut how would you do it yourself? With all this immutability, I only see rather awkward ways of doing it..
06:55AWizzArdfor me it was not time critical, I just splitted at spaces, then built a sequence of capitalized strings and glued them together
06:55AWizzArdthere are also string buffers for doing this efficiently
06:56frodefok, thanks.
06:56AWizzArdyou could use something like this: (defn capitalize [string] (apply str (.toUpperCase (str (first string))) (rest string)))
06:57AWizzArdand then (apply str (map capitalize array-of-splitted-strings))
06:57AWizzArdit's not efficient, but easy and maybe enough
07:11achimstr uses a StringBuilder internally, so it should be reasonably efficient
07:16AWizzArdyes, but first splitting the string means to create several new ones. Then reading the first element and stringing it also, then rebuilding it via toUpperCase plus building all the rest strings, and then in the end concatenating them again is not too efficient for some specific cases.
07:17AWizzArdbtw achim, are you still in the south or back in the west? :)
07:17achimstill in the south :)
08:22lisppaste8guille_ pasted "What's up with this ArrayList?" at http://paste.lisp.org/display/82333
08:23guille_creating an ArrayList, clojure just 'gets' a Class, so it doesn't reach the .add method when doing reflection. what's wrong with this code?
08:28guille_found, i omitted the new func. over the class name
08:35AWizzArdI have (doseq [s ["hello", "world", "and", "moon"]] (println s)) with output "hello\nworld\nand\nmoon\n" but I want "1. hello\n2. world\n3. and\n4. moon\n" as output. What is the idiomatic way to do this?
08:43Chouser(use 'clojure.contrib.seq-utils)
08:43achimAWizzArd: how about (doseq [[i s] (indexed ["a" "b"])] (printf "%s. %s\n" (inc i) s)) ? indexed is from contrib.seq-utils
08:43Chouserachim: I have that loaded in my paste buffer. :-)
08:44ChouserOh, but I used println and str instead of printf. *shrug*
08:45AWizzArdAh good, indexed sounds fine, didn't remember it.
08:45AWizzArddanke
08:46Chouser"But, a few warts aside, I find very little to complain about with Clojure. It’s actually gotten me back into coding in my free time which I haven’t done in years." ...fascinating. I think that really says something.
08:46achimChouser: heh - there's a reason why some IM apps do these "is typing" notifications
08:49rhickey_ proposal for template/are: http://groups.google.com/group/clojure-dev/msg/2df101865a378156
08:52ChouserI've not used 'are', so my opinion here is worth even less than usual. ...but that doesn't mean I don't have one. :-D
08:52rhickey_and it is?...
08:52Chouserhaving said that, I really like the explicit arg list
08:53Chouser_1 _2 seemed a bit ugly and awkward to me, even without the different arg counts compared to #()
08:56rhickey_the only excuse for #() is when the fn is tiny, it removes 2 grouping constructs #(foo) vs (fn [] (foo)), and thus enhances the readability of the enclosing block (at least when the body is small, when large not worth it), esp (map #() ...). For these tests it seems the test bodies and args etc dominate the size, and there isn't an enclosing context
08:57rhickey_the eval-once aspects of template surprised and confused me greatly
09:00ChouserI'd never looked at it closely enough to see that. In fact, I'd have to look at it more to understand.
09:01ChouserAh, that's the "Any sub-expressions without any _* variables are evaluated when the fn is created, not when it is called." part.
09:02ChouserThe few clojure-test tests I've written just used 'is' because I was too lazy to take the time to understand 'are'. :-P
09:03Chouserthough it's really great that someone built a good enough framework early enough that we can already have so many regression tests.
09:03ChouserI think that puts Clojure in a better position that it otherwise would be now.
09:04ChouserI have written a batch of JUnit tests in Clojure for work. Not so nice.
09:04Chouserheh, #^lift is cute
09:05AWizzArdNow that the Summer has begun more people will become interested in programming again, and also into Clojure.
09:06ChouserAWizzArd: really?
09:06AWizzArdBetween February and May lots of people lose their interest.
09:06ChouserWhy is that?
09:06mblinnseasonal programming depression
09:06AWizzArdIn many programming channels the number of users goes down. Also the number of posts in newsgroups.
09:12rysfinancial year seasonal programming disorder....sounds like a wikipedia page in the waiting
09:13rhickey_Chouser: yes, the tests and the framework are great to have, just trying to use care when moving across to clojure proper
09:14Chouserrhickey_: yes. I fully agree with being careful, but it can be hard to take having a lot of people concentrating on the weaknesses of your code -- I'd hate for anyone to feel belittled when nothing like that is intended.
09:15ChouserSo I just wanted to mention that it's good we have a testing code base like this to critique. :-)
09:19nsinghalI am doing gen-class, one of the method should return a String array (String[]). How can I define that in the :methods?
09:22hoeckWRT 'are': I have found it to be really useful in the last two days, though I would prefer a cleaner approach than the template expansion
09:23Chouser,(class (make-array String 0))
09:23clojurebot[Ljava.lang.String;
09:23Chousernsinghal: so probably use a string instead of a bare symbol: "[Ljava.lang.String;"
09:23Chousernsinghal: there may be a better way, but I think that will work.
09:30nsinghal(:gen-class :name MyClass :methods [#^{:static true} [getEntries [Integer] StringArray]])
09:31nsinghalBoth [Ljava.lang.String; and (class (make-array String 0)) dont work here.
09:32rhickey_Chouser: yes, I'm familiar with that feeling :)
09:32rhickey_gotta run
09:35lenst#=(class (make-array String 0))
09:37Chouser:methods [#^{static true} [getEntries [Integer] "[Ljava.lang.String;"]]
09:41lenst,'#=(java.lang.Class/forName "[Ljava.lang.String;")
09:41clojurebot[Ljava.lang.String;
09:45kefka,(into-array (Byte/TYPE) [86 87 88])
09:45clojurebotjava.lang.IllegalArgumentException: argument type mismatch
09:45kefka,(into-array (Integer/TYPE) [86 87 88])
09:45clojurebot#<int[] [I@6231ed>
09:50nsinghalThanks for help. #=(class (make-array String 0)) caused clojure.lang.PersistentList to be returned. "[Ljava.lang.String;" worked.
09:53Chouseryou could also do something like: (defn array-type-str [t] (.getName (class (make-array (resolve t) 0))))
09:53Chouserthen use #=(array-type-str String)
09:57nsinghalChouser: I am using (ns ... (:gen-class ... #=(array-type-str String)...): getting Can't resolve array-type-str. I will have to define it in some other library and than do ":use"?
09:58Chousernsinghal: hm, I yeah that's a bit awkward isn't it.
09:58Chouserthe literal string that you already have working is probably the "normal" way right now.
09:59Chouserif you want to use something like array-type-str, it would be best to put it in a specific other namespace first.
09:59nsinghalChouser: thanks - using it and it works fine
09:59nsinghalyup
09:59nsinghalthat can be a good utility fn
10:00Chouser...and even then, you couldn't rely on a :require from the ns form you're doing :gen-class in to bring in that other namespace, because the #=() would happen too early.
10:01Chousera bit of a mess, altogether. Probably the right solution would involve adding a special case to gen-class for arrays.
10:02nsinghalyup - i like the simple solution you gave me before. could use a explicit special reader macro or something for gen-class
10:08AWizzArdI get a sequence of refs of hashmaps: (filter #(= (:type @%) :category) (find-objects word)). Should this line of code be embedded into a dosync? I would think yes, because in principle the refs returned by find-objects could be changed while filter is running.
10:10Chousukeif the hashmaps aren't independent, why not use single ref?
10:11AWizzArdThey are small objects that may be changed.
10:12Chousukethey could still be in a single ref.
10:12Chousukeespecially if they're small
10:12ChouserAWizzArd: the list itself won't change, but if you need a consistent snapshot of the values in the refs, then yes you want a dosync
10:14ChouserChousuke: if there are lots of threads working on the refs, but generally only change one or two refs per transaction, wouldn't it make sense to have lots of little refs?
10:15ChouserIf it was one ref, wouldn't that be an unnecessary bottleneck?
10:16ChousukeChouser: but the transactions would be commutative wouldn't they? It might still work.
10:17Chouserit would work, but they'd have to go in order.
10:17Chouserit would still be "correct" but I think it might be less efficient than it could be.
10:18Chousukeit'd be a lot simpler though :/
10:19AWizzArdI have a ref on a set of refs on hashmaps, and I need that.
10:21Chousukeif you're going to have things often "locking" all the refs for reading, it's going to hurt performance.
10:23Chouserbut a dosync that just reads doesn't need to block writers or other readers.
10:23Chousukedoes it need a dosync? wouldn't a (doseq [x refs] @x) do?
10:24Chousukeit has to be non-lazy, anyway
10:27Chousukeexcept not doseq but the other thing that returns the results :P
10:58AWizzArdyes, i think my example with filter from above would require a doall
10:58AWizzArdwhat if my filter inside a dosync wants to return a lazy seq of two objects, i read one, wait 5 minutes and read the second?
10:59ChouserI assume returning a lazy seq to outside the dosync has the same kinds of problems as lazy seqs and any other dynamic scope.
11:00Chouserthat is -- the transaction will be gone, and you'll end up doing a flying read when the lazy seq is realized.
11:59_hrrldI've been using println to report some status to stdout, but now I don't want the newline, so I switched to print, but now it doesn't seem to be flushing the stream. Do I need to do something explicit to flush the stream when using print instead of println?
11:59Chouseryes. (flush)
12:00_hrrldheh, I should have guessed... Thanks, that works a treat.
12:00gnuvince(doc flush)
12:00clojurebot"([]); Flushes the output stream that is the current value of *out*"
12:00gnuvinceneat
12:01gnuvinceI always used the Java interop to do that
12:01lpetitHi, a quick tour in #clojure for gathering more feedback for the new name of clojure-dev :-)
12:01Chouserit's amazing how long you can use clojure and still find new little tidbits like that.
12:01ChouserI haven't fully integrated select-keys into my toolbox yet.
12:01Chouserlpetit: welcome!
12:02Chouserlpetit: this is the IntelliJ plugin?
12:02lpetitThis is the eclipse plugin
12:02Chouseroh, sorry.
12:02lpetitno problem !
12:03lpetitSo far we have as candidates : cljdt (clojure development tools) , eclojure , eclipje , clojure-eclipse and some exotic variations : Clojipsy , eclojion
12:04lpetitSome have argued that eclojure may be too close to enclojure (netbeans plugin), but I can't ban it since it seems to me very appropriate as a contraction of eclipse and clojure ... what do you think ?
12:06ChouserI agree it's too similar. I suppose eclipsjure or something might be ok.
12:07ChouserPersonally I'd vote for clojure-eclipse, though I'd understand if you found that too vanilla.
12:07clojurebotfor is not used often enough.
12:08lpetiteclipjure ?
12:08lpetit:-$
12:09cemerickcljdt is very eclipse-esque. I'm not in that world anymore though :-)
12:09lpetitwell, sometimes you don't have a choice, and make the best you can with the tools you have :-)
12:10lpetitcljdt is close to the matching criteria, but I'm looking for a way to make a more pronounciable variant of it ( some vowel would be welcome :-)
12:11Chousercloj-dot
12:11lpetitwhat rationale behind cloj-dot ? (would'nt it be more appropriate for the visual studio dot net - still missing :-) - plugin ?
12:12Chouserjust inserting vowels in cljdot
12:12lpetitah ok you added the missing vowels
12:12Chouser:-)
12:12Chousernot very original, I know.
12:14Chousukemakes me think of "clod" :P
12:15lpetitBTW , do you know, in the 'enclojure' name, if there is an implicit reference to netbeans ? (for example, if we choose cljdt, this will really be an implicit/cryptic reference to eclipse for even eclipse users that don't know JDT and CDT are the names of the java/c/c++ eclipse environments)
12:19dhazacljdt looks like line noise
12:20dhazabut i guess it would be good for getting relevant information from google searches
12:20lpetiteclipjure ?
12:21Chousukeno more jures please ;/
12:21cp2my local barnes and noble has stuart's book
12:21cp2i looked through it a bit
12:21cp2pretty good
12:22lpetitWell, we have enclojure , vimClojure , why should the eclipse plugin be excluded from the trend ? :-)
12:23cp2clojure-mode ;P
12:24lpetitChristophe suggested eclojion . What do native english speakers think about placing j and i so close ? would it be easy to spell ?
12:24clojurebotWhat is meta
12:25lpetitIt's been a long time since I've been here on #clojure. Does clojurebot start to live its own life, or can someone explain me why it is intervening from time to time ? :-)
12:25lpetiteclojion would avoid having another "jure" :-)
12:26ChousukeBut it looks weird :P
12:26dhazaclojumbra
12:26dhazasee what i did there
12:29Chouser~I was trying to think of a good name, when suddenly...
12:29clojurebotCLABANGO!
12:30justin`what about Clabing, what lisp needs is a good rebranding
12:30Chousuke:P
12:31lpetitChouser: did I miss something ?
12:32Chouserhm? I don't think so.
12:33lpetitChouser: when you wrote with the side effect of having clojurebot say "CLABANGO!"
12:33lpetitChouser: did you just want to make this effect, or your sentence really was not ended ? :-)
12:34_hrrld~hmmm, when suddenly...
12:34clojurebotCLABANGO!
12:34Chouserlpetit: just the effect. A joke. Unless of course you like the name clabango.
12:34lpetit_hrrld: yes, I have since understood how it works :-)
12:34ChouserIt's a good name looking for a project.
12:35dhazais cluje taken?
12:35dhazacrajy
12:35dhazayo dis shit is crajy man
12:35Chousukej is overused :>
12:36lpetitclabango would have little to do with eclipse and clojure (but still starts with cl) but it indeed looks nice. But I can see an already existing project created by Lau of DK on github :-(
12:36lpetitwell, Lau of DK == Chouser ?
12:37lpetitno wait, sorry
12:38lpetityes, j is overused, jure is overused, but we're speaking about a project forced to change its name !
12:40lpetitI must leave, thanks for sharing your thoughts (and since I don't track #clojure regularly, please answer to the "poll" on the clojure ml if you have an interesting suggestion, so that I don't miss it)
12:40lpetitCU
14:13technomancyow my eyes!
15:23vagifHello, any compojure users ?
16:06ninjuddanyone who can answer some questions about the clojure zipper library?
16:07kotarakninjudd: well... just ask your questions and we'll see...
16:08ninjuddok. i have some metadata stored on my nodes, and it seems like doing a replace and then a call to root is removing it
16:09kotarakThe zipper library uses the metadata... Just a sec...
16:10hiredmanand it uses with-meta
16:10ninjuddi can make the nodes a heavier structure and write my own branch? and children methods, but it seems like the metadata on nodes shouldn't be removed
16:10hiredmanwhich overwrites the metadata map
16:10ninjuddunless clojure doesn't allow metadata on an array and items in the array
16:11Chouserzip-filter decorates zipper nodes with its own meta-data tag.
16:11hiredmanninjudd: do you really mean array, or do you mean vector?
16:12hiredmanmetadata cannot be added to arrays
16:12ninjuddit seems like clojure.zip adds metadata to the zipper data structure (which is an array of two elements), but i can't see where it adds metadata to the nodes themselves
16:12ninjuddsorry.. i meant vector
16:12hiredmanninjudd: not an array
16:12kotarakhmmm... But zip uses metadata on a vector containing the node, that shouldn't affect the node itself, no?
16:12ninjuddkotarak: right, that's what i though
16:12ninjuddthought
16:13hiredmanah, right
16:14kotarakBut up makes a new node. ninjudd: do you provide your own make-node?
16:15ninjuddno
16:16ninjuddi think that's it. i need to write my own make-node that preserves metadata
16:17ninjuddhmm.. it looks like i may have to patch clojure.zip/up and down to preserve metadata
16:17kotarakninjudd: no. That should not be necessary.
16:19ninjuddkotarak: you're right. the problem is that vector-zip's make-node ignores the previous node altogether
16:20ninjuddso i can either patch vector-zip or call zipper directly
16:20kotarakIt should probably transfer metadata if there is.
16:20Chouserkotarak: yeah, sounds right to me.
16:20kotarakShall I add a ticket and provide a patch?
16:21Chouserkotarak: only rhickey can make that call.
16:21ninjuddyep, calling zipper directly works. i can submit a patch to seq-zip and vector-zip on github
16:21Chouserif rhickey doesn't respond here, you can mention it on the google group.
16:21ninjuddok
16:22ninjuddone more question about zippers:
16:22Chouserninjudd: a patch would be welcome if you've submitted a CA, but please see http://clojure.org/patches
16:22ninjuddit seems like zip/down will descend into things that aren't branches
16:22ninjuddwhile zip/next will skip them
16:22kotarakI have CA filed. I'll see, whether I get git running. :)
16:23ChouserOops. I think "a patch will be welcome" is exactly what I'm not authorized to say. :-P
16:23kotarak~bat light
16:23clojurebotIt's greek to me.
16:23kotarakHmm.. Ok.
16:23ninjuddkotarak: ok, i'll read the patches page first
16:24kotarakrhickey: should vector-zip and seq-zip move metadata if available when creating a new node?
16:26ninjuddkotarak: did you catch my second zipper question, or did it get lost in the stream?
16:27kotarakoeh... the one about down?
16:27ninjuddyeah
16:27ninjuddbasically, zip/down doesn't obey branch?
16:28rhickeykotarak: yes, patch welcome
16:28kotarakk
16:32hiredmanninjudd: eh?
16:33ninjuddrhickey: thanks, i'll send a CA and submit the patch on github
16:33ninjuddhiredman: eh, what?
16:36hiredmanhow does down not obey branch?
16:37ninjuddvector-zip defines branch? to be vector?, but it will still descend into non vectors
16:38hiredmanah
16:38hiredmanexplains why I never ran into that (never did zippers on vectors)
16:38hiredmanhmmm
16:39hiredmanseq-zip does it too
16:39hiredman:(
16:39hiredmanwell, I suppose that sort of makes sense
16:39ninjuddfor example:
16:39clojurebotfor is not used enough
16:40ninjudd(-> (clojure.zip/vector-zip '[(1 3) (2 4)]) clojure.zip/down clojure.zip/down)
16:40ninjudd=> [1 {:l [], :pnodes [[(1 3) (2 4)] (1 3)], :ppath {:l [], :pnodes [[(1 3) (2 4)]], :ppath nil, :r ((2 4))}, :r (3)}]
16:40ninjuddit should not descend into the sequence, right?
16:40hiredmanninjudd: I agree
16:41ninjuddhiredman: seems like it should just return nil if you try to descend too far, right now it throws java.lang.IllegalArgumentException
16:44ninjuddmaybe i'll work on a patch for that too
16:44kotarakok. ticket created with patch attached.
16:45kotarakI didn't find the "Choose an action..." though...
16:46ninjuddkotarak: is that a patch for the vector-zip thing? or something else?
16:46kotarakthe metadata thing in the zipper
16:47ninjuddoh sweet, thanks!
16:47kotarak#134
16:47bpattisonis there an easy way to get the count/length of a list?
16:47kotarak(doc count)
16:47clojurebot"([coll]); Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Java Collections and Maps"
16:48bpattisonthanks
16:48kotarakbeware of (iterate inc 0) ;)
16:49bpattisonlol -- wouldn't be the first time I had a stack over flow
16:50ninjuddkotarak: what do you think about a patch for the branch? issue with zip/down?
16:51kotarakninjudd: well.. that's rhickey 's decision. If you says, yes, I can provide one.
16:51kotaraks/you/he/
16:52ninjuddrhickey: what do you think? should zip/down refuse to descend when branch? is false?
16:52rhickeyninjudd: it is refusing to descend
16:54ninjuddrhickey: are you sure? try (-> (clojure.zip/vector-zip '[(1 3) (2 4)]) clojure.zip/down clojure.zip/down)
16:57rhickeyninjudd: ah, I thought it threw and you wanted nil
16:57ninjuddor it could throw an exception
16:57kotarakdown only checks whether there are children, vector-zip uses seq for children, it doesn't check for branch?
16:58ninjuddrhickey: right now, it just descends into the list
16:58ninjuddkotarak: oh right, this could also be fixed through a patch to children
17:00kotarakhmm... Is it better to check for branch? in down and throw an exception? Or should it just ignore the fact and return nil for children of nodes for which branch? is false?
17:02ninjuddif you do the check in (defn children... then you can keep the calls to zipper simpler and you get it for all future zippers too
17:04ninjuddperhaps.. (if branch? ((:zip/children ^loc) (node loc)))
17:09rhickeychildren could check if node is branch and throw if not
17:09kotarakrhickey: should it throw or return nil?
17:11rhickeythrow
17:11kotarakk
17:25ninjuddyeah, throwing is more consistent with the rest of clojure.zip
17:26ninjuddkotarak: thanks for the quick response and patches!
17:26kotarakticket #135 with patch created
17:26kotaraknp
18:55krumholt_how can i exit the repl?
18:57ataggartctrl-D ?
18:58krumholt_oh thanks :) i tried (quit) and (exit) and lots of others
18:59ataggartheh
19:00ataggartthis would work too: (System/exit 0)
19:10hiredmanI bought programming in clojure last night from amazon, today I was at barnse and noble and they had two copies, then when I got home my copy was waiting in front of my door
19:11slashus2It is neat that they have it at b&n.
19:31cp2hiredman: same
19:31cp2well, the b&n part
19:52krumholt_i am trying to run the ant.clj example. it is working but the window is not repainting. what could be the problem?
22:19hiredmanhttp://sellmic.com/blog/2009/06/11/classpath-hell-just-froze-over/ <-- java module system
22:25holmakhiredman: !
22:25holmakhiredman: Good catch!
22:27hiredmannah, just repasted from #java
23:35plymouthah friends, it doesnt matter if you're a man or a woman if you're in love with someone these are the words you've gotta learn to say
23:38hiredmanclojurebot: ping?
23:38clojurebotPONG!
23:39holmakdon't provoke the bot, man