#clojure logs

2008-09-22

09:50rhickeyI've added print-method multimethod and switched printing to use it
09:50rhickeybuilt on contribution from Erik Soehnel
09:55wwmorganrhickey: that's a lot cleaner than the old way of doing it
09:56wwmorganalso I think it should recognize Patterns and print them using the #"foo" form
09:56rhickeywwmorgan: right, it needed the isa multimethod enhancements I added this summer
09:56rhickeywwmorgan: ah yes, was waiting for this to do patterns...
10:02rhickeywwmorgan: I've added print-method for java.util.regex.Pattern
10:02wwmorganrhickey: sweet
11:26Chouserexcellent, now all I need to do is implement MultiFn in JS, and printing should work.
11:27abrooksChouser: Great work!
13:42jgracinrhickey: I see that 1040 revision has fixed print-method exception. However, I'm still get the following when compiling code wlth failures, from Slime: ...(incoming paste)
13:42lisppaste8jgracin pasted "Compiler exception" at http://paste.lisp.org/display/67278
13:47rhickeyjgracin: there's too much going on there for me to suss this out - can you narrow it down at all?
13:47jgracinrhickey: I'll try.
13:57jgracinrhickey: it seems to me that during compilation, LazyCons.first is called and it throws RuntimeException, and this exception is not encapsulated in CompilerException, which is what Slime expects. Any ideas? I'll keep digging...
13:58rhickeyseems to me Slime shouldn't hardwire CompilerException
14:03leafwI have a conceptual problem. I am far too used to looping; suppose I have a list of objects, of which I have to find 3, given 3 desired names. I.e. getTitle has to be called on each object. What I would like to get back is a table of name - object. What is a good strategy in clojure to do that?
14:05leafwsomwhow, is not obvious to me. I could do it perhaps with a recursive function that returns a table with a new entry, that table being given as argument ad thus extended, or nothing when reaching the end of the list.
14:09ozzileeleafw: You could do it with reduce: (reduce (fn [a x] (if (is-something-we-want (.getTitle x)) (assoc a x (.getTitle x) a) {})
14:09cemerickleafw: given a seq of those objects, this would give you a map of name ==> object: (apply hash-map (mapcat #(list (.getTitle %) %) seq-of-objects))
14:10ozzileeleafw: Where is-something-we-want is whatever determines whether that title is the one you want.
14:11wwmorganleafw: here is one way to do it: http://paste.lisp.org/display/67282
14:11leafwthanks people, let me digest it
14:12cemerickI often end up using filter and map instead of reduce for stuff like that -- I've never liked the position of the first value in the 3-arg version of reduce.
14:13ozzileecemerick: I prefer fold myself, as in (fold fn initial coll). But meh :-)
14:18leafwozzilee: your pasted solution is missing parentheses...
14:19leafwcemerick: your solution looks really cool -- will it accept any list, like a java.util.ArrayList ? Or does it need a clojure list?
14:19ozzileeleafw: That's possible.
14:19leafwwwmorgan: thanks for that post, just got nice insight into memfn
14:20leafwIt's amazing there are so many solutions
14:20cemerickleafw: seq-of-objects can be anything that's seq-able -- all collections can be treated as seqs
14:20ozzilee(reduce (fn [a x] (if (is-something-we-want (.getTitle x))) (assoc a x (.getTitle x) a) {}) ; Better.
14:22leafwthank you
14:23leafwhum, ozzilee : the 'if' has no body as you declared it.
14:26ozzileeYeesh, writing lisp without emacs doesn't work out so well. This should be correct, sorry about that: (reduce (fn [a x] (if (is-something-we-want (.getTitle x)) (assoc a x (.getTitle x)) a)) coll {})
14:28leafwozzilee: so you are doing: reduce fn list1 set1 , is that right?
14:29ozzilee(reduce function seq initial-value), yeah.
14:29leafwaha
14:29leafwintial-value ... got it, got it.
14:29ozzileeWe start with an empty hash-map, and then assoc in x if it's something we want, otherwise we return what we've reduced so far (a).
14:30leafwI understand it. Thanks.
14:31ozzileeOk. Next time I'll check my parens before I post :-)
14:31rhickey(into {} (for [x coll :when (we-like x)] [(key-for x) (val-for x)]))
14:32cemerickhrm, forgot about into...
15:48leafwfor all clojure's power, debugging is one of its weaknessess: the stack traces never mean much to me ...
15:48abrooksleafw: There's been several threads about this on the Clojure group.
15:49abrooksleafw: And I have to agree.
15:49TreeRexI found it just takes practice.
15:49abrooksIf I get things right, it just works. If I screw up I get to stare blankly at the stack trace and flail around until I figure out what's wrong.
15:50leafwproblem is, when an exception is thrown on code pasted to an interpreter, it doesn't give back anything useful such as the names of the function where it failed, and its parent stack of caller functions.
15:50abrooksIt seems that with all the introspective abilities, we should be able to provide much more useful information.
15:51leafwthat alone would help a lot, much more than (defn pdatas (reduce (fn [project ptable] (assoc ptable project (create-pdata project)) ptable) (ControlWindow/getProjects) {}))
15:51abrooksleafw: By interpreter you mean REPL?
15:51leafwoops
15:51leafwbad paste (we luve linux pasting)
15:51leafwyes, REPL
15:56leafwat least, functional-style makes things trivial to debug manually
15:56leafwbut I can't imageine what it will be to debug a large project.
15:56leafweven making on-site test functions is trivial and almost natural.
15:57abrooksIf C compilers can print out the offending line with a "------^ " pointing to the offending expression / token it seems that Clojure should be able to as well.
15:58leafwI wish I knew how. I may dig in one of this days, into Clojure's exception handling system. With all the metadata, there must be a way to just print the stack of functions.
15:59ozzileeleafw: I actually hacked that in the other day on my lunch break, it shouldn't be too tough to do it nicely.
16:01lisppaste8ozzilee pasted "chicken's errors" at http://paste.lisp.org/display/67284
16:01ozzileefwiw that's how chicken scheme shows errors, which I always appreciated. Other lisps may do something similar.
16:03abrooksozzilee: That's exactly what I'd like to se.
16:03abrookssee
16:04leafwyeah, that's the right direction IMO
16:09ozzileeShould be do-able, but... "not it!" :-)
16:09abrooksozzilee: :)
16:22TreeRexWhile I haven't used it, the screenshots of the Enclojure debugger look promising: perhaps there is some useful functionality in that IDE which could be moved into the REPL.
17:03leafwmy problem with enclojure and the like is that its not an editor (aka it's not vim, it's not emacs)
17:03leafwI would use it only for debugging, if they make that worthwhile.
17:11ozzileeparth_m started a repl written in clojure, might be something worth looking at: http://code.google.com/p/iclj/
17:41leafwis there any built-in way to do a .toArray() to a list? Aka put all elements of a list into an array of a certain type. I can do that with a reduce, but I wonder if there are easier ways.
17:45ozzilee(into-array seq) ?
17:47leafwnice
17:47leafwthanks
18:36leafwand using reduce/map and the like, how can one add all values of a half-matrix? I.e. all values of an array NxM, where only values under the diagonal should be added.
18:44rhickey_leafw: try for
18:46leafwstill te problem of a mutable var that accumulates the sum
18:47rhickey_the problem is in wanting one - just pick the values you care about first, then add them with reduce +
18:48leafwthat means a huge memory increase -- which is fine in most occasions, but not in this one.
18:49leafwthanks anyway
18:49rhickey_um, no, since seqs can be lazy
18:49leafwif anything, there are integer indices to the arrays right?
18:49rhickey_for yields a lazy seq, for instance
18:49rhickey_range yields a lazy sequence
18:49rhickey_etc
18:50leafwI think I don't understand lazy seqs them
18:50leafws/them/then
18:53rhickey_try (reduce + (range 100000000)) and watch memory use, it doesn't budge
18:54leafwmeaning, each element of the sequence is returned without the sequence existing in memory?
18:55rhickey_right
18:56rhickey_a lazy seq is a recipe for a seq, the whole seq need never exist. As you call first/rest you get bits of it created on demand, as long as you don't hold onto them, they are discarded after you use them
18:56rhickey_cycle returns an infinite seq, for instance
18:56rhickey_you'll never use all of it
18:57leafwvery nice. Now it's my task to figure out how to use it for the half-matrix sum.
18:58rhickey_try for
18:58rhickey_:)
19:04leafwso I need a lazy seq of lazy seqs right ?
19:04leafwbut then I need to flatten it ... man, thinking this way is totally new
19:05rhickey_(for [ x (range 3) y (range 3)] [x y])
19:06leafw(for [x (range 10) y (range x)] [x y])
19:06leafwinteresting
19:09rhickey_there's also :when and :while options
19:11leafwfor a NxN matrix, the half-matrix is (for [x (range 0 N) y (range 0 x)] [x y])
19:11leafwthe lower one, at least, without the diagonal of zeros.
19:48ericthorHas anything changed with arglists recently? If I say (meta #'clojure/*) I'm getting an IndexOutOfBoundsException when the REPL attempts to print the arglist
19:51akingericthor: works here
19:52ericthoraking: what svn revision are u using?
19:52akingericthor: 1039 - trying with 1040
19:53ericthoraking: could be time for a full rebuild on my end here...
19:53akinghmm.. doesn't work with 1040
19:54ericthorphew
19:54ericthorthanks
19:54ericthorIt appears to be the 0th element
19:55ericthoris said to be out of bounds
19:55ericthor1 2 3 all ok of 4
19:55ericthorI'll back up to 1039
19:56akingericthor: it might have been 1038 - I had updated last night, but there looks to be 2 updates today
19:56ericthoraking: ok thanks...I'll try both
20:07akingericthor: looks like I was at a slightly older version then I thought - anything after 1037 breaks
20:07ericthoraking: 1037 is oko?
20:07ericthorok?
20:07akingyup
20:08ericthoraking: I was just doing the same thing...saved me the trouble. Thanks!
20:34rhickey_fixed print-method on empty vector
20:35rhickey_rev 1041
21:30ericthorrhickey: Thanks!
21:30rhickey_sure, new print multimethods getting shaken out...
23:32yangsxwhat is the best way to use clojure.contrib? I'm trying clojure with the svn repo