#clojure logs

2011-03-20

00:02meci think just using 1.3 from the repl would be less painful than this
00:02mecrepl from the command prompt*
00:02scottjmec, maybe you have an old version of swank-clojure
00:03mecim using :dev-dependencies [[swank-clojure "1.2.0"]]
00:03scottj1.3.0-SNAPSHOT
00:03mecah was looking for that but couldnt find any refrence to it
00:04scottjhttp://clojars.org/search?q=swank-clojure
00:04pdkactually where is 1.3 standing for release timeline now anyway
00:04pdkare we getting into release candidates soon
00:05scottjyou could look at jira
00:06mec1.3.0-SNAPSHOT is sitll giving me exceptions
00:06scottjpastebin it
00:08mechttps://gist.github.com/878064 https://gist.github.com/878066
00:10scottjoh yeah, I think that's actually a real bug, there's an open ticket for it on swank-clojure I think it started with alpha6, not sure though
00:12mecwow alpha5 works so far, thanks
04:13fmwpublic class TermsFilter extends Filter { Set<Term> terms=new TreeSet<Term>(); [...] } how do I access that terms field (its a field, right?)? When I run (. (TermsFilter.) terms) I get java.lang.IllegalArgumentException: No matching field found: terms [...]
04:17fmwI guess (.terms (TermsFilter.)) is more idiomatic, but that still gives the same error.
04:23brehautfmw you need to have access to it
04:24fmwbrehaut: so its a private field?
04:24brehautfmw: my rusty java memory tells me its protected?
04:24brehautmake it public and see if it changes it
04:25fmwbrehaut: I'm trying to implement a third party API (from Lucene)
04:25brehautfmw: oh. i have heard that that is not the most pleasant
04:26fmwbrehaut: the Lucene API in particular or implementing a 3rd party API in general? ;)
04:26brehautlucene from clojure in particular
04:27brehautalso idiomatic java would haveyou leave that field as protected and add a public getter
04:30Raynesbrehaut: Could you develop an application that uses some strange brain wave manipulation so that I can text-to-speech JoC to myself while sleeping and reap all the benefits of having actually read the whole text?
04:31RaynesI want to read the whole thing so bad, but I am so easily distracted that it'll take me a year.
04:31brehautheh
04:32RaynesI swear, man, if they hadn't closed the doors at the Conj during talks, I'd have wandered out chasing after something shiny.
04:32brehautRaynes: if you dont read it fast enough the orielly book will come out and you'll not be ready to read a book with cgrand content
04:32brehautman i wish i could make it to a conj
04:33RaynesI want to read The Joy of Clojure as a prerequisite to my restructuring+partial rewriting of my own book. Alas, things are moving to slowly.
04:33brehauti know the feeling eh
04:34fmwbrehaut: this is the first Java API I'm implementing from Clojure so far, but apart from this particular issue it has been fine. As to the idiomatic Java comment, adding a subclass with a public getter is what I had in mind. I'm going to read up on clojure proxies and try that now.
04:35brehautif its private a proxy wont be able to access the field. if it is protected it might be able to
04:39brehautfmw: im not really the person to be answering java interop questions; ive done very little myself
04:40fmwbrehaut: I'll try and see what happens, thanks :)
04:40brehautno worries
04:40fmweveryone is very excited about the Joy of Clojure, I see ;)
04:41brehautfmw: its a pretty fantastic book
04:41brehautits got a lot of quite deep content about the why of stuff
04:41fmwwhat sets it apart from books like Programming Clojure by Halloway?
04:42brehautaside from two years more clojure?
04:42fmwah, the deep content about the way of stuff, I guess.
04:42brehautits expects a certain familiarity with either a lisp or java
04:42fmwAFAIK Programming Clojure is also based on 1.2?
04:43fmwJoC assumes the familiarity?
04:43brehautyeah TJoC does
04:43RaynesProgramming Clojure is 1.1
04:44fmwI've been considering to get the early access version (manning is spamming me with discount codes anyway), but at this point its probably more convenient to wait for the print version from Amazon :(
04:44brehautive only skimmed a friends copy of Programming Clojure. it seemed more like a good introductory text
04:44fmwit is
04:45fmwI liked it quite a lot, as well as the Clojure part of Bruce Tate's Seven Languages book
04:45brehautim curious where the orielly book (Clojure Programming?) will fall
04:46Raynesbrehaut: It'll be a 1.3 book. So will mine.
04:46brehautfor sure
04:47fmwah, it says it will be released on March 25th in print now
04:48fmwdoesn't list a release date on Amazon yet, though, so wondering if I'll have to wait longer than the 25th.
04:52brehautfmw: oh other reasons that set apart TJoC: Lovecraftian footnotes, Wilco references and a generally pretty witty tone hiding in the corners
04:58brehautRaynes: has nec-ev been behaving itself?
04:58fmwbrehaut: seems fun, although I have never read anything by Lovecraft and have no clue who Wilco is;)
04:59RaynesHaven't actually done anything with it yet.
04:59brehautfmw: wilco is a band. they are pretty great. basicly, its enjoyable reading which makes it easier to get through the necessary but otherwise dry sections
04:59brehautRaynes: its probably for the best
05:01fmwI see :)
05:09fmwbrehaut: ah, I figured out how to access private/protected fields: (clojure.contrib.reflect/get-field org.apache.lucene.search.TermsFilter "terms" flt)
05:09brehautfmw; huh thats interesting
05:10fmwbrehaut: pretty cool functionality, one of the things that make Clojure even more effective at interacting with Java than Java itself
06:28zmyrgelwhat would be a good way to do unit testing in clojure?
06:28opqdonutthere are a couple of test frameworks
06:28opqdonutbut maybe you'll want to start with clojure.test
06:28zmyrgelI mean I have lein project and I want to test some functions but they are private in their own namespace
06:29opqdonutI'd just make them public
06:29opqdonutwhat's the harm?
06:29zmyrgeloverall structure in my opinion
06:30zmyrgelI'd hate to turn all my functions public just so I can test them
06:30opqdonutor you can put the tests in the ns itself, which is what I prefer
06:31opqdonutit just seems like the clojure test tools are more geared toward separate test namespaces
06:31opqdonutof course you can use the @' trick to access private functions
06:31zmyrgel@' trick?
06:33opqdonutgah, can't find the right combination of weird characters
06:34opqdonutah, #'
06:35opqdonuthttp://paste.lisp.org/display/120688
06:37zmyrgelah, that seems to be just what I'm looking for my unit tests
06:37opqdonuthttps://www.assembla.com/wiki/show/clojure/Clojure_Library_Coding_Standards <- the coding standards suggest it too
06:37opqdonut(second-to-last bullet point)
06:39zmyrgelthanks for the link
06:39zmyrgelgotta read it and then check that my project follows the standards
06:54SergeyDHi, is it a Clojure/Java bug if binded var restores its old value unpredictably inside the same thread?
06:57SergeyDSimplified: (def myvar "oldvalue") (binding [myvar "newvalue"] .. myvarIsNew ... myvarIsNew ... myvarIsOld)
06:57SergeyDI use "(prn (. (Thread/currentThread) getId))" to print the current thread id
07:01Zealousso.... how does ns macro works for use again
07:01Zealous (:use [ring.middleware.reload :only wrap-reload]
07:09Zealous error: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol (core.clj:1)
07:09Zealousgoddamn why can't compiler at least tell me which symbol it was or something
07:10SergeyDZealos, use this syntax "[ring.adapter.jetty :only [run-jetty]]"
07:11SergeyDZealos, it usually helps to search for an example or tutorial
07:17Zealousthanks
07:18Zealousnamespace manipulation is one of the worse things abotu clojure for beginners
07:18Zealousunlike java which has 1 form, clojure has like 4
07:21SergeyDI heard a lot of times that error messages are quite bad in Clojure right now. That does not stop me though :)
07:22Zealousright, it could be way way better
09:57angermanjikes.
09:58angermanincanter.core/decomp-eigenvalue produces correct eigenvalues but wrong eigenvectors.
10:08zakwilson(filter (memfn isFile) (.listFiles folder)) <-- isFile does reflection here. Can I use a type hint without putting the result of (.listFiles folder) in a variable, and if so, what's the syntax?
10:10raek,(set! *print-meta* true)
10:10clojurebotjava.lang.IllegalStateException: Can't change/establish root binding of: *print-meta* with set
10:10raek,(macroexpand-1 '(memfn ^java.io.File isFile))
10:10clojurebot(clojure.core/fn [target__3915__auto__] (. target__3915__auto__ (isFile)))
10:11raekhrm, I'm not sure you can do it with the memfn macro
10:11raekbut you can with #(.isFile ^java.io.File %)
10:12zakwilsonYep, works, thanks.
10:17zakwilson(defn foo [a b] (/ (int (count a)) (int (count b)))) <-- call to divide can't be resolved - why?
10:20opqdonutzakwilson: because clojure sucks, mostly
10:21opqdonutgetting the arithmetic ops to not reflect can be a bit hard sometimes
10:21opqdonutzakwilson: try unchecked-divide
10:22zakwilsonI did, and that eliminated the reflection warning. It's less pretty though, and doesn't have any measurable effect on speed.
10:22opqdonutyeah
10:23opqdonutthe reflection reporting in 1.2 isn't perfect. it doesn't report some things that cause reflection, and seems to report reflection in places where there isn't any or it doesn't matter
10:23opqdonutbut it's still a valuable tool
10:25zakwilsonIt doesn't matter here because that code wasn't an inner loop, but I wanted to understand it for situations where it is.
11:09sharat87I am writing a compojure app and am currently running the server with `lein ring server-remote 5000` which works fine, but I want to run the server myself, in my app's core module and I am unable to find any API help on how to do this
11:10sharat87does anybody know how I can achieve this? I'm not sure I presented my problem well, if there are any gaps, please feel free to ask for details
11:10sharat87and also, this is my first with clojure :)
11:31fliebelsharat87: I think the Jetty wrapper is the place to look.
11:37sharat87fliebel, yeah, I am reading the source of lein-ring project on github and trying to figure something out...
11:37sharat87I feel I am quite close... yet so far :)
11:38fliebelsharat87: http://mmcgrana.github.com/ring/adapter.jetty-api.html#ring.adapter.jetty/run-jetty
11:38sharat87yes, the handler object is what I am trying to figure out
11:39fliebelsharat87: The handler is just your ring app.
11:44sharat87um, what's a ring app? I have my app declared with (site main-routes) with main-routes declared with defroutes from compojure, I think
11:46sharat87fliebel, oh yeah, you're right, its just the app I needed to send
11:47sharat87I was sending (var app) instead of app, which I saw in the lein-ring source :)
11:47sharat87guess I should understand stuff before I copy-past ha! :)
11:47sharat87thanks a lot fliebel
11:48fliebelyou're welcome :)
12:13TimMcNote to self: "Wrong number of arguments passed to foo" probably means I have (apply foo ...) somewhere in my code.
12:13opqdonutoh, I've never had that type of bug
12:15TimMcYeah, I was doing (apply map vector vs) and vs was nil instead of being a collection.
12:16TimMcThis is one of the reasons I am suspicious of the supposed benefits of returning nil instead of throwing exceptions.
12:16opqdonutI'm sceptical too
12:26fliebelDoes anyone have a nice snippet using promise? It seems a useful thing, but I never actually use it.
12:32fliebelFor most cases where I would think a promise makes sense, a future makes more sense. Except for interop'y things and 'mutable' bindings. Like… (.putOnStuff javaThreadLoopEventThing (promise)) or (let [p (promise)] (do stuff) (deliver do-more-stuff))
12:32jamesswifthi. quick opinion check. i would like to add a simple text search feature to my clojure app. a search to result in a seq of ids to original text sources. i'm guessing lucene is one of the simplest libs for this or is it over kill? any simple example clojure code existing for this?
12:37TimMcjamesswift: Fulltext search is hard to get right. Using a large-ish lib for it would not be inappropriate.
12:42jamesswiftTimMc: OK thanks. Will have a proper look at Lucene then.
12:48Zealouswhat's wrong with using regex for full text search :)
12:48jlfhi #clojure, does the error "Unable to resolve artifact" during lein deps indicate that a dependency has gone missing from the remote repos or that my project.clj is broken?
12:49ZealousI think it could be either
12:49jlfproject.clj and session transcript at http://paste.lisp.org/display/120696
12:49technomancyjlf: cloud be either one, but it's bad form to remove published artifacts
12:49fliebelZealous: Well, nothing, if you check 5 times 200 characters.
12:49technomancyon the remote side
12:49TimMcjlf: dependency missing from remote repos would be indistinguishable from a misspelled name in your project.clj
12:50technomancyjlf: in this case it's a bug in cascalog
12:50technomancyit's declaring dependencies on jars that aren't in any of the configured repos
12:50jlftechnomancy: ah, thanks. i'll ping nathanmarz.
12:51taloshello :)
12:51technomancyjlf: it's an easy problem to make since the developers always have that stuff already on their machine, so they'd never notice it's not in the default repos.
12:51taloscan i call clojure from jruby?
12:51talosor jython?
12:52technomancytalos: jruby works: https://github.com/technomancy/clojure-gem
12:52jlftechnomancy: who's the clojars maintainer? it'd be sensible to public newly uploaded packages in a sandbox iff they build successfully.
12:52talosthx :)
12:52jlfs/public/publish/
12:52sexpbot<jlf> technomancy: who's the clojars maintainer? it'd be sensible to publish newly uploaded packages in a sandbox iff they build successfully.
12:52technomancytalos: though there are still problems with transaction retries caused by jruby functions
12:52fliebeltalos: Jython also works… https://github.com/rplevy/clojure-python
12:53technomancyjlf: the clojars maintainer disappeared a while ago =(
12:53jlfo_O
12:53technomancyit desperately needs someone to take it over
12:55talosis java part of clojure normally usage?
12:56technomancytalos: not as much these days. but it depends on what you're doing.
12:57TimMctalos: Are you referring to using clojure.lang classes by name in Clojure?
12:57talosi dont know much
12:57talosi just hate java
12:57TimMcOr to using the Java standard libraries from Clojure?
12:58taloslike functional and dinamic languages
12:58TimMcOr perhaps having a mix of Java and Clojure code in a given project?
12:58talosmy question i that in order to use clojure you depend on java?
12:58technomancyit's very rare to see Clojure projects that include Java source code
12:59talosok :)
12:59technomancyit's common to see Clojure projects that use Java classes, but it's not required like it used to be.
12:59fliebelBut it's very common to see Clojure projects use some existing Java code.
12:59TimMctalos: Clojure depends on the JVM and uses Java internally, but you do not need to write .java files in order to write Clojure.
13:00talosok,thx you much guys
13:00talos:)
13:01TimMctalos: https://github.com/timmc/CS4300-HW3/blob/master/src/timmcHW3/gui.clj#L132 <-- this is about as close as I get to Java
13:01TimMcMost of my code is written in a more functional style.
13:06talosi saw the code,for gui what are the options?
13:06talosjava swing?
13:07TimMctalos: You can use any Java library from Clojure code.
13:08talosdo you see a big future in clojure? i like it but i total newbie
13:13talosbye guys thx you :) have a nice day
14:06nickikwhy does this throw a NullPointerExeption? http://paste.lisp.org/display/120698
14:08Zealousno idea, I'm using moustache :)
14:09nickikit throws it a line 11
14:09nickikdeftemplate
14:10raeknickik: probably because it cannot find the file on the classpath
14:10Zealousmaybe selector returns nil?
14:10nickikbut it worked befor and i dont think i changed anything
14:10raeknickik: "resources/templates/404.html" should be sufficient
14:11raeksorry, "templates/404.html"
14:11raekassuming resources/ is the dir that is at the same level as src/
14:12raekdeftemplate throws NPE when it cannot open the file (not a very helpful error)
14:13nickiksrc and resources are both toplevel (readme, project.clj)
14:14nickikif i just write "404.html" where does it lookup the file? in the src directory?
14:14raekwhat does (require '[clojure.java.io :as io]) (io/resource "templates/404.html") return?
14:14raeknickik: in all directories (and jar files) on the classpath
14:15raekso it looks for src/404.html and resources/404.html
14:15nickikis resources on the classpath automaticly?
14:15raekwith leiningen, yes.
14:16raekbut if the directory didn't exist when you started clojure, you might need to restart it
14:16raek...or hack it in with (add-classpath "file://complete/pat/to/resources")
14:18nickikim restarting everything
14:19nickikanother questions if you have images in a template where do the start the lookup
14:19nickik*links to images in a template
14:20raekwell, if the page is served as /foo/bar.html, and it contains a <img src="baz.png" /> the browser will request /foo/baz.png
14:20raekand you have to make your routes serve that file
14:20raek(there is middleware for handling that)
14:22raeksee http://clojuredocs.org/ring/ring.middleware.file and http://clojuredocs.org/ring/ring.middleware.file-info
14:24nickikah ok thx
14:25phenom_what happened to clojure.contrib.string ?
14:25raekit became clojure.string
14:32sineerAnyone knows why (:import com.foo.bar MyClass) gives me ClassNotFoundException running my test.clj this way: java -jar /path/to/clojure.jar test.clj ... yet java com.foo.bar.MyClass works! So my CLASSPATH env var is set properly I believe..
14:34sineerahj -jar overwrite -classpath uh.. never mind
14:35raeksineer: also, it should be (:import (com.foo.bar MyClass))
14:36sineerraek: sorry I did made a typo in my short example..
14:36sineerI keep messing ()s up..
14:36sineererr it not only overwrite the -classpath but I cannot set -classpath manually when I run java -jar ?
14:37nickikif i just want to serve the content of a static file. how would i do that?
14:37sineerI guess the right question is how to start clojure using "clojure" instead of "java -jar" and append the proper classpath ?
14:38technomancysineer: launching clojure manually using the "java" command is usually more trouble than it's worth.
14:39phenom_technomancy: know how to create a project that has java/clojure interop? default project layout assumes only clojure
14:39phenom_with lein
14:40sineerThis is what clojure --help gives me: f0x# clojure --help
14:40sineerUsage: java -cp clojure.jar clojure.main [init-opt*] [main-opt] [arg*] ... so my clojure start script (1.2 from FreeBSD Ports) isn't helping..
14:40raeksineer: clojure does not have a standard launcher
14:41raekthe majority of launcher scripts available are for getting a repl to play with, but are generally insuffiecient when you want to have code in more than one file
14:42raekphenom_: newer versions of leiningen have lein-javac built in
14:42raekjust fill in :java-source-path in the project.clj
14:44raeksineer: when you do have multiple source file or depenency jars, I'd suggest you use a build tool like leiningen, cake or maven
14:44sineerraek: yeah.. thanks.. I think i'll have to do that soon indeed...
14:45raeknickik: this example project serves static files (but uses moustache for routing, rather than compojure) https://github.com/raek/lcug-guestbook
14:46technomancyphenom_: there's no skeleton for that; you can just add a :java-source-path into project.clj
14:46technomancy:java-source-path can even just be "src" for minimal clutter
14:50technomancysomeone's working on a lein plugin to allow more different tyes of skeleton generation; might be interesting.
14:51sineerwtf is this: Exception in thread "main" java.lang.IllegalArgumentException: No matching ctor found for class java.lang.ProcessBuilder (doh.clj:20) ??
14:51sineergenerated byt this line: No matching ctor found for class
14:51sineererr (def proc (new ProcessBuilder "ls"))
14:52raekbtw, epresent rocks for making clojure presentations
14:52technomancyraek: nice! =)
14:53raektechnomancy: I looked at you conj presentation slides to learn it. it's neat!
14:54technomancyraek: unfortunately presentation software is one of those things (like gitjour) that offers very little motivation to continue maintaining after the conference is over
15:11not-timmcsineer: That's a varargs constructor. You'll need to pass a String array in.
15:11sineernot-timmc: yeah I figured it out.. thanks too :-)
15:14not-timmcsineer: (ProcessBuilder. (into-array String ["ls"]))
15:14not-timmcYou can use that shorthand for constructors.
15:15sineercool!
15:16not-timmcYou can also leave out the "String" in my example, since into-array will use the class of the first element, but if you are using a variable from another part of your program it is nice to have that type check.
15:18not-timmcsineer: http://clojure.org/java_interop has a lot of this stuff
15:19not-timmcI wish it mentioned varargs, though -- it's a common stumbling block.
16:39thorwilfun with appengine-magic: com.google.appengine.api.datastore.Key cannot be cast to clojure.lang.IFn
16:40thorwili reduced stuff down to: (ds/defentity Article [^:key path, text])
16:40thorwiland (defn submit-article [] (ds/save! (Article. "foo" "blabla")))
17:46phenom_anyone know how to make type hints show up in a macro/
17:46d5dq(for (i 0 (< 1 10)) (print i))
17:46brehautd5dq: ?
17:47d5dqbrehaut: do you know why that for loop doesn't seem to work
17:47brehautd5dq: beacuse thats not for-loop notation in clojure
17:48d5dqdamn, I copied from someone's clojure code though
17:48brehautd5dq: there are two forms you want to look at: for, doseq
17:48brehautreally?
17:48brehautcurious
17:48d5dqyea, maybe it used to be supported?
17:48raekphenom_: if you (set! *print-meta* true), then you will see metadata when you do (macroexpand-1 '(your-macro ...))
17:48brehautso if you want a lazy seq, you use for, if you want side effects (eg printing) you use doseq
17:48brehautd5dq: ##(doseq [i (range 1 10)] (print i))
17:48sexpbot⟹ 123456789nil
17:49d5dqsweet thanks
17:49brehaut&(for [i (range 1 10)] (print i))
17:49sexpbot⟹ (123456789nil nil nil nil nil nil nil nil nil)
17:51brehautd5dq: sexpbot made a wee bit of a mess of that, but its returned a lazy seq of nils (print returns nil) as well as printing all the values. do-seq returned one nil
18:23devnhey everyone
18:28brehautmorning devn
18:40d5dqcan someone tell me why this is not working: https://gist.github.com/878748
18:40phenom_hmmm, raek: I see the metadata but im still getting refelction warnings though I see the type hints
18:42d5dqnm found the problem
18:42d5dqwrong order
18:44raekphenom_: I guess you could try evaluating the macroexpansion and observe what form the compiler complains about
18:46raekthe compiler shouldn't be able to tell if the code comes from a macro or directly from the original source
18:47raekare you sure typehints are in place for the call it warns about?
19:18phenom_raek: turns out I had to fully qualify the class of the hint, or import those classes in the calling .clj
19:20brehautphenom_: good to know. and well done
20:12devni wonder if we're being robbed on github due to the fact that most clojure apps are small enough that simply packaging with jquery with it makes it show up as a js repository
20:27not-timmcdevn: What's an example of a Clojure app with jQuery in it? Like, a web app?
20:27not-timmcOr do you mean .js in doc files?
21:11ymasorywhich is the "official" clojure-mode repo?
21:33phenom_are 1.3 nightly builds available from maven ?
22:39tomojneither bot agrees, but for me ((fn [] {:foo})) throws the expected error while (do (defn foo [] {:foo}) (foo)) and (letfn [(foo [] {:foo})] (foo)) return {}
22:40tomoj..why?
22:44xlarsx{:foo} is a dictionary so you need a key/value {:foo 1} for example
22:44xlarsx=> {:foo}
22:44xlarsxjava.lang.ArrayIndexOutOfBoundsException: 1
22:48xlarsxthe 3 options throws the same Exception
22:48tomojnot for me, as I said
22:49xlarsx(I'm using Clojure 1.2.0)
22:49tomojhmm, in a bare repl they all throw
22:49tomojin my slime repl the latter two return {}
22:50tomojmust be something crazy swank-clojure does
23:52devnnot-timmc: many of them...
23:52devnnot-timmc: granted you could just remove the JS and source it from google, but either way, kind of a bummer
23:57brehautdevn i think they some sort of filter to by filename.