#clojure logs

2009-07-04

00:00jackdempseyspeaking of offlining
00:00jackdempseyany there any well vouched for solutions for small simple db solutions
00:01jackdempseylike, i've used sqlite before, and can be useful in certain cases
00:01jackdempseyjust wondering if there's anything idiomatic or preferred
00:01Knekkhow simple?
00:01Knekkkey/value?
00:01jackdempseysure
00:02Knekkbdb is good
00:02jackdempseysomething that you can install in a few minutes and quickly store things/retrieve them......i'm familiar with a variety of solutions, but not used to connecting to them from clojure
00:02jackdempseyok
00:02Knekkmemcachedb is also nice
00:02jackdempseyyeah
00:03jackdempseylooks like there's some driers for sqlite
00:03jackdempseywill have to check that out as well
00:03jackdempseythanks Knekk
00:03Knekkspeaking of which, maybe I'll use memecachedb for offlining.
00:09fooxhi, anyone pls help;
00:10fooxI have two sub expression inside a Let; The second expr evaluates before the First; How can I overcome this?
00:10Knekkhow do you know it evaluates first?
00:11fooxI was not getting result. So I added println in the first expr;
00:12fooxThe second expr displays a JFrame;
00:12fooxafter displaying the JFrame; the Println in the first expr printing...
00:13Knekkfoox: do you know about lazy-seq ? They won't evaluate until needed
00:13fooxyes, My first expr is doseq
00:14Knekkthen it might help if you show some code
00:19fooxKnekk: pasted here : http://paste.lisp.org/display/82989
00:21fooxin that I'm just trying to fill a TimeSeries object and display it with JFreeChart
00:22Knekkdid you try wrapping with (do ... ) to make sure they are called sequentially?
00:23KnekkI am pretty new at this myself, so I am not sure I am helping at all
00:24ykphuahcan i use clojure to make classes in lisp that java classes use?
00:26fooxKnekk: do didn't help me out.
00:27Knekkfoox: someone more experienced might know. Sorry
00:28fooxKnekk: ok thanks.
01:00Lau_of_DKGood morning guys
01:01jackdempseymorning, whew, you must be in europe?
01:02Lau_of_DKDenmark to be exact
01:02jackdempseyah, cool
01:02Lau_of_DKWhy?
01:02jackdempseyoh, no reason, was just thinking its 1am here
01:02jackdempseyabout time for sleep
01:02jackdempsey(washington, dc)
01:03jackdempseyjust trying to figure out some simple java stuff
01:03jackdempseywas looking to do some stuff with JSON
01:03Lau_of_DKYes that can be painful at 1 am :)
01:03jackdempseyfound this collection of classes
01:03jackdempseyno kidding :-(
01:03jackdempseyi thought i'd be smart and package up the .java files in a jar
01:03jackdempseythen import them
01:03jackdempseybut i'm doing something stupid
01:03Lau_of_DKhehe
01:04Lau_of_DKI remember one such night - I asked Cemerick to take a look, I couldnt work it out - We spent 2.5 hours debugging the stuff over IRC... painful
01:04jackdempseyha
01:04jackdempseyi think this is simpler
01:04jackdempseyi'm just so out of practice with java
01:04jackdempseyis it common to create a jar by doing jar cf json.jar json/*.java
01:05jackdempseyor do i need to compile those java files first perhaps
01:06Lau_of_DKYou should make a build.xml which describes the project, and then ant build it. If you need inspiration, you could have a look at ClojureQLs build.xml, just dont get distracted by the Ivy references
01:08jackdempseyhmm
01:08jackdempseyok, what are my options for going simpler than that....basically, i'm surprised this person didn't jar up those java files.....but if i want to just include a class straight away
01:08jackdempseyas long as its in the path i should be able to use import right?
01:09Lau_of_DKI guess in principle you could run javac on every java files, giving you the class file, and then you could zip it to a jar, lemme see if I can find a link
01:10Lau_of_DKhttp://www3.ntu.edu.sg/home/ehchua/programming/java/J9d_Jar.html
01:10Lau_of_DKThat might help you
01:11jackdempseyhaha, yeah i'm doing that right now :-)
01:11Lau_of_DKI would go for the build.xml
01:12fooxis there any doc regarding working with side-effects & clojure?
01:12Lau_of_DK(doc doseq) ? :)
01:16jackdempseyah, don't know how i missed this: http://github.com/danlarkin/clojure-json/tree/master :-)
01:17Lau_of_DKYea Dan's a good guy - I've also learned that when it comes to web-technologies, Blackdog is always the first guy to get something running - Look him up, either on Github or on Pastebin
01:17jackdempseyblackdog, ok cool, don't recognize
01:18Lau_of_DKHe sent me a Clojure/Servlet/JSON/JQuery example about a year ago I think
01:21jackdempseyah ok cool
01:28fooxLau_of_DK: thanks
01:29Lau_of_DKDid it help?
01:30fooxyes, it works; but i dont know i'm doing it in the right way. I will paste the code
01:31Lau_of_DKk
01:31fooxhttp://paste.lisp.org/display/82992
01:32Lau_of_DKThe first doseq [] - Is that just to keep it going ?
01:33fooxwithout that it didn't work
01:34fooxI gave it to do the second (.addSeries ts-col ts) and third expr to eval sequentially.
01:34Lau_of_DKI dont think you need to forsake the functional approach for this. You could define your ticks as an infinite sequence, and perhaps send off and agent that'll pull out the next record every second or so?
01:34Lau_of_DK>>>>>>>>>>>>>
01:34Lau_of_DKoops
01:35fooxI have to add all items in a java object (TimeSeries object)
01:35hiredman~ping
01:35clojurebotPONG!
01:36fooxgiven in the line -- (.add ts (Second. (first tick)) (second tick))))
01:38Lau_of_DK(map #(.add ts (Second. (first %)) (second %)) ticks), and then its a seq
01:39fooxit will be a lazy-seq? ??
01:39Lau_of_DKYep
01:40hiredmanmap is lazy
01:40fooxso the ts object would have not been affected, right??
01:40Lau_of_DK(first seq) = ts is affected once, (take 5 seq) = ts is affected 5 times, and so on
01:40Lau_of_DK(count seq) = it runs ad infinity
01:41fooxts is not a list object. it is a custom java class (TimeSeries)
01:42Lau_of_DKSure
03:29unlink1Is lazy-cat new?
03:31unlink1And how is it materially different from concat?
09:10powr-tocI'm struggling to get a multimethod to dispatch on the values of a string
09:13lisppaste8powr-toc pasted "multi method dispatch on string value?" at http://paste.lisp.org/display/83007
09:13powr-tocany ideas how to get it working?
09:15lisppaste8powr-toc annotated #83007 "At the REPL" at http://paste.lisp.org/display/83007#1
09:18JAS415hmm
09:18powr-tocIt returns a NullPointerException, which I think can be fixed by using a :default ... but the dispatch then only ever uses the default
09:18fulletsIt works for me if you use a real fn instead of using the callable map
09:19fulletsI notice one of the optional arguments to defmulti is a map - is it perhaps misinterpreting that argument?
09:20fulletsIn fact, how about (defmulti testmulti "" {} { "FOO" :foo }) etc
09:21powr-tocCheers
09:21powr-tocthat works
09:22fulletsYou may be able to omit the empty docstring too
09:23Chouserfullets: good catch. Does seem a bit unfortunate though, doesn't it?
09:23powr-tocyeah you can... my bad... should have seen the attr-map
09:24Chouserit's not a problem with defn because in that case you use def which doesn't support an attr-map
09:36Chousukehm
09:36Chousukethe --patience switch to git diff/format-patch produces much more readable diffs :P
09:42fulletsChouser: something like changing the first binding of m in defmulti to (if (and (map? (first options)) (second options) (not (map? (second options)))) ...) would de-unfortunate it, but seems awfully un-clojurey
10:42Chouserfullets: hm, I dunno. That seems pretty reasonable to me.
11:14jackdempseyhey all, is this the most common way to do a val[:foo] || "test" type of construct?
11:14jackdempsey(or (y :namebar) "Baz")
11:28Chouserjackdempsey: (:namebar y "Baz")
11:28jackdempseyahh, yeah i thought there was a quicker way like that. awesome, thanks!
11:29Chouserthat form is slightly different in that if the value of y at :namebar exists but is nil or false, it'll return that actual value not "Baz"
11:38jackdempseyhmm
11:38jackdempseyahh
11:39jackdempseyso if the key is there
11:39jackdempseyyeah
11:39jackdempseycool i think this shoudl work fine, thx again
13:31somethingI'm on mac osx using aquamacs, I noticed when I use test-is and run-tests doesn't show me the results.
13:35somethingso in order for me to see the results I have to eval *test-out*, on my other machine (ubuntu) it outputs to repl.
13:38drewrsomething: Have you restarted your JVM to make sure?
13:39somethingdrewr: yes, I have, not sure what's going on here.
14:25jackdempseyso if i had a ref like this (def DB (ref {:channels #{}, :subscribers #{}}))
14:25jackdempseyand i'd like to add elements to the :channels set
14:26jackdempseyi'm stumped at how to reach inside...(alter DB conj {:channels id}) isn't working quite the way i'd like
14:26jackdempseyany tips?
14:29Chousukehmm
14:29jackdempseyah
14:29Chousukejackdempsey: (alter *db* update-in [:channels] conj channel)
14:29jackdempsey(alter DB conj {:channels (conj (@DB :channels) id)}))
14:29jackdempseyahh
14:30jackdempseycool, my janky way works it seems, but thought htere must be a nicer way to do it
14:30Chousuke*db* being more idiomatic naming than DB
14:30jackdempseyk, gotta learn update-in
14:30jackdempseyyeah, nice, thank you
14:30Chousukejackdempsey: there's also assoc-in and dissoc-in
14:30jackdempseynice, update-in is perfect
14:30jackdempseyah ok
14:32jackdempseyyep perfect
14:48mauritslamersquestion: I am trying to learn clojure by porting an application I wrote in a few other languages. For this app I need to have a function that works on a list of options and returns all valid routes through those options. Every option has a :from and :to keyword...
14:48mauritslamersI feel I could use a kind of double reduce action, but my imperative mindset is playing up constantly :)
14:50mauritslamersany ideas?
14:50Chousukeare they loopless? :/
14:51mauritslamersChousuke: yes
14:52mauritslamersthey are a model of a movement in time
14:52Chousuketry solving a subproblem first: return a sequence of a single route
14:53mauritslamersThat is what I have been trying to do, but I have no clue on how to do that non-imperatively...
14:53mauritslamersthe function I wrote are constantly returning nil :)
14:54Chousukecan you pastebin some code?
14:54mauritslamersyep, moment...
14:55lisppaste8mauritslamers pasted "route-detection" at http://paste.lisp.org/display/83016
14:55mauritslamersThat function is intended to be used in a reduce function
14:56mauritslamersas (reduce filterfunc list-with-lists-of-items)
14:56Chousukehmm
14:56mauritslamersbut this func only returns the entire first list with items without any filtering
14:59mauritslamersIf I would write it imperatively, I would take the first list, process it one by one by walking through the rest of the list, taking the previous to element as from element and if it fits push it to the result array
14:59ChousukeI really can't visualise even that :P
14:59mauritslamershehe :)
15:00Chousukehow is your data structured?
15:00mauritslamersI will add an example of the source data and the result i'd love to have to the pastebin
15:03Chousukemaybe you could restructure it to use sets?
15:03Chousukefor every item, you would have a set of from and to items
15:04lisppaste8mauritslamers annotated #83016 "route-detection" at http://paste.lisp.org/display/83016#1
15:04Chousukeyou'd have to give them unique ids and pt them in a map or something though
15:04mauritslamersthe issue is that one item is both it's own from and to
15:04mauritslamersand I cannot split them
15:05mauritslamersthe data is a kind of vector
15:06Chousukethat example is even more confusing :/
15:06mauritslamerssorry about that :)
15:06Chousukewhy do you have two sequences of the same data?
15:07mauritslamersbecause the real source data is a ratio and these two sequences of the same data are options for that specific ratio
15:08ChousukeI'm sorry, I don't understand this problem at all :P
15:08mauritslamersthese sequences are the same now because there is a succession of the same ratio
15:09mauritslamersI cannot go into details too much, but let's image there is a drawing
15:09mauritslamersthe drawing exists of a series of vectors
15:09mauritslamersthese vectors all have more or less the same length
15:10mauritslamersThe input to the application is a set with vector lengths and the app needs to figure out what places in the drawing that sequence of lengths can occur
15:12mauritslamersso I need to create a kind of function that can reduce all the possible options to a sequence of possible options as they occur in the drawing
15:13ChousukeI don't get that at all :P
15:13mauritslamersit is a kind of patternmatching?
15:14mauritslamers:)
15:14Chousukeit sounds like you need to find the possible paths from A to B in a graph but hm
15:19mauritslamersChousuke: that is more or less the same problem indeed
15:25Chousuke(fn adjacents [node] (set (map adjacents (filter #(= (:to node) (:from %)) *nodelist*))))
15:25Chousukeshould give you a set of sets of sets of something until ???
15:26Chousukethe filter must be made such that eventually it returns nil
15:26Chousukenot efficient, but should work :P
15:28Chousukeactually
15:29Chousukeyou'll need (if-let [adjs (seq (map adjacents ...)] (set adjs) node) to actually get useful output
15:29mauritslamersok, thanks!
15:30Chousukebut this is all done without testing
15:30Chousukeso it might loop infinitely.
15:30mauritslamersnp :)
15:31mauritslamersI am first trying to get what you are doing exactly and then write my own code
15:31mauritslamersthanks!
15:31Chousukeyou might want to return {node (set ...)} too
15:32Chousukebut the idea is to build a hierarchy of sets so that the first set contains all the nodes that you can access from the first node, along with THEIR sets of nodes accessible from them
15:38powr-tocWhat happens if you recur inside a multi-method, do you recur to the multi dispatch, or do you just recur to the local defmethod?
15:39hiredmanthe local
15:40powr-tocI'm guessing it just recurs to local method, as otherwise clojure's recur would support mutual recursion, right?
15:40powr-toccheers hiredman
15:40hiredmanhello
16:55Knekkcan I (make-array ) with a clojure struct?
16:56Chousukeyou want an array of maps?
16:56Knekkyes
16:56Knekkor refs to structs
16:56Chousukewhy not just use a vector?
16:57KnekkI am trying to figure out what's most efficient
16:57Chousukevectors are a lot easier to use than arrays
16:59duncanmand vectors can always turn into arrays, right? so that answers the question
17:00Chousukeno they don't
17:00duncanmoh?
17:00Chousukethey're persistent and immutable, so they can't.
17:00duncanmahhhh
17:01Chousukethere's an optimised version though, if you only create the vector and never conj on it.
17:01Chousukebut that's an implementation detail :)
17:01KnekkI need mutable data.
17:01Chousukeuse a ref to a vector.
17:01KnekkI am
17:01Chousukeand is it too slow? :/
17:02Knekkdon't know. Keep blowing the heap :)
17:02Chousukeprobably not the ref's fault.
17:02Knekkno
17:03Chousukemost likely you're holding onto a big seq somehwere.
17:03Knekkit's me holding on to the vector of refs I create
17:04Knekknot sure how to create the vector and then reference it later without forcing it to instantiate right away
17:04Chousukehow many items does the vector contain? :P
17:04Chousukemillions?
17:05Knekkyeah
17:05Chousukehmm.
17:06Chousukewhat does it contain?
17:06Knekkjust refs to a simple struct for now
17:07Chousukeyou probably don't want millions of refs
17:07Knekkthat's what I am figuring out
17:07Chousukeinstead you could have a single ref to a huge vector of structs.
17:07Knekksince it's all mutable data I am probably gonna have to come up with a method to offline pieces of it
17:08Chousukeeven with millions of items, a conj to a clojure vector only takes ~20 or so iterations.
17:09Chousukeit's O(log_32)
17:09unlink1O(1)?
17:09Chousukenot O(1)
17:09Chousukebut close enough :)
17:10unlink1O(log n)?
17:10unlink1what is O(log_32)?
17:10Chousukeno, O(log_32 n) :P
17:10unlink1oh
17:10unlink1that's the same complexity as O(log n) ;-)
17:11Chousukeexcept it grows a *lot* slower.
17:11unlink1A constant factor slower.
17:11Chousukeuh, no.
17:11unlink1(1/log 32) slower
17:12unlink1log32(n) = log(n)/log(32)
17:12unlink11/log(32) is a constant factor
17:12Chousukehm, right
17:13unlink1compared to say, log(log(n))
18:12dcnstrcthas anyone tried using clojure to program Android apps ?
18:12dcnstrctI'm not sure if it's possible or not
18:13hiredman~google clojure android
18:13clojurebotFirst, out of 9270 results is:
18:13clojurebotClojure and Android - Clojure | Google Groups
18:13clojurebothttp://groups.google.com/group/clojure/browse_thread/thread/cf9c928f0027836a
18:14dcnstrcthrm... so the answer is no
18:14dcnstrctsux
18:15dcnstrctthere is a Java bytecode -> Dalvik bytecode compiler.. but no way to support the runtime compilation used
18:15dcnstrctby Clojure
18:16dcnstrctO well
18:23jackdempseyhey guys, i'm not sure if i'm just expecting something mutable here where its not, but i would think that the second conj call here would add to the set and we'd have two values in there
18:23jackdempseyhttp://gist.github.com/140751
18:23jackdempseyam i doing it wrong?
18:39Chouserjackdempsey: right, update-in is just like assoc: takes an immutable map, returns a new immutable map.
18:42jackdempseyok so the only reason i was able to use update-in before was on account of the alter and STM features
18:43jackdempseyah
18:43jackdempseyyeah just inspected foo
18:43jackdempsey{:a 1, :e {:b 2, :c #{}}}
18:43jackdempseymakes sense
20:40krumholtwhat is wrong here?: (defn handle-client [counter]
20:40krumholt (Thread/sleep 1000)
20:40krumholt (dosync (alter counter inc))
20:40krumholt (send-off *agent* #'handle-client counter) nil)
20:57arbscht_krumholt: when send-off calls a function, the first argument is the state of the agent, followed by your other args
21:00krumholtarbscht_, thanks
23:00Chouserha. Just used javadoc on a non-builtin class. Worked perfectly.
23:01ChouserIt's like magic.