#clojure logs

2010-08-16

00:00technomancymmarczyk: that's a lot of text for a forum post; have you thought about submitting it as part of the official docs?
00:00mmarczyktechnomancy: I've only just finished writing it
00:00mmarczykturns out to be just under 10 KiB of text
00:01Raynestechnomancy: You haven't seen many of his answers on stackoverflow, have you?
00:01Raynes;)
00:01mmarczyknot exactly my first estimate for an SO answer, so I'm at a loss as to what to do with it
00:01RaynesThe only way I can ever get an accepted Clojure answer on SO is if I manage to beat him to the punch. I literally set my feed reader to update the Clojure SO feed every 5 minutes just for that purpose.
00:01Raynes._.
00:02RaynesHe's a beast.
00:03mmarczyk:-)
00:03mmarczykfunny, I always check it manually :-)
00:04RaynesYou're a stronger man than I.
00:24notsonerdysunnyException in thread "main" java.lang.ClassNotFoundException: com.jcraft.jsch.JSch (push.clj:1) at clojure.lang.Compiler.eval(Compiler.java:5435) I tried to do a lein push on the lein-clojars repo I cloned from github .. and I got the above error .. I am having trouble pushing my jar files to the clojars repo via "lein push" .. can anybody help?
00:25technomancygrrr... I've been blocked for 3 days fighting the maven API for this one remaining lein 1.3 feature, and I just realized it's really easy to do in the ant API
00:25notsonerdysunnytechnomancy are you responding to me?
00:26technomancynotsonerdysunny: oh, no
00:26notsonerdysunnysorry .. I just logged in ..
00:26technomancynotsonerdysunny: I recommend against "lein push"; the java SSH libraries are not compatible with all key types.
00:27technomancyjust make a shell alias for "lein pom && lein jar && scp pom.xml myproject.jar clojars@clojars.org"
00:27notsonerdysunnyoh ok
00:28notsonerdysunnyI found a clojars@clojars.org: on the website .. (note the trailing ':') .. so am I not supposed to have that ':'
00:28technomancyoh right; I should have put on a :
00:28technomancymy bad
00:29notsonerdysunnyIs this how one would do it if I want to to upload it to my group?
00:29technomancyyou need to set the group in project.clj to org.clojars.notsonerdysunny before you do anything
00:30technomancyunless you are a maintainer
00:33technomancynotsonerdysunny: actually I'm curious why you are trying to publish your own version of that library to begin with
00:42notsonerdysunnytechnomancy .. the reason is I have the jar files for jReality ... I didnot find it on any repositories .. I wanted to have a easily reproducible builds .. do you have a suggestion?
00:42notsonerdysunnyjReality also has native-lib dependencies...
00:42technomancynotsonerdysunny: oh, I thought you said you were pushing the lein-clojars project
00:42technomancynever mind; carry on
00:46notsonerdysunnytechnomancy .. I was just trying to get it working on lein-clojars before I tried the jReality
01:04technomancyleiningen 1.3 RC1 tomorrow
01:04technomancyit'll be HEAD from right now, I'm just too lazy to tag it and update NEWS tonight =)
01:06notsonerdysunnythese are the basic jars I want to upload ..
01:06notsonerdysunny|-- jReality.jar
01:06notsonerdysunny`-- jni
01:06notsonerdysunny |-- jReality-jni-linux32.zip
01:06notsonerdysunny |-- jReality-jni-linux64.zip
01:06notsonerdysunny |-- jReality-jni-macosx.zip
01:06notsonerdysunny |-- jReality-jni-win32.zip
01:06notsonerdysunny `-- jReality-jni-win64.zip
01:06notsonerdysunnycan anybody give me a starting point for writing a project file for this?
01:15amalloyis there a builtin function for this? (zipmap my-keys (map f my-keys))
01:16amalloystill learning clojure, and this seems useful/general enough that it must exist, but i don't know where to look
01:23notsonerdysunnyall the zip files contain .so/.dll/.jnilib files..
01:48amalloynotsonerdysunny: not a clojure expert here but maybe i can help. what problem are you having with your library files?
01:50notsonerdysunnyamalloy I want to juse jReality in my project .. and jReality is not available in any public repositories.. it is available for download though .. so, i would like to upload the jar to my group in clojars.org
01:50notsonerdysunnyand also, this library has native dependency files...
01:50amalloyah. way above my level of competence so far, i'm afraid
01:50amalloycome back in a few months and i'll know how :)
02:01notsonerdysunny:) thanks
02:56LauJensenGood morning all
03:08amalloymorning laugensen
03:08amalloybtw laujensen i asked this earlier but nobody seemed to be around: is there a builtin function for this? (zipmap my-keys (map f my-keys))
03:09LauJensenNot that Im aware
03:09LauJensenbut if there was, it would certainly be written like that, so grep the src/ of clojure
03:10amalloyhah, good point
03:12amalloyhm, i don't see it. i'm surprised, since it seems so useful (avoids repeating my-keys) and generic. am i wrong about its usefulness? (fairly new to clj so expecting to be wrong a lot)
03:13notsonerdysunnyfor those of you interested in jReality (visualization and realtime graphics and scenegraph library.. ) you can use [org.clojars.sunilnandihalli/jreality-native-deps "current"]
03:13LauJensenamalloy: I think its useful, so Im guessing a few people have a variant lying around in their local projects
03:15amalloyokay. i'll put it on the google group, ask if someone wants to add it to one of their c.contrib packages or if i should learn how to write my own
03:15amalloy(and try to think of another useful thing or two, so that my package is more than two lines long!)
03:27LauJensenamalloy: Have a look http://clojure.org/contributing
03:33amalloythanks Laujensen
03:39LauJensennp
05:45esjMorning All.
05:49LauJensenMorning
08:41bartjhow do I go about investigating/improving the performance of a system written in Clojure ?
08:42LauJensenbartj: There are a few things to be mindful of, depending a little on the system. Since you're functional, keep allocation low, avoid reflection at all costs, tweak heavy math to work with primitives
08:43bartjlike which function is taking the maximum time/number of objects allocated in the function, etc.
08:44bartjthe system is extremely heavy in math and computes a lot of scores for two records in a database
08:46AWizzArdrhickey: any chance that http://www.assembla.com/spaces/clojure/tickets/394 will go into 1.2?
08:47LauJensenbartj: sequence of map, filter, remove etc can be sped up by switching to 'for' instead. But what you need to do is profile and find out where you're spending time, then fix those hotspots
08:47rhickeyAWizzArd: no
08:47LauJensenbartj: You can check out my blogpost on fluid dynamics for a reference
08:48LauJensenrhickey: How about the work you did on statics/primitives, is that going in ?
08:48rhickeyLauJensen: not in 1.2, betas are 'feature complete', so no features not in the betas/rcs
08:48LauJensenalright
08:49rhickeyis there a way to get github to show you the source tree as of a commit (i.e. not the commit diffs)?
08:50bartjLauJensen, thanks a lot - will have a look at this - http://www.bestinclass.dk/index.clj/2010/03/functional-fluid-dynamics-in-clojure.html
08:50LauJensenrhickey: Dont know about github, but if you use Magit locally, just move the cursor down to that commit and hit 'o', then do what you want to do, and when you're done, hit 'o master' to switch back, IIRC
08:50AWizzArdrhickey: when I click on http://github.com/richhickey/clojure/commits/master/ I see the history. On the right side it offers me "commit", "tree" and "parent". Try to click on "tree"
08:51LauJensens/master/HEAD/
08:51sexpbotrhickey: Dont know about github, but if you use Magit locally, just move the cursor down to that commit and hit 'o', then do what you want to do, and when you're done, hit 'o HEAD' to switch back, IIRC
08:53rhickeyAWizzArd: thanks
08:56rhickeyfogus_: the past is immutable :) http://github.com/clojure/clojure/tree/da14d89c1936e9de6eacb9c12dd9e6a0d68a0829/src
08:57rhickeyfogus_: see the 'lisp' dir
08:57rhickeyfogus_: the first Clojure compiler was in CL and generated Java/C# source
08:58fogus_rhickey: Great! Thank you for that. I should have known. :-)
08:59rhickeyfogus_: there was work that preceded sourceforge that is only on my machines
08:59fogus_rhickey: Does that (your machine) include the predicate dispatch code?
09:00rhickeyfogus_: yes
09:00AWizzArdoho, a CL compiler
09:00fogus_rhickey: Any plans to revisit that?
09:00rhickeyand a version of the compiler that used more CLOS
09:01LauJensenrhickey: You opening a museum ? :)
09:02rhickeyfogus_: I didn't prefer the CLOS version to the one with more ccase
09:02AWizzArdI remember there was this jfly tool
09:03rhickeyfogus_: It was just a prototype based on Chambers/Chen. I've invited people to implement Chambers/Chen (http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.47.4553) several times, but no takers
09:03rhickeyfogus_: mine added a mini-prolog to do implication
09:03fogus_rhickey: Interesting. I think I missed that invitation.
09:05rhickeyhttp://groups.google.com/group/clojure/msg/e03f9874ccab7f0f
09:05rhickeyhttp://groups.google.com/group/clojure/msg/fd7022af9c1b4891
09:07fogus_rhickey: I've done a (simplified) pred-dispatch implementation in grad school, but it's been quite a while. Maybe I can dig that up and see where it takes me.
09:08rhickeyfogus_: Chambers/Chen is pretty easy, but hardwires a few things. The trick is to make it open
09:08fogus_Noted.
09:09rhickeybut a fully open dispatch system would include a little logic engine, and thus an unavoidable amount of overhead. The flexibility would be fantastic though
09:10fogus_I'm working on a unification lib at the moment that I was hoping to use as the basis for a little logic engine, so I suppose I'm on that path already.
09:12rhickeyfogus_: so, the next trick is, does your logic engine have clause order dependence (like Prolog)? If so, not a good match for open predicate dispatch. occurs check/tabling, more overhead
09:14fogus_rhickey: Nice points. I will make sure that it does not.
09:28chouserI sure do pick the mornings to be out. :-P
09:31LauJensenhehe
10:01arkhI want to use named arguments in a function - is it idiomatic to use Maps with Keywords (w/ destructuring) or is there a better way?
10:03AWizzArdarkh: that is okay, but you can also say & args and do an apply hash-map on that. And in Contrib there is also something.
10:03arkhAWizzArd: thank you
10:03raekit is possible to use map destructuring in & args nowadays
10:05raeksomething like [a b & {:keys [foo bar], :as opts, :or {:foo 1, :bar 2}}]
10:05raeks/{:foo 1, :bar 2
10:05raekahem
10:06raekreplace :or {:foo 1, :bar 2} with :or {foo 1, bar 2}
10:07arkhI'll look into that, too; thanks raek
10:09fogus_arkh: http://gist.github.com/526993
10:12esjfogus_: I object. All of this makes life too easy. Where's the sense of accomplishment ?! :P
10:14arkhthanks fogus_ :) I also look forward to the wood pulp version of your book.
10:26bartjLauJensen, are macros faster than functions ?
10:28chousermacros run at compile time not runtime
10:28chouserso in a sense, by the time your runtime code is running, macros take no time at all
10:29bartjso if I needed to speed up something, I should probably just convert all the (anonymous?) functions to macros ?
10:29bartjthough I know this will be severely criticised
10:32bartjno, the above question is not a troll :(
10:33chouserwell, the code *generated* by a macro still runs at runtime.
10:33chouserif all your macro does is produce the same code that you would have written by hand, it won't improve your performance at all.
10:35chouserthe way to use macros to improve performances is: first, improve performance other ways -- this is a corollary to the first rule of writing a macro (don't write a macro)
10:36chousersecond, find things that are being computed at runtime that could be computed at compile time instead, and implement those at compile time.
10:37bartjchouser, is there any performance related tips in "Joy of Clojure" ?
10:37bartjs/is/are
10:38bartjesj, which chapter ?
10:39esj11
10:45chouserreaching peak performance for you clojure program could probably be a whole separate book
10:46chouserand it'd be mostly about java
10:47fogus_LOL
10:50chouserI'm not even sure I could work up the motivation to read such a book, let alone write it.
10:50LauJensenbartj: The only reason I rely heavily on Macros for that post, is because that way I can avoid the boxing of numbers, since everything passed between functions gets boxed.
10:54LauJensen(hopefully this will change in 1.3, and then I'll probably rewrite the blogpost)
10:55bartjLauJensen, ok
10:55bartjthough I don't understand what you mean by "boxing"
10:56bartjyou definitely don't mean the sporting kind...
10:57AWizzArdbartj: putting numbers into a container, a box.
10:57AWizzArdInstead of reaching around numbers, you reach around that box which contains the number.
10:59LauJensenbartj: We want to work with java primitives like 'Integer', but thanks to the compiler that int gets wrapped in an Object, slowing the computations down by a factor 10x or so
11:00bartjLauJensen, ok and the way around that problem is to avoid reflection - am I right ?
11:02kenshoI have a problem with leiningen. When I run "lein repl" I want it to use the clojure version which I specified as dependency in my project.clj. Out of the box it launches with 1.2.0-beta1. I modified the classpath so that the specified clojure dep comes first and it works as expected. However when I now change the version in project.clj and then run "lein deps" I get an IOException about not being able to delete the clojure jars in
11:02kensholib. When I manually delete them it works fine. What am I missing?
11:06LauJensenbartj: wrong. Reflection is for guessing types, not for working with primitives. Reflection is also a huge performance hit, but its easily avoided by compiling your code with (set! *warn-on-reflection* true), and then adding ^Integer hints where appropriate
11:13arohnerbartj: when working with primitives, the values are pushed onto the stack. When java does arithmetic on them, it copies the value from the stack, pushes into a hardware register, and then calls the native math instruction. Very fast.
11:13arohnerbartj: when a number is "boxed", that means the value is stored in an instance of a class, in main memory. To do arithmetic, it has to read from main memory rather than the stack, so it's much slower
11:15bartjarohner, LauJensen thanks a lot
11:15LauJensenbartj: np
11:17AWizzArdThere are several fns in core.clj that forward a call to a java method, for example keys and vals. Is there a good reason why those are not definlines but defns instead?
11:28slyrusrhickey: I see you were talking about your earlier clojure in CL efforts. I've been wishing I could just say (cl:defpackage foo (:use "CLOJURE") ...) and get clojure (minus the java interop stuff) in an (otherwise-)CL environment.
11:28AWizzArdslyrus: Do you have a CL code base?
11:28slyrusyes
11:28AWizzArdMaybe you can go the other way around and get your code running under ABCL.
11:29AWizzArdAnd then you could call it from Clojure.
11:29AWizzArdslyrus: http://common-lisp.net/project/armedbear/
11:29AWizzArdIt is a CL implementation for Java.
11:29slyrusyeah, yeah, yeah...
11:29AWizzArdbut?
11:29AWizzArdAlready tried that?
11:30slyrusno, but I've thought about it.
11:30bartjto remove the reflection warning on: (map #(String. % "UTF-8") byte-array)
11:30AWizzArdIn theory it is just a 7 MB .jar file that you can put into your CP and that's the way to get your CL sources run with your Clojure code.
11:30bartjI did this: (map #(String. #^String % "UTF-8") byte-array)
11:30slyrusa clojure that compiled to native code using something like SBCLs compiler infrastructure would be ... interesting.
11:31slyrusmore so than, say, CLR as far as I'm concerned
11:31AWizzArdbartj: looks good, but do you mean maybe byte-arrays instead, ending in "s"? Cause otherwise map would not be the right solution..
11:31AWizzArdslyrus: yes, only that the JVM often outperforms sbcl.
11:32AWizzArdI can't say how efficient ABCL compiled CL is, but in general Clojure has the potential to outperform SBCL.
11:32bartjAWizzArd, Yes. I mean byte-arrays
11:32AWizzArdThough it is quite possible that when Clojure gets rewritten in Clojure then someone will port that implementation to a CL.
11:32AWizzArdPorts for JavaScript and .NET are already being worked on.
11:33slyrusAWizzArd: I would bet there are many cases where SBCL beats the JVM too
11:33AWizzArdbartj: then this is good. But if you plan to use Clojure 1.2 soon, then instead of saying #^String you could say just ^String
11:33AWizzArdslyrus: probably
11:34bartjAWizzArd, I am using 1.2
11:34AWizzArdbartj: then better use ^ for your type hints
11:34bartjAWizzArd, I wonder why I still get the reflection warning
11:35AWizzArdslyrus: have a look at the Computer Language Shootout
11:39AWizzArdslyrus: if you try ABCL please report back to me. I would be interested in the results, that is compatibility with CL, efficiency and how easy it is to call your CL code from Clojure.
11:55chouserShould changes to "our own" contrib libraries get their own assembla tickets now, or are we still allowed to just commit fixes as needed?
12:06raekbartj: could you try (map (fn [^String s] (String. s "UTF-8")) byte-arrays)
12:06raek(or #^String in 1.1)
12:07raekhrm, should the arg relly be type hinted as a String? (was that what you wanted to do?)
12:08raek(for [^bytes ba byte-arrays] (String. ba "UTF-8"))
12:16bortreb,(str-join "" (repeat 5 \tab))
12:16clojurebotjava.lang.Exception: Unable to resolve symbol: str-join in this context
12:17bortrebproduces "\t\t\t\t\t
12:17bortrebis that a bug?
12:18bortrebsince \t != \tab
12:19bortreboh, nevermind, I get it now
12:20chouserit's definitely a quirk
12:27chouserbortreb: http://paste.lisp.org/display/91391
12:28bortrebhurrr
12:32Chousukethe disparity was pretty much unavoidable.
12:32chouserC has literal syntax for chars without such a disparity
12:33Chousukethe escapes in strings are dictated by the java spec, and it isn't possible to use them and have \ be the character dispatch
12:33Chousukebut C uses '' for characters which is not possible in a lisp :)
12:34Chousuke(or if you do it, people will complain :P)
12:34chouserbah. syntax bikeshedding in a lisp. unacceptable
12:34chouser:-)
12:35chouser\( ), \(\n), \(n)
12:35Chousukeew :P
12:35chouser\" ", \"\n", \"n"
12:36Chousukea bit better. Though to get " you'd need \"\""
12:36chouserhm, yeah.
12:36chousersame with \(\)) I suppose
12:37chouserthe only reason to want a trailing marker is for whitespace, but I suppose that could be special-cased?
12:38chouserif "\s" = " ", then you could do \\s, \\n, \n and still be compatible with existing Clojure code
12:54hanDerPederim trying to implement least common multiplier that works with an arbitrary number of arguments, but not quite there: http://pastebin.com/q4ggi0Za
12:54hanDerPedercan somebody give me some pointers please.. quite new at this
13:14kenshohanDerPeder: (use 'clojure.contrib.math) (reduce lcm [2 3 6 8])
13:16hanDerPederkensho: thanks
13:16kenshonp
13:18hanDerPederkensho: my code crashes because nil gets passed to lcm in the last step, how does one generally avoid this in clojure? should I check for nil?
13:20ChousukehanDerPeder: in general you should try to write code using "nil-resistant" functions
13:20kenshohanDerPeder: That should certainly work but I'm a new to this myself so I don't know if there's a better way
13:22hanDerPederChousuke: how would that work with, say: (foo (rest coll))
13:22Chousukeyou would check for (if (seq coll) ...) in foo
13:22pdk,(seq nil)
13:22clojurebotnil
13:22pdk,(if (seq nil) :yes :no)
13:22clojurebot:no
13:23Chousukebut in this case using reduce is better as it already handles the case when the sequence ends
13:23hanDerPederokay, thanks
13:25Chousukenote: (seq coll) is one of the core idioms when working with sequences. it basically checks whether the collection has items
13:25Chousukeit might not be obvious but it's one of those things you just need to know :)
13:26pdk(doc apply)
13:26clojurebot"([f args* argseq]); Applies fn f to the argument list formed by prepending args to argseq."
13:26pdk(doc reduce)
13:26clojurebot"; "
13:26pdkthanks clojurebot
13:27pdk(doc reduce)
13:27clojurebot"; "
13:27pdk:|
13:27raek,(if () :yes :no)
13:27clojurebot:yes
13:27raek,(if (seq ()) :yes :no)
13:27clojurebot:no
13:29raek,(let [ls (lazy-seq (if (zero? (rand-int 2)) nil [1 2 3])] [(if ls :yes :no) (if (seq ls) :yes :no)])
13:29clojurebotUnmatched delimiter: ]
13:29raek,(let [ls (lazy-seq (if (zero? (rand-int 2)) nil [1 2 3]))] [(if ls :yes :no) (if (seq ls) :yes :no)])
13:29clojurebot[:yes :no]
13:29raek,(let [ls (lazy-seq (if (zero? (rand-int 2)) nil [1 2 3]))] [(if ls :yes :no) (if (seq ls) :yes :no)])
13:29clojurebot[:yes :yes]
13:30raekone could say that the lazy-seq has not decided if it's gonna be nil or not... :)
13:30raekseq forces that
14:13bortrebwhy doesn't doc return more info when you use it on special forms like def?
14:14hiredmanspecial forms like def don't have a var to hang doc metadata on
14:14chouserspecial forms generally need a lot more information to understand how to use them correctly, and there's not very many of them.
14:15chouserit's probably worth sitting down and learning them all at once.
14:16technomancystill, saying "Here's a web page you should read" is a little tacky imo
14:17bortrebthat is true. but it does violate the principle of least surprise: the way it works now is jarring to a beginner
14:17hiredmanfn gets around it by being a macro
14:18bortrebit's quite startling and you almost feel like you've done something wrong
14:18pdkno real harm to adding special cases to doc to provide docstrings hard coded into the function for special forms
14:20bortrebyeah ~ maybe an example and a short blurb, with the whole "you should master special forms" recommendation, would be better received?
14:26lyleI am just beginning to learn Clojure from Stu Halloway's book, but am curious about where to look for good "real world" examples of Clojure code.
14:27lyleInterested in how folks structure large Clojure apps and libraries, as well as what idiomatic Clojure looks like.
14:27lyleAny pointers?
14:30fogus_lyle: What specific real-world-like applications are you interested in?
14:31technomancyClojure apps tend to not get large. =)
14:33arkhlyle: try looking at the source of leiningen. technomancy just isn't plugging his own ;)
14:33pdklyle you may want to pick up some books on traditional lisp as well since a lot of the principles carry over here
14:34pdkansi common lisp, on lisp, let over lambda etc
14:34pdkespecially since on lisp is free as a pdf/html document now
14:58booradcemerick: is ashafa ever in here?
14:59fogus_This needs to be in core.somewhere: (defn available-processors [] (.availableProcessors (Runtime/getRuntime))) -- I see it in so many projects... maybe (def *available-processors* (.availableProcessors (Runtime/getRuntime))) is better.
15:07hiredmanping?
15:07clojurebotPONG!
15:11hugodhas anyone else seen instance? return incorrect results on a deftype instance?
15:29arkhhow would I do type hints with a :keys directive? i.e. this doesn't work: (defn create-udp-server [& {:keys [^String local-ip local-port ^String remote-ip remote-port]}] nil )
15:32chouserhugod: not in 1.2 RC3
15:33chouserarkh: oh, interesting.
15:35chouserhm, looks like that ought to work.
15:35arkhI'm using 1.1 still - maybe that's my problem :(
15:38chouser,(binding [*print-meta* true] (pr-str (macroexpand '(let [{:keys [^String a ^Integer b]} c ^Float d 1.0]))))
15:38clojurebot"(let* [map__502832 c map__502832 (if (clojure.core/seq? map__502832) (clojure.core/apply clojure.core/hash-map map__502832) map__502832) ^Integer b (clojure.core/get map__502832 :b) ^String a (clojure.core/get map__502832 :a) ^Float d 1.0])"
15:38hugodchouser: #424 still fails for me in RC3
15:39chouserif you run that and see hints on b, a, and d then it should mork.
15:39chouserhugod: hm, I haven't tested that one at all.
15:40arkhchouser: thank you
15:40bortrebarkh: your method does work, I just tested it, but remember that if you don't actually use anything in the function body that requires a string, it will still work for non-string arguments
15:40chouserhehe. "mork"
15:42arkhbortreb: the String type hints are used later when passing to (InetAddress/getByName local-ip)
15:46arkhI don't even know if it reflects without it - and maybe I shouldn't put type hints in unless running it warns on reflection? Not sure what's best practice there.
15:53edbondI have a function (with side-effects) that returns a vector. How to make infinite lazy seq from it?
16:01kencauseyedbond: why not 'lazy-seq ?
16:01tomojedbond: not enough information
16:02bortrebedbond: can you describe it a little more? do you want an infinite sequence of vectors?
16:12ninjudddnolen: the proposed 0.4.0 release of cake is on github in the duplex-refactor branch if you want to test it out with textmate-clojure. all the bound vars are in the cake namespace now
16:13dnolenninjudd: cool, thx for the heads up, will check it out later
16:14ninjudddnolen: it also has more reasonable handling of stdin. it should work with run and eval now
16:16edbondnevemind, I found repeatedly to constant call my func that return list
16:16edbondnow I have (lazy-seq (flatten (repeatedly f)))
16:18technomancywould anyone use an option for allowing deps to be kept in ~/.m2/repository rather than being copied into lib/? turning it on would break M-x swank-clojure-project and perhaps some other tools with that assumption.
16:18kencauseyso 'repeatedly includes a promise of executing the function only one like lazy-seq?
16:18kencauseys/only one/only once/
16:18technomancyjust trying to decide if it should be in lein 1.3 or later
16:18sexpbotso 'repeatedly includes a promise of executing the function only once like lazy-seq?
16:19kencauseytechnomancy: the value being no multiple copies among projects?
16:19technomancykencausey: yeah, save a bit of disk space
16:19kencauseyI guess links are out of the question
16:20nickikcan anybody help me to get the new Emacs auto-complete plugin to work
16:20nickik=
16:20nickik?
16:20technomancykencausey: eh; symlinks are already supported on unix
16:20technomancybut there's really no need for a lib/ dir at all, technically
16:21nickiki have no idea how to get that working
16:21kencauseywhy does it break any functionality?
16:21nickiki just cloned it into the .emacs folder
16:21kencauseybecause they assume /lib and are not part of lein?
16:21technomancykencausey: yeah, because M-x swank-clojure-project is implemented in elisp.
16:21kencauseyso can be fixed given time?
16:22kencauseyseems reasonable to me then
16:22technomancykencausey: it can't, but swank-clojure-project is deprecated in favour of lein swank.
16:22kencauseywell, fixed for anyone who cares ;)
16:22technomancyI'm going to add it, it's just a question of now or later, so I'm trying to gauge interest
16:22edbond,(take 10 (repeatedly 5))
16:22clojurebotjava.lang.RuntimeException: java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
16:23nickikrepeatedly calls the arg
16:23kotarak,(take 10 (repeatedly (constantly 5)))
16:23clojurebot(5 5 5 5 5 5 5 5 5 5)
16:23nickikif you want a stream of 5s you need to make (repeat 5)
16:23dnolentechnomancy: I've kind of come to consider the location of lib in the project directory to be a feature, it's easy to see what .jars are a part of your project.
16:24dnolentechnomancy: you don't have to hunt for the path.
16:24kotarak,(repeat 10 5)
16:24clojurebot(5 5 5 5 5 5 5 5 5 5)
16:25technomancydnolen: right; leaving out lib/ will not be the default in the forseeable future, just an option.
16:25technomancydnolen: are there other tools you know of that use that assumption though?
16:30dnolentechnomancy: not that I'm aware of, but it's such a standard layout that I wouldn't be surprised if plugins, etc. assumes it's there.
16:36raekedbond: could cycle be a possible solution?
16:37raekhrm, just read about the side-effects...
16:37raeknevermind
16:38raek(defn foo (lazy-cat (f) (foo))) could work too
16:38raekflatten is recursive, I think
17:02kencauseyShould I be able to ctrl-C ctrl-C a defn in emacs with a lein swank and slime-connect? This is winxp/cygwin. I guess a No such namespace: [Thrown class java.lang.Exception\
17:03kencauseys/guess/get/
17:03sexpbotShould I be able to ctrl-C ctrl-C a defn in emacs with a lein swank and slime-connect? This is winxp/cygwin. I get a No such namespace: [Thrown class java.lang.Exception\
17:06ska2342kencausey: do you have a call to ns at the beginning of your file?
17:06phaerkencausey: C-c C-c? I can't find such keybinding in C-h m. Do you mean C-c C-e? Then i guess you should be able to do it...
17:07amalloyC-c C-c should work, but it shouldn't hurt to C-c C-k to make sure the rest of the file is loaded first
17:10kencauseyC-c C-k works, but still not C-c C-c
17:11ska2342kencausey: I've had the same problem when I was editing files without a namespace definition at the top. Do you have one?
17:11kencauseyno I guess that's it
17:11kencauseybut it doesn't make sense if it's only paying attention to the form near the cursor
17:15amalloyphaer: the binding is listed in C-h m, under the Slime minor mode
17:17phaeramalloy: right, my bad.
17:26kencauseyok, it seems I have to C-c C-k the file once anyway to create the namespace
17:26kencauseyafter that C-c C-c seems to work
17:26kencauseymakes sense I suppose
17:26raekauto-complete-mode for clojure is awesome...
17:27raekC-c C-e puts things in the user namespace if the ns declaration hasn't been evaled
17:27raekthis might be related
17:28scottjIs there a more concise version of this? (if (symbol? (first expr)) (first expr) nil)
17:28AWizzArdscottj: when
17:29AWizzArd(if x y nil) ==> (when x y)
17:29raek(if x y) works too...
17:29AWizzArdThis is considered bad style, while when documents exactly this.
17:30raekis it?
17:30raek,(doc when)
17:30clojurebot"([test & body]); Evaluates test. If logical true, evaluates body in an implicit do."
17:30AWizzArdyes
17:30raekI've heard this been debated before
17:30AWizzArdraek: rhickey explained (in 2008) or so that using the nil return value of when is idiomatic in Clojure.
17:30ska2342reak: it tells the reader: "Don't go searching for an else, there is none."
17:31AWizzArdPlus if IF only has one branch you don't know if it was intended or accidently forgotten.
17:31raekyes, I know
17:31AWizzArdthus IF should always have two branches, while when makes the intentions of the author totally clear
17:32raekI just didn't know about rich's utterance
17:32scottjIs there a shortcut for not duplicating the (first expr) other than this (let [a (first expr)] (when (symbol? a) a))
17:32AWizzArdraek: I asked him 2008 or early 2009
17:32raekscottj: I don't think so, no
17:32raekAWizzArd: ok. I trust you :)
17:33AWizzArdraek: you can also try to find it online, all (well, most) logs of this are available online
17:33arohnerscottj: if-let
17:34arohnerscottj: and when-let
17:34arohner,(doc when-let)
17:34clojurebot"([bindings & body]); bindings => binding-form test When test is true, evaluates body with binding-form bound to the value of test"
17:34raekbut when-let will bind the value of (symbol? ...) in that case
17:36raekhttp://github.com/Kaali/pour/blob/master/src/pour/core.clj#L24
17:36raekI know Kaali ended up with this for a predicate to validator function
17:37raek(where a "validator" is a fn either returning the value or nil, depending on whether a predicate returned true for it)
17:38raek(def maybe-symbol (pred-to-validator symbol?))
17:38raek(maybe-symbol (first expr))
17:39raekthat is what I can come up with right now
17:39raekfunctions making functions can be very neat
17:40hanDerPederhow can i cast a huge number as string, ie "1234..." to a vector of digits?
17:40scottjDoes something like (ensure [] '(1 2 3)) -> [1 2 3], (ensure #{} 1) -> #{1} exist? (I've written it as a wrapper around into but not sure if there's already something like that in contrib or core
17:41hanDerPederor can you use a string as a vector of characters?
17:41raekthe special cases for vectors and sets are available as the vec and set functions
17:41raekhanDerPeder: strings can be used as a sequence of characters
17:42raekyou can turn it into a vector (if you need to) with vec
17:42raek,(vec "foo")
17:42clojurebot[\f \o \o]
17:42raekclojure's sequence functions call seq on their arguments
17:42raek,(seq "foo")
17:42clojurebot(\f \o \o)
17:43raekscottj: into
17:44raek,(into [] '(1 2 3))
17:44clojurebot[1 2 3]
17:44raek,(into #{} '(1))
17:44clojurebot#{1}
17:44hanDerPederraek: trying to do something like (map Integer. (vec "123")), don't know if there is a better way of doing it..
17:45raekyou'll have to do #(Integer. %), but otherways that looks resonable
17:45raekthere might be a numerical value method of the character class
17:46ska2342Hello. May I humbly ask, if there is already a release date for 1.2, in case there are no more reports on the latest RC?
17:47scottjraek: almost. the point of ensure is the second arg doesn't have to be a collection
17:48raekI see
17:48scottjIs there a single function in core to make one item into a collection iff the something's not already a collection?
17:48raekthen ensure could be as a composition of two functions: into and "make-coll"
17:49raeknot what I know of
17:49raek(defn make-coll [x] (if (coll? x) x (list x)))
17:50hanDerPederraek: what can i google to learn more about what in the world the #(Integer. %) syntax is all about?
17:50scottjI realize it's easy :)
17:50dnolenska2342: probably nothing more accurate than "soon".
17:50scottjhanDerPeder: do you know what #() is about?
17:51raekhanDerPeder: #(foo a % b) is a short form for (fn [x] a x b)
17:51raek*ahem*
17:51ska2342dnolen: just thought, maybe someone mentioned it here (and I've not been here lately). Thanks.
17:51raek(fn [x] (foo a x b))
17:52raekhanDerPeder: the java constructor syntax Integer. is not a function
17:52raekso you have to make it one...
17:52hanDerPederraek: okay, thanks
17:53raekthe syntax is described at http://clojure.org/reader
17:53raekthe java interop is described at http://clojure.org/java_interop
17:56raek,(map #(Character/getNumericValue %) "123")
17:56clojurebot(1 2 3)
17:56raek,(map #(Character/getNumericValue %) "٠١٢٣٤٥٦٧٨٩")
17:56clojurebot(0 1 2 3 4 5 6 7 8 9)
17:57raekas a bonus, that works for any unicode numeral
17:57hanDerPederthanks, makes a lot more sense now :)
18:00wolfjbdoes leiningen-war work for anyone? I'm getting a Exception in thread "main" java.lang.NoSuchMethodError: clojure.lang.RestFn.<init>(I)V (war.clj:1)
18:01raekthat message is usually a result of using two AOT compiled libraries that was compiled with different clojure versions
18:02raekhttp://github.com/technomancy/leiningen has a point about it
18:03raek(clojure versions are not binary compatible with each other)
18:15AWizzArdwhen I want to make a proxy in which I list two interfaces, and both include a method with the identical name foo, how can I implement those?
18:20raekhrm, do they have the same signature?
18:20AWizzArdLet's talk about both situations.
18:21raekin the jvm, methods of classes don't "know" which interface they come from
18:21JorejiAWizzard: The same way you would do with only one interface I'd say. At least it works for me: http://pastebin.com/KftuZEyG
18:22AWizzArdSo, if the signatures are different, then I could simply list both (or even 18, if I want maany Interfaces) of them. Otherwise it will be forbidden?
18:22hiredmanAWizzArd: you write a proxy body, just make sure it can handle both signatures
18:22hiredmanno
18:22hiredmanyou can't just list both, because proxy doesn't do method selection by types
18:22hiredmanit does it by name
18:24raekreify can do this: "If a method is overloaded in a protocol/interface, multiple independent method definitions must be supplied. If overloaded with same arity in an interface you must specify complete hints to disambiguate - a missing hint implies Object.
18:24raek"
18:24hiredmanclojurebot: proxy is not reify
18:24clojurebotAlles klar
18:25AWizzArdSo if two interfaces have the same signature, then we can't disambiguate between them?
18:25AWizzArdeven in reify
18:25hiredmanyou can, but proxy can't
18:26hiredmanoh
18:26hiredmanif they have the same signature, no
18:26AWizzArdokay, so, different signatures is okay with reify
18:26AWizzArdidentical signatures - forbidden
18:27hiredmanno
18:27hiredmanyou can use them, you just have to do dispatch yourself
18:27AWizzArdyes
18:27AWizzArdbut not with reify, right?
18:28hiredmandepends on the signature
18:36AWizzArdidentical
18:36AWizzArd4 interfaces, all offer int foo(int)
18:37rhudsonAWizzArd, it's (not) just a Clojure issue, it's how Java works
18:37AWizzArdyes, I am not saying that it is Clojure
18:37AWizzArdI am just curious if/how this is solved.
18:38rhudsonBy rewriting your interfaces :)
18:39rhudsonJava methods within a class are distinguished by name and signature, and not by which interface they implement
18:39rhudsonThe various Clojure interop facilities build on that machinery
18:41rhudsonSo in your hypothetical, you could provide an int foo(int) but it would satisfy all 4 interfaces
18:43AWizzArdoki, thx
19:04nickikdo sets keep order?
19:07AWizzArdnickik: nein
19:07AWizzArdbut SortedSets do
19:07ninjuddnickik: do you mean insertion order?
19:08AWizzArd,(sorted-set 30 20 10 5 6 7 2)
19:08clojurebot#{2 5 6 7 10 20 30}
19:09ninjuddright, insertion order would be #{30 20 10 5 6 7 2}
19:13nickiki ment insertion order
19:13AWizzArdnot trivially possible
19:13ninjuddhttp://github.com/ninjudd/ordered-set
19:14AWizzArdyes, you best would use some existing class/deftype for that
19:15nickiksomething else can i get the name of a record?
19:16nickiki do (defrecord test [])
19:17nickikhow do i go from (test. ) to test
19:19nickiki have to remember the orderd set could come in handy at onepoint
19:21AWizzArdninjudd: useful!
19:39dprohi
19:40dprodumb noob q., is there an existing function to get a random element from a vector or list ? (I'm just trying to find my way around the docs)
19:40hiredman,(doc rand-nth)
19:40clojurebot"([coll]); Return a random element of the (sequential) collection. Will have the same performance characteristics as nth for the given collection."
19:41dprohiredman: cheers
19:41dproclojurebot: cheers to you too of course :)
19:41clojurebothip hip, hooray! hip hip, hooray! hip hip, hooray!
19:41dprohehe
19:43AWizzArda useful tool when you think you have an interesting keyword: (find-doc "random")
20:00nickikdoes pmap still only use 2 cores=
20:00nickik?
20:01dnolennickik: pmap happens to use the number of cores on your system plus 2 i believe.
20:02nickikah ok very good
20:22nickikhow can I init a record from a other namespace?
20:24mefestonickik: did you import the classname?
20:26nickik(ns titfortat.main.core (:use [main.core] :reload-all) (:use [clojure.test]))
20:26nickik(ns main.test.core (:use [main.core] :reload-all) (:use [clojure.test]))
20:27nickik@mefest for testing i need a record from the main ns
20:27hiredmandefrecord produces a named class
20:27mefestonickik: perform a java import (import 'titfortat.main.core.MyRecord)
20:27hiredman(ns foo.bar) (defrecord Baz)
20:28hiredman(foo.bar.Baz.)
20:28hiredman(ns foo.bar) (defrecord Baz [])
20:32wolfjbI have installed clojure 1.1.0, running clojure says 1.1.0, I have set clojure and clojure-contrib in my project.clj to 1.1.0 but lein war still give me this: Exception in thread "main" java.lang.NoSuchMethodError: clojure.lang.RestFn.<init>(I)V (war.clj:1)
20:32wolfjbwhat else can I check?
20:32hiredmandid you run lein clean and lein deps afterwards?
20:32wolfjbyes
20:32hiredmanwhat do you mean by installed?
20:33wolfjbI downloaded clojure and clojure-contrib version 1.1.0 from clojure download site and pointed my launcher script to them
20:33hiredmanuh
20:34hiredmanthat has nothing to do with lein and project.clj
20:34hiredmanwhat versions of clojure and contrib is your project.clj pulling in?
20:34wolfjb1.1.0 is what I set in my project.clj
20:34hiredmanfor which?
20:34wolfjbin the lib directory is clojure-1.1.0
20:34wolfjbum
20:35hiredmancontrib and clojure both?
20:35wolfjbwell, I just downloaded the script on the leiningen github site
20:35wolfjblet me look at that, maybe I missed something
20:35nickiklook at this
20:35hiredmanuh
20:35nickik(ns titfortat.test.core (:use [titfortat.core] :reload-all) (:use [clojure.test]) (:import [titfortat.core.nice]) (:import [titfortat.core.asshole]))
20:35hiredmanwhere did you get your project.clj?
20:36wolfjblein new cabinet
20:36hiredmanok
20:36nickikis this right?
20:36hiredmanand what does your project.clj say?
20:36wolfjbfollowing this tutorial http://mmcgrana.github.com/2010/08/clojure-rest-api.html
20:36mefestonickik: what is the name of your record?
20:37hiredmanthe tutorial on that site doesn't use 1.1.0
20:37wolfjbtrue, but I changed it to say 1.1.0.
20:37nickik@mefesto nce and asshole
20:37nickik*nice
20:37hiredmanwolfjb: it being what?
20:37mefestonickik: remove the last dot in your import
20:38mefestoreplace with a space
20:38hiredmanclojure and clojure contrib are seperate things, and you need to having matching versions in your project.clj
20:38wolfjbsorry, I changed my project.clj for the cabinet project to have 1.1.0 for the clojure and clojure-contrib version
20:38nickikah ok
20:38mefestonickik: it would work the way you have it if it was not in []
20:38nickiki haven't worked with java interop much so i leak that a bit
20:38hiredmanwolfjb: and you only have 1.1.0 jars for both in lib?
20:39wolfjbyes
20:39nickik*lack :)
20:39wolfjbhttp://pastebin.com/QK1mX36B
20:39wolfjbis project.clj
20:40hiredmanwolfjb: so most likely some other library you are using is incompatible with 1.1
20:40nickik@mefesto ah ok thx
20:42wolfjbSo, I was originally using 1.2.0-master-SNAPSHOT for clojure and 1.2.0-SNAPSHOT for clojure-contrib, but in lib/dev clojure-1.1.0 and clojure-contrib-1.1.0 were showing up after lein deps
20:42wolfjbwhich is why I changed the project.clj to 1.1.0 for both clojure and contrib
20:44hiredmanright, so you are mixing libraries that require different versions of clojure
20:44hiredmandon't do that
20:44wolfjbtrying not to
20:44wolfjb:-)
20:44technomancylein pom && mvn dependency:tree # to spot the offenders
20:44technomancywolfjb: ^
20:44wolfjbah
20:44wolfjbI'll try that
20:50wolfjbso, that didn't seem to work, it doesn't seem to show the dev-dependencies in the tree
20:51wolfjbI'm guessing this has to do with the dev-dependencies
20:51wolfjblein run run.clj works, but lein war doesn't
20:51wolfjbbut that's only true when I switch back to clojure 1.2.0
20:51wolfjbin the project.clj
20:52wolfjbwith 1.1.0 in the project.clj, neither of those work
20:52wolfjbbut lein puts 1.1.0 jars in lib/dev
20:54wolfjbok so the dev-dependency which seems to be bringing in the 1.1.0 version is lein-run plugin
21:05bobbytekwhat's the difference between a form and an expression?
21:05technomancywolfjb: that's definitely a lein-run bug
21:06wolfjbah
21:09bobbytekAnd how is a symbol different than a reference?
21:17arbschtbobbytek: the first is a general question whose answer may be better documented in other lisps; for example, the Common Lisp HyperSpec defines 'form' and 'expression' in its glossary, and the general idea applies to Clojure
21:17bobbytekI'm pretty new to lisps...
21:18bobbytekis caml a lisp? I've used that a long time ago
21:18arbschtbobbytek: I don't understand what you mean by reference. do you mean the STM ref type, or some other general reference?
21:18bobbytekjava reference
21:18bobbytekor pointer
21:18arbschtbobbytek: caml is not a lisp
21:20arbschtbobbytek: a symbol is a particular type of object whose name is used to identify other things. it's not the same as a java reference
21:20bobbyteka reference in java identifies an object
21:20bobbytekhow is it different?
21:20scottj,'symbol
21:20clojurebotsymbol
21:21scottj,symbol
21:21clojurebot#<core$symbol clojure.core$symbol@1f5a0f0>
21:21bobbytekit is effectively an indirection mechanism that also establishes identity
21:22scottjsymbols can be used for their own sake kind of like keywords, or they can be evaluated in which case they point to a var, which in turn points to an object
21:23tomoj,(let [a 1] #'a)
21:23clojurebotjava.lang.Exception: Unable to resolve var: a in this context
21:23bobbytekheh, maybe I should read more of my practical closure book
21:23bobbytek(just getting started)
21:24arbschtbobbytek: symbols are first-class, can be interned in namespaces, and so on. the use case of naming a binding is one similarity with references, but symbols do more
21:24chouser(let [map 1] map)
21:24chouser,(let [map 1] map)
21:24clojurebot1
21:24chouser,(let [map 1] #'map)
21:24clojurebot#'clojure.core/map
21:33hiredmanvars are often overlooked
21:33hiredmanthey can be tricky, e.g. if you are conditionally import or loading code
21:34hiredmanimporting
21:35hiredmanaot compiled code can end with references to the wrong var
21:35hiredmanand then you end up digging through javap output
21:39spewnWhat steps are necessary between lein install and being able to (use 'foo)?
22:28bmaddyHi all. Anyone have an idea as to why this returns nil? (use 'clojure.contrib.pprint)
22:28bmaddyThat should just work, shouldn't it?
22:29cemerickuse, require, and import all return nil
22:29bmaddyHeh, clearly I'm new. Thanks! :)
22:29cemerickwelcome :-)
22:33kotrincan anyone help me debug the NullPointerException i'm getting in this code? not sure what i'm doing wrong...nor do i know how to debug clojure :) http://pastie.org/1096855
22:33kotrinor maybe even some code improvement tips while your staring at it? <3
22:34kotrinyou're*
22:34cemerickkotrin: use records instead of structs (http://clojure.org/datatypes)
22:34kotrini'll look into it...thanks cemerick
22:35cemerickkotrin: there's an NPE because t is a sequence of rest args
22:35cemerickremove the & and it should work.
22:36cemerick(or, at the very least, (:key t) won't return nil anymore)
22:37kotrinalright, thanks for the help!
23:22seangroveHey all, is there an example in clojure of interacting with a webcam?
23:25dnolenseangrove: I think ztellman had some luck with OpenCV for Processing/Java, but I don't know of any Clojure source that you can actually look at.
23:26seangroveYeah, I saw that, but I've had a very, very difficult time getting it to work
23:26seangroveOpenCV is actually where I'd like to get to, but I'm not sure how to get a setup that runs his source
23:27dnolenseangrove: there's also http://www.xuggle.com/
23:27seangroveI'll take a look
23:27seangroveAfraid I'm very new to clojure
23:27seangroveMuch more of a scheme guy, heh
23:27dnolenseangrove: it's a bit complex, and there are not bindings to Clojure, but also powerful.
23:28seangroveI'll start by trying to get the smallest example working first, I think
23:28dnolenseangrove: yeah, if you're getting into media stuff, you need to have the Java basics down.
23:29seangroveI have an opengl clojure app I made
23:29seangroveBut I certainly don't have java basics by any means
23:29dnolenseangrove: by basic I really just mean, jars, classpath, compiling Java source, and maybe some about where to put native files.
23:30seangroveAh, yes, I'm ok with that
23:30seangroveIt's been about 6 months though
23:30seangroveSo we'll see how this goes :)
23:31dnolenseangrove: Xuggle source seems pretty easy to run, next step would be running it from Clojure, next step a binding, and finally a idioamtic library that we can all use :D
23:38seangroveLooks like incanter has processing, which I believe has opencv
23:38technomancyseangrove: yeah, processing would be my recommendation
23:42dnolenseangrove: technomancy: I agree as well. far simpler that's for sure.
23:49seangroveWow, incanter is quite impressive
23:54seangroveuser=> (import 'hypermedia.video.OpenCV)
23:54seangrovejava.lang.ClassNotFoundException: hypermedia.video.OpenCV (NO_SOURCE_FILE:17)
23:54seangroveI'm supposing this means I haven't put the jar in the right file, or I haven't set the classpath correctly
23:54seangroveThat seem about right?
23:54dnolenseangrove: yeah
23:55seangroveGot some japanese blog, hehe: http://e-arrows.sakura.ne.jp/2010/01/clojure-opencv.html
23:56dnolenseangrove: I think OpenCV also relies on native libs, so you'll need to set your library path as well.
23:56seangroveNot sure how to set that in the slime repl
23:56seangroveI'll try it frm the cli for now
23:59dnolenseangrove: yeah you can't do it from the repl, has to be at startup time. lein will do this for you if you have the proper project layout - http://github.com/swannodette/native-deps