#clojure logs

2010-06-01

00:23mebaran151I'm having some slime trouble
00:23mebaran151whenever I try to C-c C-k it fails to compile-file-for-emacs
00:31Raynesmebaran151: It fails to find the command?
00:32mebaran151wrong number of args passed
00:32mebaran151slime starts up, and I can run basic commands, but I can move any clojure from the edit buffer to the repl
00:32RaynesWrong number of args passed to compile-file-for-emacs?
00:32mebaran151yep
00:33mebaran151wrong number of args passed to basic$eval--986$compile-file-for-emacs
00:33mebaran151thrown by a working slime
00:33RaynesC-c C-k is bound to slime-compile-and-load-file
00:33RaynesNot compile-file-for-emacs.
00:34RaynesTry doing M-x slime-compile-and-load-file and see what happens.
00:34mebaran151same problem
00:35mebaran151actually C-c C-c works
00:36RaynesHrm.
00:36mebaran151it got a def
00:36mebaran151could it be a mismatch between my slime and clojure versions
00:36mebaran151I downloaded clojure-1.2 and I think I'm running swank-clojure-1.2
00:37Raynesmebaran151: Are you using leiningen for this project?
00:37RaynesThe latest version of swank-clojure is 1.2.1.
00:37mebaran151right now I'm not using leiningen
00:38RaynesShouldn't be any problems with whatever version of Clojure you're using.
00:38mebaran151I just swank-clojure-project to slurp up the jars in my lib dir
00:38Raynesmebaran151: I'd suggest asking on the swank-clojure mailing list, perhaps linking to this discussion.
03:07bozhidarhey, guys - how can one access the a resource in the resources folder of a lein application?
03:08bozhidarin Java I'd do a getResourceAsStream("/the/package/the_resource")
03:08bozhidarshould I use the same code or is there something more idiomatic?
03:14tomojas far as I know there is nothing more idiomatic
03:14tomojI think something like (.getResourceAsStream (clojure.lang.RT/baseLoader) ...)
03:15bozhidarI see
03:17lessthantristanyeah, I've always just used the line tomoj suggested. i've never asked about a more idiomatic form tho :)
03:21bozhidarlessthantristan: I have nothing against the Java interop, after all I'm a Java dev
03:22bozhidarthat said I enjoy idiomatic clojure a lot more, when available ;-)
03:33tomojI guess ideally this bit of java interop will be wrapped over with pretty clojure
03:33tomojI mean, e.g. enlive wraps over it so that a user of enlive never has to write it
04:06LauJensenMorning guys
04:06bozhidarMorning :-)
04:08sparievmorning Lau
04:24bartjmorning Lau
04:36bartjer, is it possible to call c++ from clojure (planning to call webkit functions)
04:38LauJensenbartj: There's a project which was/is called clojure-native (see the group), which allows you to do that
04:43bartjI am only able to see chouser's clojure-jna
04:43Licenser_mornin g
04:43LauJensenhttp://groups.google.com/group/clojure/browse_thread/thread/f0cc00d87912878b/467dc469f45498bd?lnk=gst&q=clojure+native#467dc469f45498bd
04:43LauJensen@ bartj
04:45esjMorning All
04:45LauJensenMorning esj
04:48chuckleranyone here using emacs23 and clojure-mode?
04:49tomojplenty
04:51LauJensenchuckler: all the cool kids
04:51LauJensenand tomoj ...
04:51LauJensen:)
04:51tomoj:(
04:59bozhidarm2
04:59bozhidar:-)
05:40bartja bit off topic - a question on sampling
05:41bartjA= (1 2 3 4 5), B = (1 2 3)
05:42bartjclearly B is a subset of A, but if I choose the wrong sampling set ie. (4, 5) then I will conclude wrongly
05:42bartjhow do I prevent this?
05:43bartjie. what is the best way to sample so that, I can check for common elements?
05:47LauJensenbartj: Do you just want to know if they intersect ?
05:47tomojyou want to guess whether B is a subset of A based on a limited number of inclusion checks?
05:48LauJensen$(clojure.set/intersection #{1 2 3 4 5} #{1 2 3})
05:48sexpbotjava.lang.ClassNotFoundException: clojure.set$intersection$fn__5560
05:48LauJensen$(intersection #{1 2 3 4 5} #{1 2 3})
05:48sexpbotjava.lang.Exception: Unable to resolve symbol: intersection in this context
05:48tomoj"B subset A" means "if it's in B, it's in A", so seems like picking random elements from B and checking whether they're in A would be the best way
05:48LauJensenok, experiment in your own rpel :)
05:48LauJensenand swap letters where appropriate
05:49bartjLauJensen: actually, what elements should I pick from a given set to know that they intersect
05:50bartjie. if two sets A and B intersect, and all my samples are from (A-B) then, I would conclude that they don't intersect
05:51bartjis there any way I can avoid this...
05:51tomojsuppose A and B each have 1000000 elements, and their intersection has just one element
05:51tomojyou're gonna have to get pretty damn lucky no matter how you sample
05:52bartjtomoj: yeah you are right!
05:54bartjtomoj: we could perhaps set a limit of 10%?
05:54tomojit shouldn't be too hard to find the probability, hmm
05:55bartjtrouble is, if all the 10,000 elements you picked are from (A-B)?
05:55tomojright, but we can calculate the probability of that
05:55tomojand so get some idea of how likely it is that they intersect given the evidence
05:55tomojdo you know the sizes of the sets?
05:56bartj5L and 1L
05:56bartjhave another one which is 1M and 2L
05:57G0SUBLauJensen:
05:57tomojwhat's "L" stand for?
05:57bartjlakh
05:57G0SUBwhat?
05:57clojurebotwhat is wrong with you
05:57konrJust out of curiosity: do you guys still use common lisp? If so, for what?
05:57bartj5L = 5,00,000
05:57tomojah, 100000?
05:57G0SUBbartj: are you from India?
05:58bartjGOSUB: yep!
05:58bartjI guess we use that here a lot...sorry!
05:58tomojin america we are doomed to say 500K I guess
05:58G0SUBbartj: I am from India too.
05:58tomojtwo extra characters :(
05:59tomojI think you want to be sampling from the smaller set
06:01bartjtomoj: I still wouldn't want to pick all the 200,000 entries to compare against the 1M...
06:02bartjtomoj: that is, I do not want the sample size to be 200,000
06:02tomojright
06:03tomojbut you will have a better chance of discovering the intersection if you sample from the smaller set
06:04G0SUBLauJensen: did you read my blog post on protocols?
06:07tomojbartj: hmm.. the probability that you will discover the intersection with N checks depends on the size of the intersection
06:07LauJensenG0SUB: I did actually :)
06:07tomojso it's more difficult than I thought
06:07LauJensenAnd I find your style of writing very compelling, must loot
06:07G0SUBLauJensen: oh, thanks, Lau. it's very valuable.
06:08tomojI guess we can assume you've made N checks and haven't found any common elements
06:09bartjtomoj: yes you are right
06:10bartjtomoj: one obvious way would be to increase the size of N
06:10bartjtomoj: but, I want to know the upper limit of N
06:16tomojwell, hmm
06:23bozhidarG0SUB: can you post a link to this blog article?
06:23tomojI don't think you can get any good handle on the probability that there is any intersection at all
06:23G0SUBbozhidar: http://freegeek.in/blog/2010/05/clojure-protocols-datatypes-a-sneak-peek/
06:23tomojI think you may be able to get a good idea about the probability that there is an intersection of some size X
06:23bozhidarG0SUB: 10x
06:25tomojif you sample 50% of the smaller set, I think you can be only 50% sure that there is no intersection at all
06:25tomojbut if you look for intersections of size X instead of any intersection you can do much better
06:28bartjtomoj: I am not sure I understand
06:29tomojthere is always the possibility that the sets share only one element
06:29tomojand in that case, the problem is just to find that element
06:29bartjtomoj: yes
06:30tomojwhich means if you sample 50% of the smaller set, you can only be 50% sure there is no such element
06:31Licenser_hmm is there any template engine in clojure that is somewhat like erb?
06:31tomoj:(
06:32bartjtomoj: yes
06:43G0SUBbozhidar: did you read it?
06:44bozhidarG0SUB: just started
06:44G0SUBbozhidar: oh, OK. feedback appreciated :)
06:52bozhidarG0SUB: great article, you've introduced a new concept in a clear and very understandable way
06:52bozhidarthe swine flu part was very funny :-)
06:53bozhidarand I was surprised to find out that there is now a workaround allowing one to extend final Java classes(like String) in Clojure
06:54G0SUBbozhidar: thanks a lot.
06:54LauJensenhehe. Im glad we spent 56 billion USD on Swine Flu vaccines that nobody wanted, imagine if the whole world went around sneezing for 3 days :)
06:54bartjtomoj: thanks
06:54bartjtomoj: ...for your help
06:54G0SUBbozhidar: yeah, that basically solves the expression problem
06:55patrkrisrhickey: just out of curiosity, which came first: persistent data structures or STM?
06:55bozhidarG0SUB: protocols support only single dispatching, right?
06:56G0SUBbozhidar: right. for arbit dispatch, you need multimethods
06:56patrkrisrhickey: in Clojure, that is
06:56G0SUBbozhidar: in case you need only type/class based dispatch, use protocols :)
06:56rhickeypatrkris: persistent data structures. Without them, I don't think STM works
06:57bozhidarG0SUB: I imagine so, it's just that in the beginning multimethods are always marketed as vastly superior to single dispatch based on the type
06:57rhickeypatrkris: but thinking about how STM might work added to the desire for pds as the default
06:58bozhidarand later we see such a feature introduced :-)
06:58G0SUBbozhidar: superior, but slow :)
06:58patrkrisrhickey: ah... but when you initially started developing Clojure, did you know that you wanted to have STM in it?
06:59patrkrisrhickey: I am just wondering whether it is correct to say that Clojure was designed from the beginning to include STM.
06:59rhickeypatrkris: I knew I wanted another model for state
07:00rhickeypatrkris: It's not necessary like there was a clear point of "I'm going to write a language and this is what will be in it". More like a lot of ideas swirling around, among which was adding direct perception to the Actor model, which also pointed to pds and some sort of reference types
07:01rhickeywhat I knew was, I wanted 'doing the right thing' with state to be automatic and enforced, without adopting a static type system
07:02rhickeyeventually there was enough alignment between all the ideas to make Clojure inevitable
07:02patrkrisrhickey: Interesting. Another thing out of curiosity: When did you write the first line of code for what was to become Clojure? :)
07:05rhickeypatrkris: sometime in 2005
07:06rhickeysourceforge project started in May 2005, so at that point I knew I was doing a language, and its name
07:06SinDocI evaluate [1] and get: java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.Symbol (pair.clj:1) Any ideas?
07:06SinDoc[1] http://github.com/sindoc/algorithms/blob/master/src/clojure/main/com/khakbaz/algorithms/clojure/memory/fixed/manual/pair.clj
07:06G0SUBrhickey: would you mind if we create your action figure? It would be a very cool addition to our office desks.
07:07Licenser_SinDoc: it is in a require
07:07patrkrisrhickey: Thanks for taking your time to answer my questions. :)
07:09SinDocLicenser_: I'm not sure what's wrong with that!
07:15G0SUBSinDoc: (:require [com.khakbaz.algorithms.clojure.memory.fixed.pair :as p])
07:17Licenser_SinDoc: one of the files you require is wrong
07:17G0SUBSinDoc: you missed the manual part
07:18G0SUBSinDoc: I was wrong. sorry.
07:18SinDocG0SUB: Licenser_: There are actually two pair.clj files
07:18G0SUBSinDoc: saw. sorry
07:18SinDocThanks G0SUB what you said, worked
07:19G0SUBSinDoc: yeah, the syntax was wrong. your ns name was correct :)
07:20rhickeyurk - why are there clojure jars in clojars?
07:20rhickeywhen there is build.clojure.org
07:21Licenser_rhickey: I think clojars subdirectories clojars
07:21rhickeyand is there a way to force maven to get clojure and contrib jars only from build.clojure.org?
07:21Licenser_but I'm not sure if that is what you mean
07:25SinDocThank you folks! See you soon ;)
07:32G0SUBrhickey: a lot of people are asking how protocols are different from haskell's type classes and Go's interfaces. what is the right answer to this question?
07:32rhickeyG0SUB: sounds like 2 questions to me
07:33G0SUBrhickey: I grouped them together for brevity.
07:33G0SUBrhickey: you can give me two answers :)
07:36rhickeythey differ from Haskell's type classes (from which they draw partial inspiration) in that the dispatch map isn't an independent entity passed around by the type system, and thus can't do return-type based method selection, and generally in that they are not static-type-system-based.
07:37G0SUBrhickey: thanks!
07:38rhickeythey differ from Go interfaces in that Go just uses method conformance to determine interface support (vs explicit declaration of 'I implement this protocol'), and Go's interfaces, last time I checked, were only 'open' within a module.
07:38G0SUBah
07:39rhickeyIf one said Clojure's protocols were like dynamic type classes you wouldn't offend me (but might offend some Haskellers)
07:39G0SUBheh
07:39rhickeybut they are not very much like Go interfaces at all
07:41G0SUBwhenever Blub programmers look at protocols, they say it's identical to the Transmogrify feature in Blub.
07:42rhickeyG0SUB: the differences can be subtle, but are important
07:43G0SUBrhickey: indeed.
07:43G0SUBIt's like saying Agents are identical to Actors
07:43cemerickrhickey: maven will grab dependencies from whereever it can get them, I believe. Stricter controls require the use of a proxy (e.g. nexus).
07:43cemerickclojars is a bit of a swamp w.r.t. following maven conventions
07:44rhickeycemerick: then I'm concerned about people putting their own Clojure jars in clojars
07:44cemerickrhickey: yeah, it simply shouldn't happen
07:44cemericksame goes for sha version numbers, misuse of classifiers, etc etc
07:46cemerickI'm guessing most people don't know that they're using a maven repo, and so without indications to do otherwise, they do what seems to make sense at the time, etc.
07:46AWizzArdcemerick: what do you mean by thas "sha version numbers" thing? Is it that some people try to depend on a specific version via hash, and that is not good?
07:46rhickeybut something must have driven people to use clojars for Clojure vs build.clojure.org
07:47cemerickAWizzArd: I mean artifacts published with a sha1 version number instead of something like 1.5.9 or whatever.
07:47AWizzArdOh okay, yes.
07:47cemerickrhickey: I presume just not knowing what should be done. Probably best to ping whoever pushed the libs to see what's up.
07:48cemerickbleh, no authorship notation in the accompanying poms
07:49cemerickrhickey: I'd say ato should just rm org/clojure/*, and make that dir read-only.
07:50cemerick*anyone* can push stuff up into clojars, which is good and bad
07:50cemerickeh, ok, so it's probably just all bad :-)
07:52bozhidarcemerick: giving anyone access to something always ends bad :-)
07:53cemerickrhickey: if there's to be any infrastructure managed by clojure/core, dropping a nexus instance on it as well would be a wise thing, I think. That'd presumably require some coordination with technomancy|away, insofar as lein pushes at clojars by default (or, exclusively?).
07:54cemerickbozhidar: it's fine as long as you can see who did what when :-)
07:54rhickeycemerick: is nexus free for open source?
07:54cemerickrhickey: and for closed source as well :-)
07:54cemericknexus pro costs, but the free version is extraordinarily full-featured.
07:55cemerickproxying, access control, host as many repos as you want, repo aggregation, etc.
07:57cemerickLooks like LDAP and P2 itnegration are the big additions in Pro http://nexus.sonatype.org/
07:57cemerickintegration*
07:59cemerickrhickey: have you been following the java closure goings-on much?
08:00rhickeycemerick: not too much, I like #() though :)
08:00cemerickheh, yeah
08:01cemerickI saw this as a "function type", and almost fell over though: #int(int, int)(throws IOException | SQLException) plusClosure = #(int
08:01cemericka, int b) (a+b);
08:02rhickeychecked exceptions showing their inherent evil again, will be the downfall of Java closures
08:02cemerickI can't imagine anyone's going to use that stuff.
08:02cemerickit seems like Oracle would be doing everyone a favor if they just got the non-Java language principals in the room, and did what they wanted (forgetting Java)
08:04rhickeygetting rid of checked exceptions and adding a smattering of inference would go a long way, neither in the cards afaik
08:04G0SUBlol
08:06rhickeyI'd be happiest if Java would just stay as-is, BUT, there is one very important side-effect of getting closures in to Java, which is: then (and only then?) they may start looking at the optimizations needed for higher-order functions like map et al
08:07cemerickgah, we'll probably have to type-hint our fns! :-x
08:07cemerickSeems like there's a *lot* of interop pain coming down the pike.
08:07rhickeycemerick: nope - Object, Object, Object...
08:08bobo_cemerick: that example is just the absolute worst scenario though, for everyday use it wont be THAT ugly, still ugly though
08:08rhickeycemerick: yes, interop the problem for alternate langs. Wanna bet the reflection story for these will stink?
08:08cemerickrhickey: but if Java libs start requiring function params of type #int(int, int)?
08:08cemerickoh, right, erasure
08:09cemerickthough I saw someone on the mlvm list talking about "fixing" erasure not too long ago
08:09rhickeycemerick: depends
08:09rhickeycemerick: erasure is the best thing ever
08:10cemerickyeah; I caught a glimpse of what D. Miller is having to deal with with ClojureCLR, and felt bad for him.
08:11rhickeycemerick: yes, people don't realize the huge tradeoff involved in the CLR approach. It greatly complicates life for everyone, and is a poor fit for dynamic langs
08:12G0SUBby erasure, do we mean type erasure here?
08:12cemerickyeah
08:12cemerickrhickey: I presume the DLR doesn't just make it all go away magically?
08:12rhickeycemerick: nope
08:14bozhidarrhickey: can we expect some dramatic performance improvements on JDK 7 because of http://java.sun.com/developer/technicalArticles/DynTypeLang/
08:15bozhidarI read somewhere that to reap the benefits one has to rewrite a lot of him current implementation however
08:16bozhidarhis*
08:17rhickeybozhidar: no, most of what you can do with invokedynamic you can do without it, it's just a bit cumbersome. But we've all done it already
08:18rhickeyand few langs will want to be Java-7 only
08:19bozhidarrhickey: I've read some article from Charles Nutter from JRuby in which he claimed this invoke dynamic will be the holy grail of dynamic languages targeting the JVM
08:19rhickeyIt would have been better if they had just made classes themselves cheaper and faster
08:20bozhidarhe mentioned that JRuby's performance will increase 10 fold, so I was wondering is Clojure affected in a similar manner
08:20bozhidarprobably an implementation detail?
08:20rhickeybozhidar: is he still saying that today?
08:20bozhidarrhickey: let me look up some articles
08:21bobo_i think that mainly is because of heavy Reflectionusage they can remove
08:21rhickeymethod handles are just going to be an entirely new thing hotspot et al are going to have to be taught to optimize. They are already awesome at optimizing ordinary class method dispatch
08:22rhickeybobo_: invokedynamic is not needed for removing reflaction
08:22rhickeyreflection
08:22bobo_no, but i think that is what nutter was saying.
08:22bobo_that jruby has loads of reflection, and they might remove that with invokedynamic
08:22rhickeyit is just a different way of doing call site caches, which you can already do today with classes and methods
08:23bobo_was long ago i read the article though.
08:23bozhidarrhickey: the only article I find is a bit old - http://blog.headius.com/2008/09/first-taste-of-invokedynamic.html
08:23rhickeybut, you end up with a lot of classes, so, IMO, make that cheaper
08:23bozhidarmaybe he has reconsidered indeed :-)
09:12SinDocI evaluate a .clj file and would like to interact with it using REPL. How can I have REPL automatically switch to a namespace other than the user ns?
09:13SinDocI use IntelliJ and LaClojure
09:35bartjis there a better way to filter nils then do - (filter (complement nil?) [nil 1 2 nil nil])
09:35bartj,(filter (complement nil?) [nil 1 2 nil nil])
09:35clojurebot(1 2)
09:36pjstadig,(remove nil? [nil 1 2 nil nil])
09:36clojurebot(1 2)
09:40bartjpjstadig: thanks
09:40cgrandSinDoc: (in-ns 'foo)
09:40pjstadignp
09:42G0SUBbartj: if you see yourself using double negative verbs, know that there must be a positive verb too :)
09:42SinDoccgrand: I've been trying that BUT without the quote
09:43bartjG0SUB: thanks!
09:43G0SUBbartj: np :)
09:46SinDoccgrand: I put (in-ns 'myns) in code but after evaluation, it's still in the user namespace
09:47cgrandSinDoc: enter it at the repl
09:47SinDocThat's kinda the reason why I asked
09:48SinDocI was hoping to make that implicit somewhere
09:48cgrandhow do you eval your file?
09:49SinDocI create a Run configuration for it in IntelliJ and simpley 'Run' it.
09:49SinDocThen it evaluates my definitions but goes back to the user ns
09:54cgrandok, too LaClojure specific for me then, sorry
09:54SinDocThanks cgrand
09:57bozhidaris there some existing way to take items in frame fashion from a sequence
09:57bozhidarfor example I have 1 2 3 4 5
09:57bozhidarfirst I take 1 2 3
09:57bozhidarthen 2 3 4
09:57bozhidar3 4 5
09:58bozhidarthe frame being x items wide and advancing by one each time
09:59vu3rdd,(partition 3 1 [1 2 3 4 5 6])
09:59clojurebot((1 2 3) (2 3 4) (3 4 5) (4 5 6))
09:59JorejiHey guys, I'd like to set a clojure variable from java code, is it possible to do it like this: String path = "/data/clojure/classes"; Var.pushThreadBindings(RT.map(Compiler.COMPILE_PATH, path));
10:00vu3rddbozhidar: is that what you want?
10:00bozhidarvu3rdd: perfect, totally forgot about partition
10:01bozhidarvu3rdd: thanks
10:01vu3rddbozhidar: no problem.
10:01G0SUBvu3rdd
10:01vu3rddG0SUB: hi
10:02G0SUBbozhidar: also, don't forget partition-all :)
10:02G0SUBvu3rdd: how are you?
10:02vu3rddG0SUB: fine. Was sick for the past 3-4 days. Back to work today
10:02G0SUBvu3rdd: Can I PM you?
10:02vu3rddG0SUB: sure
10:03bozhidarG0SUB: never new about partition-all, what is its deal?
10:04spariev,(partition 3 [1 2 3 4])
10:04clojurebot((1 2 3))
10:04spariev,(partition-all 3 [1 2 3 4])
10:04clojurebot((1 2 3) (4))
10:04hoeckJoreji: not shure, but I believe pushThreadBindings is the same as of binding in clojure, so it shares its limitations
10:04G0SUBspariev: bravo!
10:04bartj, (partition 3 2 [1 2 3 4 5 6 7])
10:04clojurebot((1 2 3) (3 4 5) (5 6 7))
10:05bartjstep=2 and still the same results?
10:05G0SUB,(partition 3 2 [1 2 3 4 5 6 7 8])
10:05clojurebot((1 2 3) (3 4 5) (5 6 7))
10:05sparievG0SUB: this difference struck me badly last week )
10:05hoeckJoreji: Var.alterRoot(...) alters the root binding, which is a bit more like "setting" the var
10:06hoeckJoreji: though I've never interfaced clojure from java, only the other way around :P
10:07G0SUB,(partition 3 2 [1 2 3 4 5 6])
10:07clojurebot((1 2 3) (3 4 5))
10:07G0SUBbozhidar: ^^^
10:07Jorejihoeck: Thanks, I'll try that out!
10:08G0SUB,(partition-all 3 2 [1 2 3 4 5 6])
10:08clojurebot((1 2 3) (3 4 5) (5 6))
10:08G0SUBbozhidar: ^^^
10:08bozhidarI see
10:09bozhidarG0SUB: 10x
10:10G0SUBbozhidar: np
10:11bartj,(doc partition)
10:11clojurebot"([n coll] [n step coll] [n step pad coll]); Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap. If a pad collection is supplied, use its elements as necessary to complete last partition upto n items. In case there are not enough padding elements, return a partition with less than n items."
10:12bartjwhat does "offsets step apart" mean?
10:14cgrandrhickey: any chance that #353 and #362 are related?
10:29hugodcgrand: thanks for finding the cause of #368. I have also been having issues with redefining multimethod dispatch functions which I assume is related. Makes interactive development very frustrating :(
10:31cemerickhugod: that's a known issue at the moment, noted in #309
10:31hugodcemerick: thanks, hadn't spotted that one
10:33cemerickseems like #368 should be moved into 1.2, no?
10:34cgrandwho decieds what's in &
10:34cgrand1.2
10:35pedroteixeiraone would create a new Exception type using deftype or using someting else? is there any macro for this already?
10:36cemerickcgrand: Stu's the only one outside of Rich that I know of who's got carte blache to promote issue.
10:36cemerickissues*
10:37cemerickanyone *can* do it, of course, but that's not so polite :-)
10:37cemerickpedroteixeira: why are you wanting to create a new Exception type?
10:38pedroteixeiracemerick: sometimes it's useful, isn't? instead of returning error codes for ex. Just tested and this worked fine: (deftype DomainException [Exception]) (DomainException. "oops")
10:39cgrandcemerick: ok, we have the same policy
10:40cemerickpedroteixeira: It's pretty rare for new exception types to be useful IMO. It's not really idiomatic within Clojure, certainly.
10:40pedroteixeiracemerick: i'm builind a large application, some part of the code might throw exceptions that have known semantic and can be handled specificly in a different part of the code.
10:41pedroteixeiracemeric: ok, thanks. will think about it.
10:42Rayneshttp://groups.google.com/group/clojure/browse_thread/thread/ad7f33cc59ce13cb?pli=1 This guy is officially awesome.
10:42cemerickpedroteixeira: if there's actually a recovery path available, then I'd consider it. Most applications don't have a reasonable recovery path though.
10:43cemerickOtherwise, IllegalArgument, IllegalState, IOException, etc. are good for 95% of the "oh, shite" error conditions that are likely to arise.
10:43nDuffWhat's the appropriate concurrency device to use for hashing a large tree of files? Agents, promises and futures all look potentially interesting.
10:43pedroteixeiracemerick: my current case is to handle possible ConflictException that has an entity with version. Different use cases, might retry and some might just return an error to the user.
10:44pedroteixeiracemerick: alright, i'm aware of those also ;)
10:46hugodpedroteixeira: you might also want to look at clojure.contrib.condition
10:47pedroteixeirahudod: thanks! looks useful
10:54islonhow can I access an inner java class in clojure? I want to use javax.mail.Message.RecipientType
10:54sparievjavax.mail.Message$RecipientType , IIRC
10:55pedroteixeirahudod: i think clojure.contrib.condition suits my needs fine.. one generic exception to rule them all :)
10:55islonthanks =)
11:17jfieldscan you memoize method calls on an instance of a java object?
11:19cgrandjfields: you have to wrap the method call in a fn: (memoize #(.substring s %))
11:19pedroteixeirajfields: memoize operates on pure functions, you can probably more easily just wrap this java call to a particular object..
11:20jfieldscgrand, pedroteixeira: cool, thanks.
11:22cgrandhugod: http://github.com/richhickey/clojure/commit/f47b3d6f028e0370c495383731a449092d0ae451 fixes #368 too
11:22pedroteixeirajfields: sometimes, you don't want memoization for the entire lifecycle of your app (i.e. for memory constraints), then you can just bind the memoized function (the return of memoize) to a local scope.
11:38hugodcgrand: excellent :)
11:43pedroteixeiraare there any recommended way to serialize clojure records? (with-in-str (binding [*print-dup* true] (pr-str (Foo. "bar"))) (read)) gives an exception.
11:43_fogus_dnolen: ping
11:43dnolen_fogus_: pong
11:43_fogus_dnolen: Do you mind if I use clj-cont in a presentation?
11:44dnolen_fogus_: not at all, I saw that you forked it.
11:44dnolen_fogus_: what is the presentation going to be about?
11:45_fogus_dnolen: Thanks! Delimited continuations (probably)
11:48hiredmanping?
11:48clojurebotPONG!
11:48_fogus_dnolen: I was going to use Scala for the preso, but thought better of it
11:49dnolen_fogus_: interesting, do you find the ideas easier to express in Clojure?
11:51_fogus_dnolen: I hadn't thought about it that way, but I would probably say yes.
11:57LauJensen_fogus_: glad you sobered up
11:59RaynesLauJensen: He puffed the magic dragon too many times last night.
12:01LauJensen_fogus_: You shouldn't focus on Scala daily, spend a little more time with Clojure before you finish the book please :)
12:13_fogus_LauJensen: What?! You don't like the latest chapter "Typed Clojure" ? :p
12:13LauJensenhaha
12:21dnolen_fogus_: so where do you feel that Scala's type system comes in handy when writing real programs? I've been wondering whether good type systems still make certain kinds of real world programming more tedious.
12:24_fogus_dnolen: Scala's type system has benefited me in a couple of ways. 1) We have a fairly static system that we spent many moons agonizing over the design and Scala's types served as (sort-of) documentation. and 2) Because our types are rock solid, I've found that if it compiles then it's correct.
12:25_fogus_However, I wouldn't want to do that same exercise (agonizing design) on every project
12:31cemerick_fogus_: I didn't agonize enough on my first scala project -- so when things had to change in some tiny way, I was faced with a boil-the-ocean refactoring. Not fun at all.
12:32_fogus_cemerick: That was definitely a problem at first, but I (erm.. we) buckled down and solidified the API.
12:32cemerickRight. More work always makes problems go away. ;-)
12:33_fogus_cemerick: I like to think I didn't work harder but.... uhhhh... well not smarter either. :p
12:33cemerickI generally assume I'm going to bork my first four shots at something, and it's oh-so-nice to just add a slot to a map that gets passed around everywhere instead of having to shatter my carefully-crafted domaint types.
12:34_fogus_cemerick: The borked part was the previous system.
12:41naeuhi there
12:42naeuI'm currently playing around with type hints trying to remove use of reflection for the core pathways of my system
12:42naeuhowever, I'm not having much luck in a particular case: (.write out-stream bytes)
12:43naeuI tried: (.write #^java.io.OutputStream out-stream bytes)
12:43naeubut the reflection warning still flags that line
12:43naeu(call to write can't be resolved.)
12:45cemericknaeu: there are both int and byte[] overloads for .write
12:45naeucemerick: oh ok, so how would I find that out?
12:45naeudo i need to inspect the javadoc, or is there a way i can ask clojure for this information?
12:45cemerickhrm; be familiar with the signatures of the methods you're calling, or have javadoc ready :-)
12:46naeualso, how would i type-hint byte[]
12:46cemerickit would be nice if the reflection warnings could point at whether the invocation target's type is unknown, or if it's trying to choose from a number of known overloads
12:46cemericknaeu: #^bytes should do it if you're using a pre-1.2 build
12:47cemerickotherwise, it's ^bytes
12:47naeucemerick: haha, I keep reading overlords instead of overloads
12:47naeuI like the idea of choosing from a number of known overlords
13:18KirinDavecemerick: pingggggg
13:19DeusExPikachuif I want to generate a fn that's code depends on runtime information, must I use eval?
13:19KirinDaveIf you want to let outside input build code, that is what eval does.
13:20KirinDaveBut it's very rare that it's necessary.
13:23DeusExPikachuso to be more precise, I want a `(fn [] ~@(for [f# my-runtime-vector-of-fns] (f#)), I'm thinking I can't use defmacro for this cause at compile time my-runtime-vector-of-fns is not defined
13:27DeusExPikachuhmm, I think that code is wrong too, cause f# needs to be symbols not fns...
13:28ericthorsencemerick: you still having frequent NB crashing?
13:28ericthorsenwroiong window
13:46bsteuberis it documented somewhere that it's not a clever idea to call a record field "size"?
13:47bsteubersay (defrecord Foo [size]) (:size (Foo. 42)) -> 1
13:56cemerickbsteuber: that's a bug from a few weeks ago that was fixed. Try a newer snapshot?
13:57LauJensencemerick: is it just me, or does it seem that there is an increase in bugs recently ?
13:58bsteubercemerick: ah, I froze my clojure version for swank
13:59cemerickLauJensen: Not sure you could characterize it as that. Part of it is stuff new in 1.2 being shaken out, which is going to produce some regressions.
13:59LauJensenSounds like you expected that?
14:00cemerickit's inevitable as things draw up to a release, no?
14:00cemerickI'd be more concerned if issues weren't being raised -- that'd indicate a lack of thorough testing.
14:00LauJensenRelative to your workflow I presume
14:00kotarakLauJensen: I got the impression that 1.2 broke way more often than the versions before. The only things similar annoying was the initial use/require move.
14:00LauJensenThat matches my experience kotarak
14:01kotarakcemerick: and (sometimes trivial) things won't get fixed... At least not contemporary...
14:01LauJensencontemporary ?
14:01cemerickI think he means lately.
14:02LauJensenAha
14:03kotarakOk. Dictionary issue. contemporary <=> zeitnah, meaning close in time. Things are reported now and fixed two months later <=> not contemporary. :/
14:03cemerickah, timeliness
14:04LauJensenOk - Also sometimes the magnitude of the bugs surprises me, like the effect of removing numbering in fns for instance
14:04cemerickThe best I can suggest is to make noise about it, here and on the dev list.
14:05LauJensenYes that would be the next move - Just wanted to be sure I wasn't the only one feeling it
14:05stuarthallowaylate to the conversation ... feeling what?
14:05kotarakWell. This is nothing new. I hope things approve with the new leutnants.
14:06stuarthallowaywhat did removing numbering cause?
14:06LauJensenstuarthalloway: feeling an increase in bugs, both frequency and magnitude
14:06kotarakstuarthalloway: that it takes sometimes quite long to fix things. (even with patch available)
14:06LauJensenstuarthalloway: Caused toplevel macros to be un-redefinable, see hugods bugreport
14:06stuarthallowayok, will discuss with Righ
14:07stuarthalloway(Rich)
14:07LauJensenOk
14:08cemerickEven if that were true, I'm not sure what the "solution" would be.
14:08cemerick"Don't cause bugs"? ;-)
14:08LauJensencemerick: right, I was just poking to verify and maybe guess the cause, change in workflow, whatever
14:09cemerickwell, many fundamental things have changed over the last months, so I'd expect that.
14:10cemerickkotarak's issue with the cadence of patches being applied is a separate issue though; the same thing applies in contrib as well, which Chousuke raised as an issue on the dev list a while back.
14:11kotarakcemerick: I kind of complained also. is stuarthalloway now kind of leutnant to Rich? That would help things, I think. (I know, that Rich has a lot to do. A leutnant team would allow him to focus...)
14:15cemerickkotarak: I presume that's what clojure/core is meant to accomlish.
14:15kotarakcemerick: yeah *thumbsup*
14:15cgrandstuarthalloway & LauJensen, http://github.com/richhickey/clojure/commit/f47b3d6f028e0370c495383731a449092d0ae451 fixed #368 too
14:17LauJensenYea i noticed
14:24bsteuberis there a function converting a lazy seq into another lazy seq with all duplicates removed?
14:26bsteubernevermind - I should use find-doc more often :)
14:26kotarakoeh? Does someone have trouble with current git?
14:26kotarakI get a NPE in a macroexpansion in protocols.clj line 11 (a defprotocol)
14:27LauJensenkotarak: when compiling, using, what?
14:27kotarakcompiling with ant
14:27LauJensenk, sec
14:28kotarakDoes it need mvn now?
14:28LauJensenRich hates mvn :)
14:28kotarak(Man! I'm disconnected with the 1.2 at the moment.... :/ )
14:29LauJensenkotarak: core.protocols compiles fine here
14:29kotarakwhat changeset?
14:29LauJensenchangeset? I just cloned HEAD
14:30kotarakHmm... Me too.
14:30LauJensenbuild.clojure.org gives the green light as well
14:30kotarakgeez
14:31kotarakCaused by: java.lang.NullPointerException (protocols.clj:11)
14:32LauJensenkotarak: Could it be caused by the fact that you've renamed all the functions in core to have german names ?
14:32kotarakLauJensen: hehe. Unlikely.
14:32cemerickkotarak: sounds like you just need a clean build?
14:32kotarakcemerick: I did a fresh checkout. ant clean. ant.
14:33kotarakwill iterate
14:33cemerickkotarak: what's the sha you have?
14:33kotarakf47b3d6f028e
14:35kotarakHmpf.
14:35kotarakWorks now.
14:36cemerickgood here
14:36cemerickheh
14:36kotarakcemerick: I hate such errors. :(
14:36cemerickkotarak: it's those neutrinos hitting the DRAM :-)
14:36kotarakcemerick: dawn butterflies. ;)
14:37kotarakdamn
14:37cemerickkotarak: just not your day, huh?
14:37kotarakcemerick: seems so.
14:37cemerickkotarak: are you still an hg loyalist?
14:38kotarakcemerick: yup
14:38LauJensenOh yes he is :)
14:38LauJensenAnd I've got the "git sucks" inbox to prove it
14:38kotarakgeninterface methods might also be strings, right?
14:38cemerickkotarak is the only hg evangelist I've had much of any contact with, so I wonder from time to time. :-)
14:39kotarakcemerick: I just like it more than git. So much easier to use.
14:39cemerickstuarthalloway: I love the change to name, FWIW. Thankyouohthankyou. :-)
14:39cemerickkotarak: I like my SCM as cryptic as possible. Keeps out the riff-raff. ;-)
14:41LauJensencemerick: change to name?
14:41kotarakcemerick: yeah. git is probably pretty cool. I just don't use it often enough to hardwire things in my spine. I can return to hg after work with git and everything works immediately. The other way around? No way.
14:41kotaraknDuff: well. nothing new. The usual "git's interface sucks" argument. But I use both, prefering hg. I'm not even sure, that svn is the enemy.
14:42cemerickkotarak: that ;-) should've been in bold. I'm actually a tech populist, and would rather have hg's UX but git's guts. But I'm also pragmatic.
14:42stuarthallowayhey all, was on the phone a few minutes, would love to go back and respond to several things
14:42cemerickLauJensen: Second System
14:42cemerickbah
14:42cemerickLauJensen: http://github.com/richhickey/clojure/commit/4bea7a529bb14b99d48758cfaf0d71af0997f0ff
14:43LauJensenk :)
14:43stuarthallowaycemerick: rich is reviewing the thread on the dev list re: #352 (macro clearing meta). there may be subtleties there so I wasn't going to answer without his input
14:43nDuffkotarak, I remember Arch's interface enough that while I think git takes the wrong approach in asking users to learn to think in its terms, it's not exactly unprecedented. :)
14:44cemerickstuarthalloway: I didn't have any questions on #352?
14:44stuarthallowaydoh! sorry, that was cgrand
14:45stuarthallowaytoo much multitasking
14:45LauJensenrelax stuarthalloway, you are among friends :)
14:45stuarthallowayLauJensen: I have been working to add tests for both new code and for regressions as they are fixed
14:45LauJensenGreat, thanks alot on behalf of the community
14:46stuarthallowaybut that doesn't necessarily prevent some short-term pain
14:46LauJensenof course
14:47stuarthallowayalso, I think that tickets have been moving through more quickly than in the past. Perception is often a lagging metric for such things
14:48stuarthallowaykotarak: the NPE at line 11 in protocols could be caused by reloading the code for a protocol, if that protocol called itself during the reload while things were in a half-baked state
14:49stuarthallowaywhen that has been a problem in the past it is a heisenbug -- very irritating to track
14:49kotarakstuarthalloway: I think I understand what happens. I'm trying to address the - in interface method names issue.
14:49stuarthallowayinterface or protocol? interfaces can't have - in their names
14:50kotarakstuarthalloway: (when (some #(-> % first name (.contains "-")) methods) (throw ...)) in generate-interface causes the NPE.
14:50cgrandstuarthalloway: great to know (#352)
14:50kotarakstuarthalloway: right. the thread from the list, you said, gen-interface/definterface should error out.
14:50kotarakstuarthalloway: working on a patch
14:50stuarthallowaykotarak: cool
14:51kotarakstuarthalloway: obviously defprotocol somehow calls into gen-interfae
15:01kotarakoeh. I'm in trouble with name.
15:02kotarakI insert internal_reduce. A symbol. But name returns nil.
15:06Borkdudehow do I maximize a list of things based on their content?
15:07Borkdudelike this: [[1 2] [1 3]] => [1 3]
15:07Borkdudelist comprehension with for?
15:08kotarakBorkdude: max-key?
15:08kotarak(doc max-key)
15:08clojurebot"([k x] [k x y] [k x y & more]); Returns the x for which (k x), a number, is greatest."
15:08Borkdudegreat
15:08kotarak,(apply max-key second [[1 2] [1 3]])
15:08clojurebot[1 3]
15:09Borkdudekotarak: what a relief this exists :)
15:10kotaraklocals named after core functions. In particular "name". Pfff
15:13tgkWhat is the idiomatic way to return false for an expression when it evaluates to nil?
15:13kotaraktgk: return nil
15:14tgkWhat if it is used in a function with a foo? name? Idiomatically I wouldn't want foo? to return nil.
15:15tgkI could use (not (nil? ...)), but is there a nicer way?
15:16LauJensenhehe, "what is the idiomatic way to return false?" "return nil" - are you kidding kotarak ? :)
15:16kotarak,(boolean nil)
15:16clojurebotfalse
15:16kotaraktgk: see above
15:16tgkOh, cool. Thanks.
15:19kotarakWhat a look there are languages with type inference.
15:19kotarakluck
15:21_fogus_kotarak: Hey, it is able to infer the return type on the RHS :p
15:22kotarakWow. I'm impressed. ;) What's that? Scala?
15:23_fogus_kotarak: Java7
15:23kotarako.O
15:41bartj,(find-doc "lazy-cons")
15:41clojurebotnil
15:42bartjer, is "lazy-cons" a function - if yes there isn't any documentation? - http://en.wikibooks.org/wiki/Clojure_Programming/Examples/Lazy_Fibonacci
15:42hiredmanlazy-cons hasn't existed since before 1.0 was released
15:42hiredmansexpbot: leave me alone
15:43kotarakbartj: It's now named lazy-seq. See http://clojure.org/lazy
15:44bartjkotarak: thanks!
15:44hiredmanlazy-seq is not lazy-cons with a new name
15:45kotarakhiredman: I know.
15:45_fogus_,(doc cons)
15:45clojurebot"([x seq]); Returns a new seq where x is the first element and seq is the rest."
15:47_fogus_with a combination of what kotarak said
16:00timcharperI'm wanting to do this: write a function that receives a writer and a list of headers, and then returns a function that receives a hash map and writes the data to the writer
16:01timcharperIt needs to be able to be called by multiple threads in parallel, so it should process writes serially
16:01timcharperI'm thinking that agents are the best tool to use for this.
16:01timcharperAm I wrong to reach for this?
16:03neotykbartj: this example caused quite some confusion in my head as well, should be updated
16:04bartjneotyk: I thought I was the only one with a head-ache now
16:04bartjneotyk: any simple examples on lazy-seq?
16:05timcharper.... agents it is then
16:06neotykbartj: not really, let me think
16:08tomojtimcharper: but if you send off to the agent multiple times, the IO won't happen serially, will it?
16:09neotyk,(doc lazy-seq)
16:09clojurebot"([& body]); Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the body only the first time seq is called, and will cache the result and return it on all subsequent seq calls."
16:11neotyk,(take 10 (lazy-seq (cycle [1 2 3])))
16:11clojurebot(1 2 3 1 2 3 1 2 3 1)
16:11neotykbartj: though it doesn't make sense, as
16:11tomoj,(take 10 (cycle [1 2 3]))
16:11clojurebot(1 2 3 1 2 3 1 2 3 1)
16:11neotyk,(take 10 (ccyle [1 2 3]))
16:11clojurebotjava.lang.Exception: Unable to resolve symbol: ccyle in this context
16:11neotykas exactly tomoj says
16:12bartjsince cycle itself is lazy, why are we passing it through lazy-seq again?
16:12tomojno good reason
16:12neotykso whats use of lazy-seq?
16:13tomojcycle already returns a lazy seq
16:13kotarakbartj: (lazy-seq (cons (do (println "huhu") :first) nil))
16:13tomojnot everything returns a lazy seq
16:13neotykbartj: was trying to come up with some body that will generate seq
16:13kotarakbartj: try in the repl, first (def x (lazy-seq ...) Then (first x)
16:14tomoj,(take 10 ((fn fib [i j] (lazy-seq (cons i (fib j (+ i j))))) 1 1))
16:14clojurebot(1 1 2 3 5 8 13 21 34 55)
16:14bartjan example which doesn't involve recursion would be good
16:15tomojI don't think I've ever used lazy-seq without recursion
16:15kotarakbartj: see my example above
16:15kotarakbartj: it shows the effect of lazy-seq
16:17bartjer, it looks like a seq was not created at all?
16:18neotyk(let [x (lazy-seq (conj '() (do (println "ein") 1) (do (println "twei") 2)))] (first x))
16:18neotyk,(let [x (lazy-seq (conj '() (do (println "ein") 1) (do (println "twei") 2)))] (first x))
16:18clojurebot2
16:18clojurebotein twei
16:19kotarakneotyk: you have to nest the lazy-seqs
16:20neotyk,(let [x (lazy-seq (cons (do (println "ein") 1) (lazy-seq (cons (do (println "twei") 2) nil))))] (first x))
16:20clojurebot1
16:20clojurebotein
16:21bartjkotarak: I am sorry I don't get it
16:22kotarakbartj: the thing inside the lazy-seq is not evaluated until you actually access it.
16:22kotaraksee in neotyk's example
16:22kotaraktwei is not printed
16:22kotarak,(let [x (lazy-seq (cons (do (println "ein") 1) (lazy-seq (cons (do (println "twei") 2) nil))))] (second x))
16:22clojurebot2
16:23clojurebotein twei
16:24kotarakbartj: in his first example twei is printed because it is evaluated in the same lazy-seq
16:24neotykit was evaluated by cons
16:24neotyknot lazy-seq
16:28neotykbartj: does it makes sense?
16:29bartj, (let [x (cons 1 (cons 2 nil))] (second x))
16:29clojurebot2
16:29bartjer, same result without the lazy-seq?
16:30neotykbartj: yes, but sideeffects are missing
16:30tomoj,(take 10 ((fn fib [i j] (cons i (fib j (+ i j)))) 1 1))
16:30clojurebotjava.lang.StackOverflowError
16:30tomoj:)
16:30kotarakbartj: no. not the same
16:30neotykbartj: include side effects and do (first x)
16:31kotarak,(let [x (cons (do (println "eins") 1) (cons (do (println "zwei") 2) nil))] (first x)
16:31clojurebotEOF while reading
16:31kotarak,(let [x (cons (do (println "eins") 1) (cons (do (println "zwei") 2) nil))] (first x))
16:31clojurebot1
16:31clojureboteins zwei
16:31kotarakbartj: compare to lazy-seq example with first
16:31bartj, (let [x (cons (do (print "test") 1) (cons 2 nil))] (first x))
16:31clojurebot1
16:31clojurebottest
16:32neotyk,(let [x (cons (do (println "ein") 1) (cons (do (println "twei") 2) nil))] (first x))
16:32clojurebot1
16:32clojurebotein twei
16:32kotarak,(let [x (lazy-seq (cons (do (println "ein") 1) (lazy-seq (cons (do (println "twei") 2) nil))))] (first x))
16:32clojurebot1
16:32clojurebotein
16:33kotarakno "twei"
16:33bartjkotarak: yes!
16:35bartjI guess I was trying with the wrong examples!
16:58bartjtomoj: one need not mention the "exit" condition while writing a lazy-seq?
16:58bartjtomoj: that is a bit hard to get over at first
16:59tomojthat's part of the point of laziness
16:59tomoj(iterate inc 0) is the natural numbers, all of them
16:59tomojbut only as many as you need will be generated
17:01tomojI've liked my eeepc but haven't tried any others, so..
17:02tomojoops
17:02tomojwrong channel
17:07KirinDave Did anyone ever make good on that lazy hash idea?
17:08CumbayahHi clojurians. Newb alert. What would be an ideomatic way of providing a lazy sequence over floats serialized to a file from java? thanks a bundle
17:09KirinDaveCumbayah: Check out lazy-seq
17:09KirinDaveCumbayah: It really works with I/O
17:11Cumbayahthx for the pointer
17:13tomojthen you end up with the stream left open if you don't consume the whole seq, though
17:14KirinDavetomoj: That is a problem with laziness.
17:14KirinDaveAnother possibility is to eat the file entirely into memory
17:14KirinDaveBut if you're making a lazy seq it's probably because the file is ginormous.
17:14KirinDaveIn that case, you need to make sure the stream is closed. preferably by a finally clause.
17:14Cumbayahpotentially huge files, want to avoid reading into mem as it can be processed sequentially
17:15KirinDaveCumbayah: So just be aware that the file can close. And if you close the file while the lazy seq has it, it'll chuck an exception.
17:15KirinDaveLazy seqs can handle streams, so it's fine.
17:15tomojavoiding holding the head will prevent keeping everything into memory, right?
17:15KirinDaveRight
17:15KirinDaveOr so I'm told
17:16arkahnI'd like to (doall map prn (line-seq rdr)) and catch the IOException so I could continue reading the file at a later time, i.e. "tailing". What syntax would I use to specify java.io.IOException in the catch clause?
17:16KirinDaveCumbayah: The easiest example of a lazy-stream is something like iterate
17:16KirinDaveCumbayah: (defn forever [start] (lazy-seq (cons start (forever (inc start)))))
17:16arkahnthe prn will be replaced with another fn
17:16KirinDaveSo (take 5 (forever)) is (0 1 2 3 4)
17:17hiredmanclojurebot: exceptions?
17:17clojurebothttp://paste.lisp.org/display/74305
17:19bartjfor this function:
17:19bartj,(defn my-iterate [f x] (lazy-seq (conj [x] (my-iterate (f x)))))
17:19clojurebotDENIED
17:19bartjwhy can't I do a - (my-iterate inc 0)
17:21KirinDavebartj: Why conj?
17:21KirinDavebartj: But anyways, note that you're passing (my-iterate (f x))
17:21KirinDaveWhich is wrong
17:21KirinDaveI think you meant
17:22KirinDave(my-iterate f (f x))
17:23bartjKirinDave: my knowledge of clojure functions is a bit limited
17:23bartjyes, you are right
17:23KirinDavebartj: I don't know why you're putting everything in a vector.
17:23KirinDaveSee my previous code for something like iterate
17:23bartjbut, I use lazyseq and *still* get a stackoverflow
17:24KirinDaveTry
17:24KirinDave(defn my-iterate [f x] (lazy-seq (cons x (my-iterate f (f x)))))
17:24KirinDaveAnd then say (take 5 (my-iterate inc 0)))
17:24KirinDaveerr, ))
17:25KirinDaveInfinite seqs are like hot lava. Unless you set up your repl to handle them, they're gonna burn you upon contact. :)
17:25naeuhot java lava
17:27ninjuddif i have an implementation of a protocol method that is the same for two different calls to deftype, what is the appropriate way to keep the code dry?
17:27ninjuddshould i just call deftype without the protocol and then use extend, merging my methods into a hash of the default implementations?
17:28naeuninjudd: is it possible to defn the method and pass the method name to deftype?
17:28bartjthank you all for helping me write my first lazy-seq
17:29ninjuddnaeu: oh, does that work?
17:29naeuninjudd: I have absolutely no idea :-)
17:29naeu'twas but a guess
17:30ninjuddi'll try it
17:33ninjuddnaeu: i can't do what you suggested, but i can call the method from my implementation, though that results in an extra method call, rather than calling my implementation directly
17:34naeuhmm that's frustrating
17:35naeuI wonder what the speed difference actually is
17:36naeuit would be interesting to do some performance tests
17:36naeuperhaps hotspot optimises away that extra method call
17:37ninjuddyeah, i doubt the performance hit would be significant. i'm more concerned with what the generally accepted idiom is for doing it
17:38naeuninjudd: I wonder if an idiom has had chance to form yet...
17:38naeu:)
17:41ninjuddclojure.contrib.io uses extend to share implementation: http://github.com/richhickey/clojure-contrib/blob/master/src/main/clojure/clojure/contrib/io.clj
17:41ninjuddbut it doesn't use deftype
17:43ninjuddchouser: do you know what the right way to share implementation with deftype is?
17:43kotarakninjudd: using extend with a map and eg. merge
17:45ninjuddkotarak: ok, so just call deftype and leave the protocol out, then do extend
17:45kotarakninjudd: yes
17:45ninjuddkotarak: cool, thanks
17:47ninjuddkotarak: the deftype fields won't be accessible directly to those methods, right? or will they?
17:47kotarakninjudd: you'll have to use (.field instance)
17:48arkahnI'm in the process of writing something that tails a file. Can anyone tell me why the following exits when it 'should' infinitely loop? http://gist.github.com/421550
17:48ninjuddkotarak: k
17:49kotarakarkahn: because repeatedly is not a loop. It create a lazy sequence, which gets never realised.
17:49kotarakYou probably want loop/recur or so
17:49kotarakOr (while true ...)
17:49arkahnkotarak: oh - ok, thank you
17:59DeusExPikachuis there a function that simply executes its argument? similar to how identity simply returns its argument? basically a name for #(%)?
18:01turbofail,(apply (fn [] "Foo"))
18:01clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$apply
18:01turbofaildoh
18:01turbofailworks on my older version of clj
18:02bartjDeusExPikachu: what do you mean by simply execute?
18:02raek,(apply (fn [] "Foo") [])
18:02clojurebot"Foo"
18:02DeusExPikachu#(%)
18:02DeusExPikachubasically a name for that
18:03turbofailis there some reason you need a name for it?
18:04DeusExPikachuclarity, readability, nothing more really
18:04turbofailwell, you could always make one
18:04tomojhrmm
18:04tomojso you have foo and you're doing (#(%) foo) ?
18:04DeusExPikachuI know I can, just wanted to know if there was one already in core
18:05turbofailthe closest thing is "apply," but that requires an extra arg
18:05DeusExPikachutomoj, no, more like (map #(%) vector-of-fns)
18:05tomojah, I see
18:06tomoj((apply juxt vector-of-fns)) heh
18:08defnhttp://gist.github.com/421584
18:08defnhow can I turn that lazy-cons into a lazy-seq
18:09tomojI think lazy-cons is (lazy-seq (cons ...)) ?
18:09defnyeah that sounds right
18:09defnnot sure if the if needs to be inside though
18:10tomojnope
18:10defnk cool, thanks
18:10defnneed to get my markov on :)
18:16bhenryis there a function to which i can pass a symbol (representing a function) that tells me what namespace said symbol is defined?
18:17tomojno
18:20lancepantzstuarthalloway: there was a discussion in the mailing list about splitting up contrib into individual jars, do you see this happening?
18:20stuarthallowaylancepantz: yes
18:20tomojbhenry: can you maybe give an example of what you want?
18:20lancepantzthat will be awesome
18:20stuarthallowaylancepantz: but not before beta1
18:21lancepantzbut before 1.3?
18:26bhenrytomoj: a project uses all kinds of namespaces eg ns1 . . . ns10
18:27bhenrytomoj: i look through the project and see (fn-1 some stuff here)
18:27bhenryi was wondering if i could do (somefunc fn-1) to see what namespace it was in
18:28tomojaha, in that case, yes
18:29tomoj,(resolve '+)
18:29clojurebot#'clojure.core/+
18:30bhenryhaha derrr. doc will do it too
18:30tomojyeah, that too
18:30tomojbest to use require or use :only, I think
18:30tomojI mean, :require or :use :only
18:31bhenryyeah. i didn't write this project. but that seems like a good practice to adopt
18:33tomojbest for the people who will have to read your code later :)
18:37bartjtrying to write a lazy-seq for generating prime numbers
18:38bartjand realized that I would have got the field's medal or something similar if I could write one....
18:38bartjFML
18:38tomojwhere's my field's medal? :(
18:39bartjtomoj: I mean there is no function which will predict the next prime number, right?
18:39tomojsure there is
18:40bartjhmm?
18:40bartjwhich is?
18:40tomojthe simplest example is the function that just keeps looking until it finds another prime..
18:41defnbartj: depends on what you mean by predit
18:41defnpredict
18:42defni could conceive of a function which guesses the next prime, but isn't always accurate
18:42tomojbut why bother when we can just make a function which is always accurate?
18:43defn*shrug* -- maybe for massive primes it's not a terrible idea to try
18:43tomojoh, yeah, for massive primes my simple function will just run until you die
18:43defn:)
18:44bartj(defn is-prime? [x] (loop [i 2] (if (>= i x) true (if (= (rem x i) 0) false (recur (inc i))))))
18:47canderaIIRC there are algorithms that can be run to determine with a lower bound on the probability that a number is prime. So if you're cool with a sequence of numbers that is highly likely to be prime, you could pull that off.
18:47tomojI don't understand
18:47tomojwe can write a function which returns a lazy seq of all and only the prime numbers
18:48canderaBut it's horrendously inefficient to use the Sieve of Erasthenese.
18:48tomojso what?
18:49canderaIf you only need the first n, for small n, then yep, so what?
18:51bartj(defn get-primes [] (lazy-seq (is-prime? (iterate inc 2))))
18:52tomoj,(doc filter)
18:52clojurebot"([pred coll]); Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-effects."
18:52bartjreturns an error of - clojure.lang.Cons cannot be cast to java.lang.Number
18:52candera(defn get-primes [] (filter is-prime? (iterate inc 2))
18:53bartjcandera: I was enthusiastic to use lazy-seq
18:54bartjalso why doesn't (take 5 (get-primes)) work?
18:54tomojyou will rarely need to use lazy-seq
18:55bartjtomoj: why not in the above case?
18:56tomojiterate already returns a lazy seq
18:57tomoj(take 5 (get-primes)) should work
18:58bartjclojure.lang.Cons cannot be cast to java.lang.Number
18:59tomojcandera corrected your get-primes
19:00tomojis-prime? expects a number, you were passing (iterate inc 2) to it, not a number
19:04bartjtomoj: yes, thank you
19:11nirlywhere do I need to put clojure files so I can load them with (require )?
19:18tomojnirly: on the classpath
19:18hiredmanrequire works on namespaces, and tries to map those namespaces to files, so if your namespaces and filenames map to each other correctly require will work
19:19hiredman~namespaces
19:19clojurebotnamespaces are (more or less, Chouser) java packages. they look like foo.bar; and corresponde to a directory foo/ containg a file bar.clj in your classpath. the namespace declaration in bar.clj would like like (ns foo.bar). Do not try to use single segment namespaces. a single segment namespace is a namespace without a period in it
19:19tomojjust use leiningen :P
19:21hiredmanif you just want to load a file, there is, well, a function called load-file
19:22jashmennis there a way i can pass a list "unpacked" to a function. like the splat* operator in ruby?
19:26lancepantzjashmenn: apply
19:26lancepantz,(apply println '("a\n" "b\n" "c\n"))
19:26clojurebota b c
19:26jashmennlancepantz: ah, right thanks!
19:27lancepantzthat makes more sense at a repl )
19:27lancepantz:)
19:42kensanataI know very little of Java and Clojure; working on my first piece of code and getting java.lang.IllegalArgumentException: No matching ctor found for class javax.swing.JPanel for this code: (import '(javax.swing JPanel ImageIcon)) (def tile (JPanel. (ImageIcon. "empty.png"))) -- what am I doing wrong?
19:48technomancykensanata: ctor means constructor, so apparently you can't construct at JPanel with an ImageIcon argument.
19:49kensanataGah, I think I confused JPanel with JLabel... Must try again.
19:50kensanataThat was it. Thanks for the pointer, technomancy. :)
20:27nubaguys, i have this centos 5.5 32 bit which i'm migrating from vmware server into a xen running on a centos 5.5 64bit, how should I go about it, regarding kernel and para or hvm?
20:27nubathe part about converting the disk image with qemu-img is sorted out already
20:28nDuffnuba, are you sure this is the channel you mean to be in?
20:29nubaaww crap, sorry guys, dammit
20:29nDuffnuba, (Xen's HVM is pretty slow, unlike KVM's; PV will require more work, but is likely worthwhile)
20:29nubawrong window, i thought i had switched irssi to #xen
20:30nubaheh, and that's from someone using irssi for 10+ years, sorry folks
20:31axianybody know why "(import ('java.io File))" isn't working with enclojure?
20:31tomoj(import java.io.File)
20:32axity
20:32axistrangely it works in repl 1.1.0
20:33axihrm yeah, (import 'java.io.File) works
21:37pedroteixeirahello, any way to keep running tests automatic just with clojure.test?
21:49cemerickpedroteixeira: you mean similar to infinitest or autotest?
21:49cemerickI don't know of anything like that yet, no.
21:49cemerickWould be pretty simple to do though.
22:06pedroteixeiracemerick: ok, thanks. i found stuarthalloway's circumspec now, will try to do something to watch and run-tests when things change,.
22:14Siasiatest
22:15SiasiaOh! Hi there!
22:15SiasiaI have some troubles with leiningen and swank
22:15SiasiaDoesn't even know whats up? Just starting with clojure.
22:16tomojwhat are your troubles
22:16Siasiacan i drop stacktrace in here
22:16Siasia?
22:17Siasiathat project clj
22:17Siasia(defproject sandbox "1.0.0-SNAPSHOT"
22:17Siasia :description "FIXME: write"
22:17Siasia :dependencies [[org.clojure/clojure "1.1.0"]
22:17Siasia [org.clojure/clojure-contrib "1.1.0"]]
22:17Siasia :dev-dependencies [[swank-clojure "1.2.0"]])
22:18Siasiajust an empty lein new
22:19Siasiahttp://pastebin.com/iestTgzW
22:19Siasiaand console session
22:19tomojhrmm
22:19Siasiaso lien swank is not warking
22:20tomojnever seen that error before there
22:20Siasiaoh i'm on freebsd
22:20Siasiaalso i tryed swank with maven and its working perfectly
22:21tomojhurrah
22:22tomojthat project.clj works fine for me
22:23hiredmanSiasia: you want lein-swank not swank-clojure
22:23tomojoh, I see what the problem is
22:23tomojperhaps
22:24hiredmantomoj: well to start with
22:24tomojSiasia: can you do (System/getProperty "os.name") and (System/getProperty "os.arch") ?
22:25hiredmanSiasia: doesn't matter
22:25hiredmaner
22:25hiredmantomoj
22:25tomojI thought we want swank-clojure not lein-swank nowadays
22:25tomojhiredman: why do you think it doesn't matterL
22:25hiredmanoh
22:25hiredmanright
22:26hiredmanI thought it was the reverse
22:26tomojI think this is what's causing the error...
22:26hiredmantomoj: what?
22:26tomojSiasia's os.name or os.arch aren't known by leiningen
22:26Siasiai was afk
22:26Siasiaso
22:27hiredmantomoj: I highly doubt that
22:27tomojwell, the stacktrace seems pretty clear to me
22:27Siasiauser=> (System/getProperty "os.name")
22:27Siasia"FreeBSD"
22:28tomojexactly
22:28Siasiauser=> (System/getProperty "os.name")
22:28Siasia"FreeBSD"
22:28tomojnative-names in compiler.clj has no key for FreeBSD
22:28Siasiasorry
22:28tomojand thus the NullPointerException
22:28Siasiaso how can i work this around?
22:29tomojmaybe you can override os.name? :/
22:29tomojI think you should report this, but don't know where leiningen bugs are reported
22:29Siasiaand how can i pass this to lein?
22:29tomojI don't know any way to do that, sorry
22:30Siasiaany solutions?
22:30tomojthe only one I can think of is to fix leiningen
22:31Siasiakinda
22:32tomojI believe adding "FreeBSD" :freebsd to the native-names map should fix your problem
22:32tomojbut maybe leiningen should not explode on an unknown os.name..
22:32hiredmantechnomancy is kind of a linux snob
22:33hiredmanI've been trying to tell him to use something other than #!/bin/bash in the shebang for lein for a while
22:34tomojSiasia: your best bet may be to follow the directions under "Hacking" in the leiningen readme and make the patch
22:35Siasiamokay. already cloning lein :)
22:44Siasiayep that's working
22:44cemerickwhy does lein care about the os.name?
22:52tomojcemerick: native lib path
22:53cemerickreally
22:53tomojayup
22:54cemericknot sure what to think of that
22:54axiwhen I create a class using ns/gen:class.. how do I expose variables
22:58axi:gen-class*
23:10tomojyou need to access these variables from java I guess?
23:11axihrm.. gen-class :exposes only works for inherited protected members :(
23:11axitomoj, i'd like to be able to do both
23:12axiaccess from java code and other clojure namespaces
23:13tomojdoes :state not do what you want?
23:16axihow would I make use of that?
23:17axi(. instance state member) - unable to resolve symbol
23:17tomojin the gen-class, you do like :state foo
23:17axiI did
23:17tomojthen (.foo instance)
23:18axiNo matching field found
23:19cemerickaxi: do you have an :init function that sets the :state?
23:20axino
23:20axii have
23:20axi(ns x.y (:gen-class :state state :init init))
23:20axi(defn -init [] ...code... )
23:22cemerickthat should work
23:22tomojbut what does -init return?
23:22cemerickregardless of that, he shouldn't be getting 'no matching field'
23:23cemerickif -init returns an 'improper' value, the :state field will just be nil
23:24cemerickaxi: are you compiling the relevant namespace, and then starting a new repl with the classpath appropriately set up to be able to load the AOT-compiled class?
23:34tomojso you can only have one state field?
23:34cemerickin gen-class, yes
23:35tomojI guess it is only really meant to store a ref/atom/whatever?
23:35cemerickyou can drop any object there if you so choose
23:35tomojbut the fact that it's final and there's only one...
23:35cemerickright, it leads you to certain good defaults
23:36cemerickdeftype and defrecord are there and quite preferable unless you really need gen-class' interop features
23:36tomojwhat if you wanted to implement the state object in clojure?
23:37cemerickhow do you mean?
23:37tomojmaybe what I'm asking is, what tools would we use to write refs/atoms in clojure
23:37cemerickah, that's exactly what deftype is for
23:37tomojdeftype doesn't give you something java can hook onto, does it?
23:38tomojor does it, hmm
23:38cemerickit emits fields
23:38cemerickfar better to define an interface and implement that in the type IMO
23:38cemerickfor java interop, that is
23:39cemerickfield access is quite non-idiomatic in java
23:39tomojbut then how does java get ahold of an actual concrete class
23:39cemerickAOT-compile a deftype, and you've got a class
23:39tomojah, yes, ok
23:39tomojonly, it can't subclass anything
23:39cemerickright
23:40cemerickextending concrete subclasses opens up a whole can of worms. That's why gen-class is sticking around.
23:40tomojso if the java lib you're working with defines it's plugin api in terms of abstract classes instead of interfaces, you're out of luck
23:40cemerick(and proxy, for that matter)
23:40tomojoh, can we use deftype with abstract classes?
23:40cemerickno
23:40tomojbut it would be less of a can of worms than extending concrete classes?
23:41tomojI wish I could somehow sneak deftype into the system
23:41cemericksorry, I meant any class
23:41tomojah
23:41cemerickas opposed to interfaces
23:42tomojI feel like there should be universal pressure on jvm developers to define their shit in terms of interfaces not abstract classes
23:42cemerickIf you need the full-boat java interop, that's what gen-class and proxy are for.
23:42cemerickyeah
23:42cemerickLots of history there.
23:42tomojmaybe there is some reading material
23:43tomojI want to know why solr uses abstract classes
23:43cemerickprobably because lucene uses abstract classes
23:43cemerick:-P
23:43cemerickgodawful choice that was
23:43tomojis there something you gain in java for using abstract classes?
23:43hiredmanyou can inheriting implementation
23:43cemerickdefault implementations
23:45tomojI see
23:45gstampI was wondering if anyone could suggest a good way to avoid repeating the call to key-pressed? in the code at http://codepad.org/ZeqvTmut. condp seems to be almost what I want but I'm not sure how I'd make it apply to this particular case.
23:45tomojso maybe what java devs should do is define public interfaces and use them all over, but use abstract classes internally?
23:45tomoj(if needed)
23:45cemerickThat's the ideal, yeah.
23:46tomojI guess this style is evident in clojure's java sources, eh?
23:46tomojnever thought much about the I's and A's there
23:47tomojwonder how much work it would be to fix solr and lucene :(
23:48cemericktomoj: never, ever, ever going to happen :-)
23:49tomojnooo
23:49tomojthis is just a nightmare I will wake up from soon