#clojure logs

2009-09-15

03:07Fossihi
03:08harblcathiya
03:19LauJensenGood morning gents
03:23arbscht_hello
05:39ChrisPSLisp without parentheses?
05:42arbscht_ChrisPS: I don't understand
05:42ChrisPSThere is an article at news.ycombinator.com
05:42ChrisPSsomething called Lispin
05:43arbscht_hm, the linked page won't load for me. does it have anything to do with clojure?
05:43ChrisPSThe site seems to be inaccessible right now, but there is google cache
05:43ChrisPSclojure is a lisp
05:44ChrisPSpersonally, I like the parentheses
05:44ChrisPSas it makes navigation easier, due to the sexp's
05:48arbscht_this looks like every other futile attempt at eliminating parens from a lisp. I'm not sure what more can be said of it
05:49arbscht_anyway, other lisps are generally off topic here. they tend to have their own channels :)
05:49ChrisPSI don't know, it doesn't really trouble me, sorry for the off-topic
05:50arbscht_some folks tried inventing syntax for clojure that reduced the use of parens. iirc, that didn't stick
06:05ChousukeI like the second comment on the news item :)
06:06Chousukejust change the colour to match the background and the parens disappear :P
06:06arbscht_heh
06:19adityogood afternoon folks
06:20adityohow would i write this in clojure new QName("http://apache.org/hello_world_soap_http", "SOAPService");
06:22adityogot it :)
06:22jdz(new QName "http://..." "SOAPService")?
06:34liwpor (QName. "http://..." "SOAPServervice")
06:34liwpif I could spell, that is
06:34powr-tocHey... I need to extend a java class in Clojure and set an instance variable within the super class... How do you do this?
06:35AWizzArdWhich lib would you use for reading pdf files?
06:37AWizzArdjdz: do you prefer calling (new SomeClass ...) over (SomeClass. ...)?
06:37clojurebotnew Class(x) is (Class. x)
06:37jdzi usually use new
06:37jdzbut simetimes, when using -> macro, it's convenient to use the dotted syntax
06:38liwpIIRC the current favourite / idiomatic style is (Class. x)
06:38jdzwell, the dot is easy to miss you know
06:38liwpyeah, I agree
06:38liwpI tend to forget to write it when I'm creating objects, i.e. I write (Class x) and then the compiler is angry at me
06:42liwp,(String. "foo")
06:42clojurebot"foo"
06:48powr-tocstill can't find any mention of setting protected member variables in super classes you extend with either proxy or gen-class
06:48powr-tocdoes anyone know if this is possible?
06:48liwppowr-toc: I haven't used proxy myself do I don't know. I think it's been asked on the mailing list a few times so it might be worth searching through the archives
06:49liwpalso, the was some trick in searching the group... someting like "use the top level group search and pass in your search term and the group name"
06:56powr-tocliwp: hmmm still can't find anything :-(
06:57powr-tocI would have thought you'd be able to access/set member variables in a binding form or something
07:08LauJensenWhen I do (range 1000), is 0 calculated? Or is the head also lazy ?
07:10liwp,(let [xs (map println (range 10))] 1)
07:10clojurebot1
07:10liwpseems to be lazy
07:10liwp,(let [xs (map println (range 10))] xs)
07:10clojurebot(nil nil nil nil nil nil nil nil nil nil)
07:10liwpor then I did something silly...
07:11liwp,(doall (let [xs (map println (range 10))] 1))
07:11clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer
07:11liwp,(doall (let [xs (map println (range 10))] xs))
07:11clojurebot(nil nil nil nil nil nil nil nil nil nil)
07:11clojurebot0 1 2 3 4 5 6 7 8 9
07:12liwp,(let [xs (map println (range 10))] xs 1)
07:12clojurebot1
07:12liwp,(let [xs (map println (range 10))] (doall xs) 1)
07:12clojurebot1
07:12clojurebot0 1 2 3 4 5 6 7 8 9
07:13LauJensenThanks, I reached the same conclusion
07:14liwpIIRC that was the goal of Rich's fully lazy sequences that happened some time ago
07:14liwpI.e. in the past head was eager
07:15liwpbut I might be wrong
07:16LauJensenNo thats exactly how I remembered it also
08:10weissjIf I have a list of lists, and i want to create a map where the keys are the 1st item in the inner lists, and the values are the inner list, how do i do that in a functional way? ie ((:a 1 2 3) (:b 2 3 4)) -> {:a (:a 1 2 3), :b (:b 2 3 4)}
08:10dabdhi, is it possible to use Jersey from clojure?
08:11dabdI am writing a bunch of RESTful web services using Jersey and I hate Java...
08:11jdzif Jersey is Java, then you can use it, yes
08:12jdz*is in
08:13fulletsweissj: (into {} (map (fn [x] [(first x) x]) [[:a 1 2 3] [:b 2 3 4]]))
08:13dabdJersey is Java but it relies heavily on annotations and it is not obvious for me how to use it from clojure
08:14dabdsay in Jerse
08:14weissjfullets: ah, so simple :) thanks
08:14dabdy you define an annotated class and several methods how can you do it from clojure?
08:14weissjwas trying to figure out how to add 2 items at a time, "into" is what does it
08:15Fossiweissj: should be possible with zipmap as well
08:16Fossidon't know which would be nicer
08:16Fossidepends on your usecase i guess
08:17fulletsFossi: that's much nicer, imo at least
08:17fullets(zipmap (map first blah) blah)
08:18liwpdabd: AFAIK clojure does not support annotations at the moment, so I think you're out of luck unless there is some other way to plug into Jersey
08:18Fossisounds like jersey and clojure wouldn't be such a nice match
08:19dabdliwp: okay that's the impression I got from skimming through the Java Interop section of the manual: that it is not possible to define annotations
08:21liwp,(let [xs [[:a 1 2 3] [:b 4 5 6]]] #(zipmap (map first %) %))
08:21clojurebot#<sandbox$eval__2969$fn__2971 sandbox$eval__2969$fn__2971@f67d81>
08:21liwp,(let [xs [[:a 1 2 3] [:b 4 5 6]]] (#(zipmap (map first %) %) xs))
08:21clojurebot{:b [:b 4 5 6], :a [:a 1 2 3]}
08:21liwpthat's not very nice at all actually...
08:22liwpI was trying to get away from repeating xs in the map and zipmap
08:22dabdmaybe Java annotations could be implemented through clojure metadata
08:22liwpyeah, that would be the way to do it
08:23liwpin the end you need to change the compiler to add the annoations to the class file and AFAIK people don't really want to touch the compiler ;)
08:31MortahI hear you guys are a friendly bunch, good work :D
08:38dabdliwp: an alternative would be to change gen-class so it generates annotated classes and methods
08:39liwpdabd: gen-calls doesn't go via the clojure compiler?
08:39dabdliwp: yes it does sorry
08:40liwpdabd: I'm sure annotations will get added at some point, but so far there hasn't been a lot of demand AFAICT
08:41ChouserI don't know much about annotations or rhickey's plans for dealing with them, but gen-class is Clojure's big hammer for cruddy Java interop where named classes are required -- it seems the natural place to add annotation support, if any, and nobody would have to touch the compiler.
08:41ChouserI just rewrote a small .clj file yesterday into a small .java file to support junit 4 annotations.
08:41ChouserAs it turns out, Clojure wasn't buying me much there.
08:42JomyootIs Conjure or Compojure more promising?
08:43liwpChouser: so is new new going to make gen-class obsolete?
08:43FossiJomyoot: i guess that depends what you are used to
08:43JomyootI am used to rails
08:43Chouserliwp: not at all
08:43JomyootBut I am wondering which one will have more users
08:44Jomyootwant to use something that will have more active users
08:44FossiJomyoot: don't know. compojure works nicely for us as kind of a cl-who clone
08:44Jomyoothave you looked at conjure?
08:45Fossiand even if it doesn't attract a lot of users, it's pretty much feature complete because it's so simple
08:45dabdChouser: if you end up using gen-class to write Java code with lisp syntax you might as well use Java directly
08:45Chousernew new (a.k.a. reify) is a native Clojure structure that will fully supported on other hosts (C#, JavaScript, etc.)
08:46Chouserin other words, not primarily a Java interop structure. gen-class and proxy are meant more for interop with Java libs that have unfortunate designs.
08:46liwpChouser: ok
08:48liwpChouser: is this correct, new new allow you to extend an existing class whereas gen-class is used to define a new class which optionally extends an existing class?
08:51Chouserliwp: yes, that's one of the differences. There are several.
08:51Chouserback in a minute.
08:52Chousukeliwp: I think everyone would prefer if you only implemented interfaces rather than extending existing classes (unless abstract) :)
08:56liwpChousuke: if you don't want me to extend your classes / methods, you should declare them as final :)
08:57weissjIf i have a list of items and i want a list with the nth item removed, how do i do that
08:57weissjdo i have to use filter (or remove)?
09:01Chousukeliwp: the problem is even having classes that others might want to extend ;)
09:01liwpChousuke: you mean in Clojure or in OO languages?
09:02ChousukeI suppose it depends a bit on the language
09:03Chouserweissj: neither vectors nor lists support efficiently removing an item in the middle, so yes you'll end up having to an O(n) walk
09:04weissjChouser: ok thanks
09:04Chouserweissj: probably most efficient to use a vector, two subvecs, and conj them.
09:06weissjChouser: yeah, all my vectors are 4 items long, and i just want to remove the 2nd item, so i can conj the first with a call to drop
09:06Chouseroh! actually, destructuring might be nice if they're that small.
09:06Chouser(let [[a _ b c] v] [a b c])
09:07weissjChouser: ok, i will try that, thanks!
09:08liwpChouser: have you seen Guy Steele's talk at ICFP'09? http://research.sun.com/projects/plrg/Publications/ICFPAugust2009Steele.pdf
09:09liwphe talks about concurrency friendly data structures, i.e. representing things like lists as trees so that you can parallelise operations on them
09:09liwphe introduces first conc lists (concatenation lists) and then talks about finger trees later on
09:10Chouseryes, I've looked through that. Clojure's vectors are actually trees internally
09:10liwpyep
09:10liwpI was just wondering if you can do all of that with just finger trees, i.e. if you have finger trees is there any use in conc lists
09:10Chouserso rhickey wrote some parallel ops to work on the vectors.
09:10liwpahh, I haven't see those
09:11liwpis that what's in clojure.parallel?
09:11ChouserI never use them, so I don't remember. looking now.
09:12ChouserI think clojure.parallel is still using the forkjoin.ParallelArray, so that's not it.
09:12liwpok
09:12liwpthe docs talk about creating a parallel array from a collection, so it must be something else then the standard vector
09:13Chouseras, there's a 'par' branch
09:13Chouser"added clojure.par ns with pvmap and pvreduce"
09:13liwpcool
09:14Chouserso those work on regular clojure vectors, leveraging the tree structure.
09:15liwpI guess the 32 object fanout helps in avoiding splitting up the work too thinly
09:15Chouseryep.
09:16Chouseras for finger trees, I guess I don't know the theory well enough yet. They should be able to useful for doing all the things described in those slides.
09:16Chouserconcat is efficient, etc.
09:17liwpthat's what I'd expect, but the slides did not really state it explicitly and I don't know finger trees well enough to work it out for myself (the paper is at home on the TODO pile)
09:17Chousercached monoids are used heavily in finger trees
09:18liwpthere's a nice blog post about finger trees in haskell which explains with a few examples how the functionality changes when the monoid is changed
09:18liwpreally cool
09:19Chousermy finger trees support Clojure's seq abstraction (ISeq) directly. That is, calling 'rest' on a finger tree gives you a new finger tree, amortized O(1) time.
09:19liwphttp://apfelmus.nfshost.com/monoid-fingertree.html
09:21Chouserlooks like there are slightly different performance profiles between finger trees and conc lists. Like first is O(1) for ft, appears to be avg O(log n) for conc, vs. concat O(log n) for ft and O(1) for conc
09:22liwpheh, now that you mention it, it seems obvious :)
09:23Chouserreally? nothing about ft's have been obvious to me. :-P thought I think I'm starting to get a sense of how they really work now.
09:23liwpand rest is O(log n) for conc as well, right? Only concat is O(1)
09:24ChouserI think so, though in practice I'm not sure how it will always turn out.
09:24liwpChouser: the conc list bit was the obvious bit, i.e. concat is O(1) and first is O(log n)
09:25ChouserThat is, ft rest is slightly worse that O(1) and it uses delay to make it as good as possible. conc rest speed will depend on how the list was built I think (depth of left path may be short)
09:25liwpChouser: I guess if you have an unbalanced conc list, then you might effectiely have a linked list and rest would be O(1) again
09:25Chouserright
09:25liwpSteele conveniently left out the balancing of conc lists from the slides
09:25Chouserheh
09:26liwpwhat do you do with fingertrees? do you need to rebalance?
09:26Chouseryeah, that's a nice feature of ft -- no rebalancing
09:26liwpok
09:26liwpdoes that lead to pathological cases?
09:27ChouserI don't know. I wouldn't be surprised if the worst cases were O(log n) when you were hoping for amoritized O(1). But maybe it's not even that bad, not sure.
09:27ankoudoes clojure not even show line numbers or file at syntaxerrors like "unmatched parentheses" or is it a problem with slime?
09:28liwpankou: I think it's a slime issue - I've only ever used slime myself
09:29liwpI also use paredit mode so it's hard to miss parens
09:30ankouI get an Message of an Exception with a backtrace of the reader but no line number of the error itself is included in the exceptionmessage
09:30liwpankou: yep, that's quite common with clojure error messages
09:30ankoureally annoying :\
09:30liwpankou: have a look at the stack trace, if that's available, usually there's a clue there
09:31liwpi.e. one or more stack frames mention your source file and line number
09:31ChouserI get: java.lang.Exception: Unmatched delimiter: ) (<file name>:<line number))
09:31liwpslime won't even inject the code with a missing paren for me...
09:32liwpahh, never mind - my test app killed my JVM...
09:32liwpit's very annoying when people bind the Swing close app button to System/exit...
09:34ankouChouser: the same thing just without the extra information. I could find the file with the help of the stack trace however loading this file directly didn't give me more information
09:51liwpdo people use a user.clj file in their classpath?
09:52liwpand if so, what's in it?
09:53ChouserI don't. My startup script puts -i $HOME/.clojure/repl-init.clj on the java command line
09:54lisppaste8Chouser pasted "repl-init.clj" at http://paste.lisp.org/display/87096
09:54liwpChouser: do you use slime?
09:54Chouserno
09:54liwpare you using the raw repl or one of the IDE plugins?
09:55Chouserrlwrap + repl in a terminal
10:03weissjok i should know this but how to turn a seq of strings into a concat'd string
10:03weissj(str (interpose "," '["a" "b"]))
10:03weissj"clojure.lang.LazySeq@1e636"
10:04Chouserapply
10:04weissjChouser thx
10:53Fossiweissj: for that case there's str-join as well
10:53Fossiin contrib
10:54Chouseralso contrib str-utils2/join
11:08weissjFossi: yeah i think that was the one i was thinking of thanks
11:09avitalwhat is used here for pasting code?
11:10crioshttp://paste.lisp.org
11:11avitalok cool so i was trying to use map on a hash map and since hash maps are collections as pairs the return value is not a hash map but rather a sequence of pairs
11:11avitalso i wrote this instead
11:11avitalhttp://paste.lisp.org/display/87103
11:11avitalis there any better way to map a hashmap?
11:12avitalin my implementation map-map receives a function and a map, the function gets two arguments (key and value) and returns a sequence of length 2 containing the new key and value
11:12Fossi(map (fn [k v] (println k v)) {:a 1 :b 2})
11:12Fossi,(map (fn [k v] (println k v)) {:a 1 :b 2})
11:12clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--2982$fn
11:13Fossiups
11:13Fossi,(map (fn [[k v]] (println k v)) {:a 1 :b 2})
11:13clojurebot(nil nil)
11:13Chouser,(into {} (for [[k v] {1 1, 2 2}] [(* 2 k) (* 3 v)]))
11:13clojurebot{4 6, 2 3}
11:13avitalthat might work but if you actually want a return value from map it won't end up a hash map.
11:13avitaloh what
11:13avitalwait
11:13avitalwhat
11:13avitalwhat is into?!
11:13Fossiyeah, into then
11:15Chouser(into target source) is (reduce conj target source), only faster
11:16avitalwow amazing
11:16avitalok
11:16avitalthanks
11:17Chouserankou: you're not the first to write map-map, but with into, for, zipmap, etc. I'm not sure people need map-map.
11:18avitalChouser: Not sure what you mean by "people need". If anyone feels that it makes his/her code simpler, more intuitive, etc. let them do it.
11:18Chouseroh sorry, mis-directed post there.
11:19avitalMy intuition says: If you can run map on maps, it should return a map. If not, then either it needs to be replaced or map-map should be part of clojure
11:21Chouser'map' is always consumes a seq lazily, returning a lazy seq. Having it return a map or vector would be a poor fit, I think -- that's exactly what 'into' is for, pouring a (possibly lazy) seq into a strict collection.
11:22Chouseras for a separate map-map: http://google.com/search?q=clojure+&quot;defn+map-map&quot;
11:23Chouserhm, some of those "map-map"s do different things.
11:24JomyootHow can you quickly convert from Java HashMap to Clojure Hash?
11:25ChouserJomyoot: you need it to actually be persistent?
11:25Jomyootnot really
11:25Jomyooteither way is fine
11:25ChouserJomyoot: clojure maps implement java map, so you may be able to just use it directly
11:26Chouser,,(into {} (java.util.HashMap. {:a 1, :b 2, :c 3}))
11:26clojurebot{:a 1, :b 2, :c 3}
11:26Jomyootcool
11:26Chouserthere's a clojure map to a java map and back again. :-)
11:27JomyootWhat about a templated HashMap
11:27ChouserJomyoot: doesn't matter
11:28ChouserJava generics are just a java compile-time check -- after the .java's been compiled, the collections don't care about their template params anymore
11:52lisppaste8raphinou pasted "untitled" at http://paste.lisp.org/display/87104
11:53raphinou_here's a little paste about a question about the (defn my-func [args & more] ...) way of defining a function and handling the more var
11:54raphinou_if second arg passed is a list, i would like more to be equal to that list. And I'm not sure what's the best way to do that...
11:54ChousukeI don't think that's a good idea :/
11:54Chousukeanyone who wants the second argument to be a list can use apply anyway
11:55ChousukeI guess you could overload it for two arguments to check whether the second argument is a list or not.
11:56Chousukeeg (fn foo ([x y] (if (seq? y) (concat x y) (concat x [y]))) ([x & more] (concat l more)))
11:57Chousukeoops
11:57Chousukethe l should of course be x :P
11:58Chousukeor hmm
11:58Chouser,(fn foo ([x y]) ([x & xs]))
11:58clojurebotjava.lang.Exception: Can't have fixed arity function with more params than variadic function
11:58Chousukeoh damn
11:58Chousuke(defn foo [x & more] (concat x (flatten more)))
11:58raphinou_chousuke: I agree it's not a good approach, but it's a question that popped up when wrtiting a test for such a function. To save time I put the more to be passed to the function, which is also the expected result , in a "variable" I could reuse
11:59Chouserdon't use 'more', it's a builtin
12:00raphinou_Chousuke: ha, I didn't know that!
12:01ChousukeChouser: wait, more is?
12:01Chousuke(doc more=
12:01clojurebotEOF while reading
12:01Chousuke(doc more)
12:01clojurebotNo entiendo
12:01ChouserChousuke: oh, nope. sorry. that's the name of the method 'rest' calls.
12:01Chousukeheh. confusing :P
12:02Chouseryeah. there are a couple interface methods that kept early names.
12:02Chouser'conj' calls 'foo.cons()' and 'rest' calls 'foo.more()'
12:03raphinou_ok!
12:03Chouserrhickey: good luck!
12:03rhickeythanks!
12:04raphinou_off to microsoft? for clojure?
12:04Chouseryeah, he's speaking
12:05raphinou_he, cool
12:06Chouserraphinou_: anyway, you're sure you can't just use apply? it's the correct solution, and usually convenient.
12:06raphinou_Chousuke: looking further at it
12:07raphinou_Chousuke: actually, first trying to get the test pass with the "& others" arguments ;)
12:07Sir_DiddymusHi all... I've extended a Java class (with :gen-class and :extends) and all is fine and works like expected. Now I need to call a protected final method of the superclass (from inside my extended class) - is there really no way do this? Or did I just not find it how to achieve this?
12:08Chouserraphinou_: otherwise, I don't think you can do better than (defn foo [x & xs] (let [xs (if (coll? (first xs)) (first xs) xs)] [x xs]))
12:09ChouserSir_Diddymus: did you look at :exposes-methods ?
12:11Sir_DiddymusChouser: yup... but maybe I didn't use it correctly. And I thought I can only access overridden methods of the superclass that way? At least that is what the API docs specify...
12:12Sir_DiddymusChouser: and well, since the protected method is final, no override possible... :\
12:13ChouserI think that's a red herring. ignore the stated purpose and look at what it does.
12:13ChouserI *think* it'll work for you.
12:14Sir_Diddymushmm... k... than I probably just did something wrong. I thought I tried that...
12:14Chouser:exposes-methods creates new public methods that can call protected methods of the superclass
12:14Chouseryeah, gen-class is a bit tricky to use right. :-/
12:15Sir_Diddymusyup. probably wrong syntax or something.
12:19Chousukeaa
12:19Chousukeoops.
12:24Sir_Diddymusnope, still doesn't work. :(
12:24Chouserlisppaste8: url?
12:24lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
12:24ChouserSir_Diddymus: shows us what you've tried?
12:25Sir_Diddymusk... sec...
12:30lisppaste8Sir_Diddymus pasted "calling a protected final method?" at http://paste.lisp.org/display/87106
12:32lowlycoderis there any reason to use clojure from git instead of the latest stable?
12:32ChouserSir_Diddymus: what error do you get?
12:33Sir_DiddymusThis is the signature of the method: protected final void beginInsertRows(com.trolltech.qt.core.QModelIndex parent, int first, int last)
12:33Sir_DiddymusThis is the error:
12:34Sir_Diddymusjava.lang.IllegalArgumentException: No matching method found: beginInsertRowsSuper for class name.space.XStoreListModel
12:36ChouserSir_Diddymus: do you have repl-utils from contrib?
12:36Sir_DiddymusSomehow I can't believe that it shouldn't be possible. Would be a real bummer though, if it really didn't work.
12:36Sir_Diddymusyeah, i think so...
12:36Chousertry (show name.space.XStoreListModel)
12:36Sir_Diddymusafter loading the class?
12:37Chousersure, or just have compiling it.
12:38Chouserthat should list all the defined methods.
12:39Chouserand should allow you to see if beginInsertRowsSuper is generated at all, or if it's the arg types causing problems.
12:42stuartsierra~seen dysinger
12:42clojurebotdysinger was last seen quiting IRC, 790 minutes ago
12:42Sir_Diddymusnope... no begin* method found.
12:43Sir_Diddymusok, compiled it again to be sure, but not listed.
12:46Sir_DiddymusI thought that I read somewhere that the combination "protected final" is the problem. But that would practically mean, that frameworks like Qt aren't (fully) usable.
12:55icylisperhow to get a list of all functions defined in a given namespace ?
12:57tmountainicylisper: ns-map ?
12:58icylisperah thanks. will check
12:58tmountainnp
13:00icylisperum-, dont see how i can filter the defns.
13:03tmountainlooks like ns-interns is actually better for what you want
13:03icylisperor maybe ns-publics
13:03tmountainuser=> (ns foo)
13:03icylisperthanks :)
13:04tmountainfoo=> (defn sum [a b] (+ a b))
13:04tmountainuser=> (ns-interns 'foo)
13:04tmountain{sum #'foo/sum}
13:04tmountainnp, I'm figuring this out as I go, so I'm wrong a lot ;-)
13:04Chousukeicylisper: (filter (fn [[k v]] (fn? v)) (ns-interns 'whatever))
13:04tmountainyeah, that looks good
13:04Chousukeoh but wait
13:04Chousukeit's vars
13:05Chousukeyou need (deref v)
13:05icylisperah.
13:05Chousuke(or @v :P)
13:05icylispercool. thanks Chousuke.
14:02criosclojurebot: logs?
14:02clojurebotlogs is http://clojure-log.n01se.net/
14:17criossir_diddymus, your problem can be related to the ticket http://www.assembla.com/spaces/clojure/tickets/126-abstract-superclass-with-non-public-accessibility ?
14:18Sir_Diddymuscrios: thanks, taking a look...
14:20crioscheck this also: http://groups.google.com/group/clojure/browse_thread/thread/d1fbdb7450b46dee/b5539e4a21c411c6?pli=1
14:20criosunluckly I'm too much newbe on Clojure , to be of any help to you :)
14:24Sir_Diddymushm... I'm not really sure if both of them apply, since I have a derived class and inside of that, I'm trying to call a protected final method of the superclass. I can call public methods from the abstract superclass just fine.
14:24Chouserthat second link is solved with :post-init
14:25Chouserthe first I don't think applies
14:25Sir_DiddymusWell, to be correct, the public method I can call are in the abstract base class, as well as the superclass...
14:25ChouserI've got a stand-alone example that reproduces the problem.
14:25Sir_Diddymuss/method/methods/
14:28crios_this patch? http://code.google.com/p/clojure/issues/detail?id=45
14:28Chousermaybe something's wrong with my .java
14:28Chouseroh. duh...
14:28Chousercrios_: yes
14:29crios_ 'this' and 'super' Java keywords cannot be used into Clojure interop. code?
14:30Chouser'this' and 'super' are not special words in clojure (expcept for 'this' inside 'proxy' forms)
14:31Sir_Diddymuscrios_: when extending a class, the first parameter in the methods (overridden as well as :exposed) get set to "this", you can call it however you want, as far as I know...
14:31ChouserSir_Diddymus: maybe I've just misunderstood gen-class and mislead you. Maybe exposes-methods just doesn't work on protected methods.
14:32Sir_DiddymusChouser: yeah, that's what a gathered from reading the API docs. And by trying. ;)
14:33lisppaste8Chouser annotated #87106 ":exposes-methods not for protected?" at http://paste.lisp.org/display/87106#1
14:33Chousertime to check the code.
14:34Chouserif not past time :-/
14:40criosif i well remember, protected methods can be accessed just by subclasses. How clojure "proxy" the classes? by delegation?
14:41criosi mean, when you compile myns.pityme you get a its proxied subclass?
14:41criosor a clojure object which delegates to myns.pityme?
14:42Chousergen-class produces a subclass with a bunch of methods. Each method listed in :methods or defined as public by a superclass, you get a little method that delegates to a defn in the given namespace.
14:43Chouserbut you can use :init, :post-init, :exposes, and :exposes-methods to generate more methods that don't deletgate to defns in the same way, but hook other code directly into the generated class.
14:43criosok
14:44Chouserok, from the code, gen-class only considers for :expose-methods methods that are "non-private"
14:46Chouserit specifically excludes methods that are named "finalize" or are final.
14:47Chouser(or a few other things)
14:47ChouserI wonder if that clause for excluding final methods really makes sense for :exposes-methods.
14:48criosfinalize?
14:49criosmaybe when clojure exposes that methods with expose-methods, would give you a chance to "override" them?
14:50criosa sort of overriding, i mean
14:50Chouserwell that's the thing -- you're not overriding a final method, just providing a way to call it.
14:51Chouserthis list of non-private methods is used for a few other things -- I wonder if 'final' is good to exclude from those, but not :expose-methods
14:53Chouseroh, it's a Range. Not sure what that is.
14:54Chousersorry, wrong window.
15:11Sir_Diddymusso :exposes-methods is definitely not the way to go. But shouldn't I be able to just use the method, since protected methods are accessible to subclasses in Java world? Hm...
15:12Chouseryour clojure fn is not *in* the subclass, it's called by the subclass.
15:12Chouserwith reify you could call it directly
15:13ChouserI think your best bet for now would be to write a subclass in .java that has a public method that calls the protected one, and then subclass that (using either proxy or gen-class)
15:14Chouserand/or bring it up on the group and see if others have solved this problem. I wouldn't be surprised if this leads to a tweak of :exposes-methods
15:15Chouserno matter how much rhickey hates protected methods, they won't just go away. :-)
15:16Sir_Diddymusugh... not pretty. ;) Yeah, that's what I wondered. I mean ok, it's Java and not all to lispy, but then again this should crop up more than once - especially with GUI frameworks.
15:17Sir_Diddymusalready wrote a message to the group...
15:18Sir_Diddymusanyway, thanks for the help...
16:18LauJensenGentlemen, I hope you enjoy the read: http://www.dzone.com/links/scala_vs_clojure_lets_get_down_to_business.html
16:22triyoLauJensen: link to the actual post doesn't seem to work
16:23triyosays "Looks like you have a problem here sir/madam...."
16:23LauJensenargh
16:24Chousukewhy don't you just link directly to the blog post? :P
16:24strlenhttp://bestinclass.wordpress.com/
16:25strlenthat's where the post is
16:26strlenugh that blog post is wrong
16:26strlenscala will do tail recursion
16:26strlennot TCO
16:26LauJensenstrlen, try it, will bork at 3600! just like Clojure
16:26strlenand that isn't written in a way that it will do tail recursion
16:27LauJensenBut anyway, the DZone link works, you just need a hard refresh
16:27strlenLauJensen: it can do a true tail recursion
16:27Chouserah, I didn't catch that!
16:27strlenthe way that code is written in scala though -- on that page
16:27strlenisn't tail recursion
16:27strlenone sec
16:28strlenclojure will do tail recursion using 'recur'
16:28Chouserstrlen: you're right that TCO wouldn't fix that algorithm.
16:28strlennow you can't do true TCO
16:28strlenas in
16:28strlenit will only do tail *RECURSION*
16:28strlennot tail call optimization which is different as it works across functions
16:30LauJensenOh okay, I didn't make that distinction
16:30strlenbut both scala and clojure do tail recursion. clojure does it using 'recur' as clojure is dynamically typed (and there's no invokedynamic yet)
16:30ChousukeLauJensen: technically, Clojure doesn't have lazy evaluation. it only has lazy seqs.
16:31Chousukefunction parameters and such are still strict
16:31LauJensenChousuke: I know, #scala is going on the same thing right now
16:31strlenyou can also do future objects in scala for lazy evals
16:31strlenboth languages are fun that's what matters :-)
16:31Chouserthe examples both demo the correct transformation from non-tail to tail recursive structure
16:32strlenhttp://www.bluishcoder.co.nz/2006/07/scala-futures-and-lazy-evaluation.html
16:32strlenwoiw that's ancient blog post
16:32strlenhttp://www.scala-lang.org/node/49
16:33Chouser2006! Clojure didn't even exist
16:56hiredmanit would be nice if range worked on characters
16:57hiredman,(map char (range (int \a) (int \e)))
16:57clojurebot(\a \b \c \d)
16:58Chouser,(+ \a 1)
16:58clojurebotjava.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Number
16:59Chouser(range \a \e \u0001) ?
17:00Chousukehmm.
17:00Chouser:-)
17:00hiredmansure
17:00hiredmanI can understand (+ \a 1) not being valid, but (range \a \z) would be nice
17:01Chousuke,(map char (range (int \か) (int \さ))); let's see what happens with non-ascii :P
17:01clojurebot(\か \が \き \ぎ \く \ぐ \け \げ \こ \ご)
17:01Chousukeooh, it works.
17:02Chousukethough usually you wouldn't want the ones with the dots if you did that :)
17:02Chouserwell, range calls + internally -- fix + and I think range would Just Work
17:02Chousukeit's kind of like getting aAbBcCdD...
17:02hiredmanChouser: or just split the code path
17:04hiredman(if (instance? x Character) (make-int-and-call-range x) ...)
17:04hiredmanor something
17:18LauJensenGuys, feel free to drop a vote, I get the sense #scala isn't exactly going to help :) http://www.dzone.com/links/scala_vs_clojure_lets_get_down_to_business.html
17:23Chouserrhickey: landed?
17:27LauJensenIts been a good night on #scala
17:27LauJensen(23:27:34) mapreduce: LauJensen: I await part 3, Chuck Norris vs. Martin Odersky.
17:27LauJensen(23:28:06) LauJensen: "Chuck Norris doesn't do push ups - Rich Hickey won't let him"
17:27LauJensenI'll leave you with that, good night :)
17:47dthomasBefore I write a quick little "walk nested maps [produced from JSON]" function, is there something already written that I should be using? I actually just need to get a sequence of map entries that match a given predicate, traversing the whole nest of maps.
17:48Chousukedoes it have to preserve the structure?
17:48Chousukeif not, you could filter and flatten.
17:48dthomasI think no, not interested in the location of the matches within the tree.
17:49dthomasAh, flatten.
17:49Chousuke(doc flatten)
17:49clojurebot"([x]); Takes any nested combination of sequential things (lists, vectors, etc.) and returns their contents as a single, flat sequence. (flatten nil) returns nil."
17:49Chousukehm
17:50Chousukeno namespace still ;/
17:50Chousukec.c.seq-utils? :/
17:52dthomasYeah, found it. (flatten some-map) => () isn't what I was expecting.
17:53dthomas(Oh, (indexed), I wanted that the other day. Good to know it's there.)
17:57Chousukehm
17:57Chousuke,(flatten {:foo :bar :zonk {:a :b}})
17:57clojurebot()
17:58Chousukehuh.
17:58Chousukethat has to be a bug :P
17:58hiredmanChousuke: if the namespace has been use'ed in the sandbox namespace, then you don't get namespace information
17:58Chousuke,(flatten (seq {:foo :bar :zonk {:a :b}}))
17:58clojurebot(:foo :bar :zonk {:a :b})
17:59hiredman~def flatten
17:59Chousukedthomas: looks like you'll need your own function. take a look at tree-seq though.
17:59hiredman,(doc sequential?)
17:59clojurebot"([coll]); Returns true if coll implements Sequential"
17:59hiredman,(sequential? {})
17:59clojurebotfalse
17:59Chousuke,(doc tree-seq)
17:59clojurebot"([branch? children root]); Returns a lazy sequence of the nodes in a tree, via a depth-first walk. branch? must be a fn of one arg that returns true if passed a node that can have children (but may not). children must be a fn of one arg that returns a sequence of the children. Will only be called on nodes for which branch? returns true. Root is the root node of the tree."
17:59hiredman^-
18:00Chousuke,(tree-seq (comp map? val) seq {:foo :bar :foo {:a :b}})
18:00clojurebotjava.lang.ClassCastException
18:00Chousukeoops.
18:01Chousuke,(tree-seq (comp val map?) seq {:foo :bar :zonk {:a :b}})
18:01clojurebotjava.lang.ClassCastException
18:01dthomastree-seq, that looks promising.
18:01Chousuke... okay I fail
18:02mabescan I coerce a vector into a a list of arguments? meaning.. if I have (def a [1 2 3]) and I want to call < on a so it would be (< 1 2 3), is that possible?
18:02Chousuke(apply < a)
18:02mabesChouser: cool, thakns. just playing/learning clojure now- so sorry for the probably simple question :)
18:04Chousukesimple questions are fine
18:04Chousukeeasy to answer so I can look like a wise sage or something :P
18:09lisppaste8beutdeuce pasted "Efficiency question" at http://paste.lisp.org/display/87136
18:18Chousukebeutdeuce: with reduce, * is a function call every time and you have a lazy seq too. in the explicit loop, there is no laziness involved and * can be inlined.
18:18Chousukebeutdeuce: is this git master or 1.0.0?
18:19beutdeuce1.0 i believe
18:19beutdeucenot the 1.1.0 snapshot
18:19beutdeucethere are changes?
18:19beutdeuce*significant* changes?
18:20Chousukeyes.
18:20Chousuke:)
18:20beutdeuce:) for example?
18:21Chousukesome performance improvements for reduce et al via chunked seqs, transients, hmm... reify coming soon I guess.
18:21Chousukeenough that I have lost track of it all :P
18:22beutdeucesounds exciting
18:22beutdeuceand it has been 2 years
18:22hiredmanuh
18:23hiredmannope
18:23Chousuke2 years since what?
18:23hiredman1.0 was months ago (5?)
18:23Chousukeoh and then there's the JDK forkjoin library thing which seemed rather impressive.
18:23ChousukeJDK7*
18:23beutdeucesweet! and ya, i forgot about 1.0
18:24beutdeuceis jdk 7 even mainstream?
18:24Chousukebut, help. my emacs is no longer treating my option key as alt :(
18:24Chousukebeutdeuce: nope, but the library is already available as a separate download for 1.6 too :)
18:26beutdeucei should try that out. I read in an article somewhere (i forgot) about the vm becoming very efficient and overpowering c++ in various different areas it used to drag behind in.
18:27beutdeuceis that sun java 7? or openjdk
18:30beutdeuce,(reduce (fn [n acc] (println (* acc n))) (range 5))
18:30clojurebotjava.lang.NullPointerException
18:30beutdeuce?
18:31Chousukebeutdeuce: I just tested
18:31Chousukebeutdeuce: on my computer the reduce version is actually faster.
18:32hiredmanbeutdeuce: println returns nil
18:32Chousukebut your loop is not optimised so that's not so surprising :)
18:32beutdeuceoh right
18:32beutdeucehow much faster?
18:32Chousukenot much
18:32beutdeucefaster than tail-recursion in that example?
18:33Chousukeabout 30-40ms on average
18:33Chousukebut hm, let me see if I can optimise the loop and see what that does.
18:33Chousukehahah
18:34ChousukeI got an integer overflow
18:34Chousukefigures
18:34beutdeuce:P
18:34Chousukelooks like there's no getting around using bignums
18:34Chousukeso reduce wins :P
18:35beutdeuceReduce | Recur || 1 | 0
18:35beutdeucesay, anyone know how to get rid of that annoying emacs auto-paranthesis match?
18:36Chousukeauto-parenthesis?
18:36Chousukeannoying? :)
18:36beutdeucelike, i cant close paranthesis until i delete whats between them
18:36beutdeuceit doesnt let me
18:36Chousukeyou don't want to get rid of that
18:36Chousuketrust me
18:37Chousukejust learn to use paredit instead
18:37beutdeuceparedit?
18:37Chousukeit's what the thing is called
18:37beutdeucek
18:37beutdeucewell
18:37beutdeuceits just that it glitched, so i had an open paran, but i couldnt delete it cause it said it was unmatched, i didnt see where the closing one was
18:37Chousukeit's "structured editing". it doesn't let you write s-exps that are "broken"
18:38beutdeucebetter now, restarted emacs
18:38Chousukeif you really have an unmatched paren, do C-q )
18:38Chousuke(C-q is "quote")
18:38beutdeucek, thnx
18:38Chousukeanyway, paredit can do much more than just match your parens.
18:39Chousukeyou can actually move around entire s-expressions.
18:39Chousukewithout fear of breaking them.
18:39beutdeucehmm, cool
18:40Chousukethe most common operations are barf and slurp: ctrl-leftarrow/rightarrow
18:40Chousukeand ctrl-k kills (cuts) a s-expression instead of a line
18:40tomojarrows? blasphemy :P
18:40Chousuketomoj: the real combo is something weird.
18:41Chousukearrows are easier.
18:41tomojC-(, C-), C-{, C-}
18:42tomojI don't like having to reach all the way over to the arrow keys :/
18:42ChousukeC-{ is impossible on my layout and C-( is nothing nice either.
18:42tomojyeah
18:42tomojprogrammer's dvorak here so those are really easy :)
18:42mDufftomoj, ...hmm; how is that to learn coming from traditional dvorak?
18:43tomojmDuff: not too bad
18:43tomojI'm still not used to the numbers
18:43beutdeucedoes println do *out* ?
18:43Chousukebeutdeuce: http://www.aaronfeng.com/articles/2008/03/23/barf-and-slurp-with-paredit
18:44beutdeucenice
18:44ChousukeI don't think I'll be able to edit lisp code without that anymore ;(
18:45tomojmDuff: I can't imagine at this point doing lisp (especially clojure, with its []s and {}s) with normal dvorak now
18:58hlshipQuestion about getting patches, to clojure-contrib, accepted.
18:58hlshipI attached a patch to ticket #24 about three weeks ago
18:59hlshipI don't have commit access
18:59hlshipwho should I assign it to, to get the patch committed?
18:59hlshipOr is there a special status?
18:59hlshiphttp://www.assembla.com/spaces/clojure-contrib/tickets/24
19:47emacsenHey. I have a question. This page: http://www.geotools.org/quickstart.html#quickstart says that I need to set up a maven project for java inclusion. How would that work with a Clojure program?
19:56interferonis there a clojure function that might be called "group-by" which takes a sequence and returns a map that groups the elements of the sequence by a function?
19:56hlshipsorry .. had to leave; any answer to my prior question about patches?
19:58Potplantinterferon: sure is. clojure.contrib.seq-utils/group-by
19:59_mst,(clojure.contrib.seq-utils/group-by #(mod % 5) (range 20))
19:59clojurebot{0 [0 5 10 15], 1 [1 6 11 16], 2 [2 7 12 17], 3 [3 8 13 18], 4 [4 9 14 19]}
20:02interferongreat!
20:02interferonthanks
20:03interferonand congratulations on parsing my mess of a sentence :)
23:53danlarkinwtb rich hickey :)