#clojure logs

2009-12-13

00:16quizmehttp://clojure.org/runtime_polymorphism <--- seems like it can do everything OO can do
00:16quizmeexcept inheritance?
00:18harrisonyou can use (derive ::child ::parent) for that
00:18Licenseralso the article is about polymorphism not inheritance :)
00:22Licenserhttp://clojure.org/multimethods <- is on multimethods and herachies
00:22harrisoni'm getting this error when i try ant or ant jar: "[javac] javac: target release 1.5 conflicts with default source release 1.7" does that mean i can't use java 7, or is there a way to make it work?
00:23Licenserit looks to me like you are trying to run ant jar with a java 1.5 while the task says it wants 1.7
00:25harrisoni just did a clean install of windows and put java 7 on it. it shouldn't even have older versions on it
00:26harrisoni'll try it with java 6 and see if it works, i guess. that's what i have on my linux box, and it works fine there.
00:27tomojthe build.xml in clojure has target="1.5" in compile-java
00:27tomojI guess you could try changing that to 1.7.. :/
00:29harrisontomoj: seems to be working. thanks! (no error yet, anyway)
00:29tomojhmm. does this mean 1.7 is not backwards-compatible with 1.5, but 1.6 is?
00:30quizmebasically methods are not attached to objects.
00:30Licensertomoj: 15 and 16 are not entirely compatible as well
00:30LicenserI think at least
00:30alexykhow do I require c.c.duck-streams.with-out-writer without prefix?
00:30Licenserwhen I remember riht I had already the problem that it told me 'can't run this, it's made for 1.6 but you use 1.5'
00:31harrisonLicenser: but you should never see "it's made for 1.5 but you use 1.6", right?
00:31Licenserno that should not happen and I don't think it will happen
00:31Licenserw
00:31Licenserwhat you see is the result of ANT not java
00:32Licenseralbino: use use not require ;)
00:32alexykwhat I mean is, what's the import form after which I can use (with-out-writer ...)
00:32Licenser(use '[c.c.duck-streams :only (with-out-writer)])
00:32LicenserI think that was the syntax
00:32tomojor with a symbol and without the quote inside ns
00:33tomoj(ns ... (:use [clojure.contrib.duck-streams ...
00:33alexykLicenser: I wonder why some choose require, some do use?
00:33tomojnot a matter of personal preference :)
00:34tomojuse is the one that pulls stuff into your namespace so you can use it with no prefix
00:35Licenseralexyk: use includes methods in your namespace, require only tells the VM to load the file so you could access the namesace
00:35tomojrequire would be useful for instance if you wanted to say (duck-streams/with-out-writer ..)
00:35alexyktomoj: you mean clojure-contrib.duck-streams/... ?
00:36LicenserI used require when I had a few namespaces with the same functions in it soI could use a name space prefix
00:36Licenseralexyk: you can 'alias' namespaces
00:36tomojyeah, require's :as lets you give them a shorter name
00:37tomojthat's pretty much all I've ever used, require :as and use :only
00:37tomojif you wanted to call it like (dick-streams/with-out-writer ..) you could do that too with require :)
00:38Licenser(require 'clojure-contrib.duck-streams :as 'dick-stream)
00:39tomojneed a vector around that I think
00:40tomojI think whenever you're passing options that are specific to a particular namespace, you need to group them in a seq
00:40tomojand no quotes inside ns, otherwise...
00:40Licenserbut it's the general spirt
00:42tomojwe can't nest libspecs, can we?
00:42tomojer, prefix lists I mean
00:44LicenserRest well people!
00:44tomojseems not
00:45tomojI think it might be kinda cool if you could, for big branchy libraries like compojure
00:46tomoj(:use [compojure [server [jetty :only (jetty-server)]] [http [servlet :only (servlet)] routes]])
00:46tomojguess you don't save all that much typing :)
03:32taliosDoes anyone know of a way to pretty print clojure code from java? I was hoping clojure.lang.RT.doFormat() / .print() etc. might help but no :(
03:32taliosI guess it's time to hack up something nasty to start with then.
03:32Carkhhave you tried using clojure.contrib.pprint ?
03:34taliosFor some reason I couldn't get that working from java. Keep geting "clojure.contrib.pprint/cl-format is unbound", after I RT.var() it.
03:34taliosthen .invoke()
03:34taliosI suspect I was missing something simple there thou
03:35Carkhyou need to (use 'c.c.pprint) first i think
03:35taliosI think I might be best off manually doing this anyway, for what I'm wanting to do anyway ( code gen from java )
03:54aluinkim trying to build a partial with a static method in java.lang.Math
03:55aluinkthis is what i'm thinking, but it doesn't work (partial (. java.lang.Math (max)) 1)
03:56aluinkthe idea would be to use it in a call to map or something, kinda like (map (partial (. java.lang.Math (max) 1)) [1,2,3,4])
03:56_atoaluink: java doesn't have first-class methods, they aren't objects, so you can't pass them around
03:56_ato,(map #(Math/max % 3) [1 2 3 4])
03:56clojurebot(3 3 3 4)
03:56aluinkhmmm, can i wrap one with a first class method?
03:56_ato,(map max [1 2 3 4])
03:56clojurebot(1 2 3 4)
03:57_atom
03:57_atoerr
03:57_ato,(map (partial max 3) [1 2 3 4])
03:57clojurebot(3 3 3 4)
03:57_atoI prefer the lambda syntax though
03:57_ato,(map #(max % 3) [1 2 3 4])
03:57clojurebot(3 3 3 4)
03:57hiredmanit's a function
03:58aluinki'm used to Haskell currying if you're at all familiar
03:58hiredmannot a first class method
03:59hiredman,(pl (↕map (replicate 3 (↕apply vector $ (↕map range $ 10 inc · inc · inc) call · ⌽* $ 10 · call · (⌽+ -2) map)) shuffle)))
03:59clojurebot((50 80 90 40 100 60 30 70 10 20) (60 100 30 80 20 40 90 70 10 50) (50 90 70 10 40 60 20 30 80 100))
03:59_atoI knew that was coming :p
03:59hiredmanhaskell?
03:59clojurebothaskell is Yo dawg, I heard you like Haskell, so I put a lazy thunk inside a lazy thunk so you don't have to compute while you don't compute.
04:00aluinksay whaah?
04:01hiredmanhaskell like currying would be neat, but how do you curry functions like max that can take an infinite number of args
04:01aluinkwell, i was more thinking of currying functions from the java standard api that take a fixed number of args
04:02aluinki guess that gets tricky with overloading with multiple args
04:02hiredmanthose are not functions
04:02hiredmanthey are methods
04:02hiredmannot first class values and attached to an object
04:03aluinkhmm, i guess i have to learn the difference between class methods and fc fns
04:03aluinkoh, sorry...fc methods
04:03hiredmanaluink: their aren't first class methods outside of the Method objects you can get using reflection
04:03hiredmanthere
04:04hiredmansome people just use "function" and "method" sloppily
04:04aluinkwhoop! over my head
04:05aluinkhaha, Lisp*
04:05hiredmanno one will know what you are talking about (except _ato) if you say first class method
04:06hiredmanbecause the only place such a thing could be said to exist is in the java reflection api, and no one calls them that
04:07hiredmanmethods are not values, you can't pass them around, or put them in a collection
04:08hiredmanfunctions are values, and you can pass them as arguments to other functions, and put them in collections, and do all the things you can do with values with them
04:14aluinkok, now why doesn't this work? (defn m ([y] (max 2 y)))
04:15aluink(max n) always == n
04:16hiredmanerm
04:16hiredmanthe function you defined is bound to the name m
04:17hiredmanwhen you are doing a single arity function you would write it like (defn m [y] (max 2 y))
04:17hiredman,(doc max)
04:17clojurebot"([x] [x y] [x y & more]); Returns the greatest of the nums."
04:17hiredmanif you pass max a single number, that single number is always the greatest number you passed
04:25aluink,(defn m [x y] (max x y 3))
04:25clojurebotDENIED
04:26hiredman,(let [m (fn [x y] (max x y 3))] (m 4 5))
04:26clojurebot5
04:26hiredman,(let [m (fn [x y] (max x y 3))] (m 30 5))
04:26clojurebot30
04:26aluinkiz'a learning
04:26aluinkbut needs sleep, thanks and night all!
04:31Carkhgrmbl, crypto api not working the same on solaris ... gotta love that
04:45LauJensenWhen the profiler says that I'm spending all my time sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run() - Does anyone know what means? This is a trivial I/O heavy app which doesn't use network in any way
04:45LauJensenI/O as in Harddrive
04:47LauJensenAh, I got tripped up by the time but I see now that its only 7 invocations, so its the instrumentation, nvm :)
06:28LauJensenWas spew or spit ever implemented for quickly dumping data to a text file ?
06:36LauJensenin contrib still I see
07:05LauJensenCan anybody think of an elegant way of transforming (["one" 1] ["two" 2] ["three" 3]) into one\t1\ntwo\t2\nthree\t3 - that is, interposing tabs and newlines ?
07:05LauJensenand by elegant I dont mean (apply str (interpose \newline (map #(apply str (interpose \tab %))) and so on
07:11_ato,(str-join "\n" (map #(str-join "\t" %) [["one" 1]["two" 2]["three" 3]]))
07:11clojurebot"one\t1\ntwo\t2\nthree\t3"
07:12LauJensen,(doc str-join)
07:12clojurebot"([separator sequence]); Returns a string of all elements in 'sequence', separated by 'separator'. Like Perl's 'join'."
07:12_atoin str-utils
07:13LauJensenah ok, thanks
07:32fliebelwhat does it mean if the doc says "in linear time"?
07:32LauJensenO(n)
07:33LauJensenMeaning if the operation takes 1 sec for 1 item, then it takes 100 secs for 100 items
07:35fliebelthanks
07:41fliebelA lazy seq is actually some magic function that returns only what is asked for, right? I'm trying to understand how they work, how I can fiddle with them and how I can make my own.
08:23fliebelI'm staring at the lazy_seqs.clj source for a hint on what's actually happening. I understand that you can use iterate or map on a function that will return one part of the list at a time, and only need as much calls as items requested. but there is still some black magic going on there I don't understand.
08:24chousereach step of a lazy seq has a closure inside.
08:25fliebeluuuhm...
08:25chouserwhen you call 'first' or 'rest' or 'seq' on a lazy seq, it invokes the closure, expecting to get back a cons or nil. If it's nil, all those return nil.
08:26chouserIf the closure returns a cons then that result is cached in that step of the lazy seq. Then 'first' returns 'first' of the cons, 'rest' returns 'rest', and 'seq' returns the whole cons.
08:27fliebelI can understand first… it just invokes the whole train once and… voila, the first value pops out.
08:27chousernot the whole train, just one step.
08:28chouserafter invoking that first closure, you now have cached both the first value and a closure that represents all the rest (but hasn't been called yet)
08:28chouserok, sorry, gotta run. good luck!
08:28fliebelthanks… :S
08:29fliebelis there someone else to take over the story?
08:31fliebelclosures is just that you save the state of a scope for later, isn't it?
08:35fliebelI should really work on my code understanding… It took me far to long to grasp 4 lines of code: http://lispwannabe.wordpress.com/2008/10/24/closures-in-clojure/
08:37fliebelThis confirms the way I was thinking about closures, but that does not explain to me how you can "invoke" a closure.
08:39cypher23fliebel, you don't, really. You invoke something that has a closure, like a function
08:41fliebelah
08:41fliebelnow I got to run, I'll search on later...
10:04LauJensenI've blogged about how to implement a parallel newsgroup parser in 19 lines of Clojure, contrasting with Scala and Ruby: http://www.bestinclass.dk/index.php/2009/12/clojure-vs-ruby-scala-transient-newsgroups/
10:17DeusExPikachuwhat's the syntatic difference between a map entry and a map? I'm trying to figure out how to use val or key
10:23the-kennyDeusExPikachu: What do you mean with "difference between map entry and a map"?
10:24DeusExPikachuwell, syntatically, I'm trying to use val, the doc says "returns the key of the map entry", I try putting a map in there, doesn't work, I try putting a vector of the key and value, doesn't work
10:24DeusExPikachuI can't figure out to input a map entry
10:26the-kennyDeusExPikachu: I think val operates on a java-class and not the clojure equivalent
10:28the-kennyDeusExPikachu: If you want to get all values on a map, use vals
10:29LauJensen,(class {:one 1 :two 2})
10:29clojurebotclojure.lang.PersistentArrayMap
10:29LauJensen,(class (first {:one 1 :two 2}))
10:29clojurebotclojure.lang.MapEntry
10:29LauJensen,(map val {:one 1 :two 2})
10:29clojurebot(1 2)
10:32bagucodeLauJensen: Read the blog post. Good stuff.
10:33LauJensenbagucode: Thanks a lot
10:36bagucodeAnyone here familiar with leiningen and ant? I'm trying to modify leiningens compile task to be able to set a directory for java.library.path and I think I got the correct path into a .addProperty on the ant java task but it does not seem to help. (Still get UnsatisfiedLinkError).
10:37bagucodeHere is my version of compile.clj http://github.com/bagucode/leiningen/blob/master/src/leiningen/compile.clj
10:49DeusExPikachuthe-kenny, I'm trying to understand someone else's code so I just needed to understand the usage of val and key; LauJensen, so to confirm my understanding, a MapEntry can not be expressed without the help of a dereferencer (e.g. first, find) applied to a map?
10:50LauJensenyou're asking if it has a constructor ?
10:53DeusExPikachuI'm asking if there's a first class like syntax for expressing a MapEntry like [] for vectors or {} for maps, "" for strings etc
10:54LauJensenNot that I know of. A MapEntry exists in a map only. At least thats my impression
10:55DeusExPikachuLauJensen, ok, thanks
10:59tomoj,(map #(+ (key %) (val %)) {1 2, 3 4, 5 6})
10:59clojurebot(3 7 11)
11:16IntertricityDoes anyone here play with ClojureCLR?
12:00fliebelLauJensen: Fun post :)
12:00LauJensenfun as in you liked it, or in many typos? :)
12:01the-kennyLauJensen: What's the url of your blog?
12:01the-kennys/blog/blag/
12:01LauJensenhttp://www.bestinclass.dk/index.php/blog/
12:01LauJensenThats the blog, I dont have a blag yet
12:02Carkhyou're missing out, these are all the rage these days
12:03fliebelwhat is a blag?
12:03the-kennyhttp://www.xkcd.com/148/
12:03rhickeyClojure vs ____ posts hurt Clojure.
12:06fliebelrhickey: just the name, I think it's cool to compare two jobs done in different languages. Not necessarily for speed, but also for lines and readability.
12:06tomoj"Clojurian" :)
12:06rhickeyThey are antagonistic, they always misrepresent ____, they will never convince users of _____ anything since they have been put on the defensive, they encourage talk of fanboyism and erode people's opinion of the Clojure community
12:07IntertricityI was convinced of clojure a long time ago :3 but I'm only a python programmer, clojure will be my second language.. I get this feeling I should know like, C++ or Java before I enter
12:08IntertricityI've only done simple console based programs but I want clojure to become the language I'm fluent in :P
12:09fliebelrhickey: That is what I mean. It's mostly in the way those ___ vs ___ are represented I think.
12:12IntertricityI think ____ vs. ____ threads can be useful in finding what language does what better for specific purposes. But general ____ vs ___ threads I think, yes, are harmful.
12:13fliebelI agree with intertricity… I tend to look at a few of them to see if they fit my purpose and style and make my own decision. (i usually don't comment on them)
12:14IntertricityMoreover, it saves me the trouble of taking a month or two to learn it before I find that I hit a brick wall and have to go back to the drawing board.
12:15fliebelbut still the best way to decide on anything is to compare the number of google results *sarcasm*
12:15Intertricityhaha
12:16Intertricityok I gotta do the fanboy thing a sec at rhickey- thankyou for making clojure :D I've been wanting a reason to learn lisp
12:16rhickeyhttp://rosettacode.org/ is a neutral way to do comparative coding
12:16rhickeyIntertricity: you're welcome
12:16Intertricity:)
12:17IntertricityI'm currently trying to assemble the pieces to try out ClojureCLR. I have a .Net project I'd like to use to learn with.
12:18LauJensenrhickey: You've raised that concern before, but I must admit that after seeing you slam all OO languages with your Java keynote, your "Common Lisp leaves you high and dry" on Clojure.org, and your 3x comparison slam in that magazine interview, I must admit I found it to be a bit hypocritical
12:18LauJensenMore so, there are several people that I've written with who are now trying out Clojure in response to comparisons
12:21rhickeyLauJensen: your posts are full of value judgements, my JVM summit keynote made technical points about OO, time and values
12:24rhickeyLauJensen: where is the "Common Lisp leaves you high and dry"?
12:24LauJensensec
12:24rhickeyand what magazine article?
12:24LauJensenI was just trying to find the pdf. It was an interview you gave to Developers Journal or such
12:25the-kennyYay... looks like forking swank-clojure on Github got stuck. No way to cancel :/
12:30LauJensenrhickey: In Clojure.org's rationale there used to be a phrase RE common Lisp which said 'left you high and dry in terms of datastructures', but that has been removed I see
12:32LauJensen"I think the Lisps prior to Clojure lead you towards a good path with functional programming and lists, only to leave you high and dry when it comes to the suite of data structures you need to write real programs"
12:32LauJensenFound here: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips
12:34rhickeyLauJensen: so you trim the beginning and end off of that sentence and misconstrue it as a pot-shot? Gimme a break
12:35rhickeyI said the same thing (the entire idea of that sentence) right to the faces of the people who invented Lisp and Scheme and they didn't disagree
12:35rhickeythe non-list data structures of traditional Lisps are not functional
12:36rhickeythat's just a fact
12:37LauJensenI trimmed it to focus your attention on what I have referenced
12:37IntertricityWill ClojureCLR compile with VS 2008 express?
12:37IntertricityI only have a full version of 2005
12:38LauJensenbbl, you can accuse me of more things after dinner :)
12:42IntertricityAnybody know about the express 2008 compile?
12:43scgilardiIntertricity: I don't know for sure, but I believe the differences between the express versions and full versions have to do with things like source control integration and other "only needed by professionals" features. My guess is it would work fine.
12:44Intertricityscgilardi, ok thanks so much :)
13:31Qvintvsmight anyone have any ideas as to why my swank repl has decided to stop evaluating code I type into it?
13:32scgilardiany chance you haven't yet supplied enough close-parens, close-braces, etc.?
13:50Qvintvsuser> (def a 4) ... <enter> nothing, no new "user>" prompt. cursor just moves one line down.
13:51the-kennyQvintvs: hm.. have you changed the mode or something? I'd try restarting the repl
13:52Qvintvsive restarted it tons of times. (def a 4) was the first thing i typed in the repl.
13:52scgilardidoes looking at your *inferior lisp* buffer give any clue?
13:54Qvintvsnothing as far as I can tell: http://pastie.org/741558
13:56Qvintvsprobably worth mentioning that i was playing around with sbcl in slime before, but i removed all traces of slime/swank i could find and completely reinstalled them
13:57scgilardithe inferior lisp looks good. it shows you're running clojure 1.0.0 (I assume that's what you intend). The repl in *inferior lisp* is "live". Is it true that Clojure does respond when you type there?
14:10Qvintvssry, yes, it works there
14:15alexykmost comparisons of Clojure vs Scala, for example, are done by people who don't know at least one of those languages well. :)
14:15qedLauJensen: nice post on the newsgroups
14:16alexykliebke: ping
14:16LauJensenqed: Thanks :)
14:16qedalexyk: while that's true, there are levels of "know"
14:17qedif they are even intermediate level in both languages i think it's very telling of a language's strengths and weaknesses
14:17qedyou shouldnt have to be an uber advanced master of scala to write decent code
14:18liebkealexyk: what's up?
14:18alexykqed: generally, a comparator is a fan of one of the languages and optimizes the heck out of it. Since he or she doesn't really know the other language, which he/she was turned off by, he/she takes a "to" code from a book, written hastily by an author who wanted to be the first to publish and is not a specialist on optimizing his language either. :)
14:18alexykliebke: I found that Mongo is the ideal back-end for Incanter!
14:18alexykany dataset goes right back via congomongo
14:18liebkereally? sounds cool!
14:19alexyksay you compute a list of results, like pagerank. It's fed right back into Mongo and then can be visualized by incanter from another shell by easily reading it back and e.g. histogramming.
14:19liebkeyou should write something up, I'd love to see it
14:20alexykliebke: it's really simple, I'll do a post on histogramming Twitter pagerank with incanter next week.
14:20alexykbasically, I sense Incanter+Mongo is the R-killer. :)
14:20liebkeexcellent :-)
14:21LauJensenalexyk: Your right, I'm not a Scala Expert and I haven't tried to optimize the code, but I think I also state that in the conclusion, that its just for kicks and nothing too serious
14:21liebkehehe, I like R too much to kill it :-)
14:23alexykLauJensen: I've tried to generalize,nice comparison for mechanisms demonstration, but numerically WideFinder in Scala from a year ago is still faster than all Clojure effort as of late, per twbray :) It's a risky business, comparisons...
14:23alexykliebke: did you try to interface Incanter to rJava?
14:23LauJensenAnd Tim Bray has now coded Clojure for how long, 3 weeks? :)
14:23alexykLauJensen: he got code from technomancy and the John of Milo!
14:24LauJensenAh ok
14:24LauJensenWell yes, comparisons are tricky
14:24alexykLauJensen: generally he was advised on clojure much better than on Scala, and Scala does right next to Java there (from a year ago).
14:24scgilardiQvintvs: sorry, I don't know what to suggest next.
14:25LauJensenalexyk: But I really cant trust any conclusion on Clojure performance which has not been through CGrand at least once :)
14:25qedha
14:26liebkealexyk: no, I don't have any plans to interface with rJava at this time
14:27alexykLauJensen: can you prod him to optimize wide finder? that would be awesome. twbray gives accounts to serious optimizers on his box. Then the race can be on again :)
14:27alexykliebke: I tried plotting in Mathematica via Clojuratica, too. X11 is much slower across the network, a no-go, but perhaps Export into a PDF may work.
14:27LauJensenI would be seriously surprised if cgrand couldn't bring Clojure up to par with Scala - cgrand you up for it?
14:28alexykLauJensen: it appears it's still Sunday in France :)
14:29LauJensenoh thats right, snail time, nom nom nom :P
14:29alexykLauJensen: with that Bordeaux :)
14:29LauJensenWhere's the code of tbrays most recent attempt?
14:29cgrandred wine with snails... absolute nonsense
14:30alexykLauJensen: the whole story is here: http://www.tbray.org/ongoing/When/200x/2009/09/27/Concur-dot-next
14:30alexykcgrand: that was intentional to cause outrage :)
14:30LauJensen<cgrand> I am so angry I could optimize the bytecode out of widefinder!!
14:31alexykif you guys are up to it, I'll wake up Erik Engbrecht of Scala who did the last year submission to WF
14:31alexykthat should be still on the box, porbably
14:32cgrandactually, I was thinking of revisiting WF2 before twbray started blogging about clojure. I hope I have time after xmas. Meanwhile I have too much on my plate
14:32LauJensenits your call cgrand, I can probably get it down to Scalas time, then you need to go beyond :)
14:33cgrand18 months ago my best attempt ran in 16mins iirc (on the niagara box).
14:34LauJensenHow long does Scala take?
14:34LauJensenAnd where's the link to his .clj file ?
14:35alexykcgrand: that's almost at Scala/Java time, 14 mins iirc
14:35qedhahahahaha i just found M-x doctor in emacs
14:36cgrandalexyk: then i don't remember correctly
14:38LauJensencgrand your last post states "So far my best runtime on the whole dataset is 27 minutes."
14:40alexykLauJensen: yeah, that's what twbray reported, too.
14:40cgrandI haven't blogged about my subsequent gains because they were too ugly. 18 months later I'm (hopefully) wiser and have new toys (transients).
14:41alexykcgrand: would be awesome to see!
14:42LauJensenYea, if optimal Clojure is 27 and Scala is 14, I suggest we buy Rich a weekend retreat somewhere nice so he can reflect on the art of writing compilers :)
14:42qedcareful, you're lible to get stabbed
14:43Chousuke:P
14:43stuarthallowaywhat do you think this should return: (flatten [1 2] nil [3 4])
14:43stuarthallowayhm, make that (flatten [[1 2] nil [3 4]])
14:45alexykLauJensen: that's right, the ultimate shootout is between Rich and Martin Odersky -- then the retreat must be somewhere neutral, like Australia... :)
14:46LauJensenhehe
14:46alexykbut I've come to appreciate compactness of sexps and dynamic typing for data mining. It's not coincidental that R is also dynamic.
14:46alexykhence Incanter is a terrific idea for Clojure
14:47alexyk...and Mongo as its JSON, dynamic store
14:47alexyk...and Mathematica is very similar, hence Clojuratica.
14:49LauJensenJ is the bomb though, for math stuff :)
14:49alexykthe main problem, I guess, it graceful handoff os heavy-duty stuff to computationally optimized engines, then getting it back.
14:49LauJensenaverage=. # % /+
14:49LauJensendoesn't get any better than that
14:49LauJensenAnyway, I gotta jet :)
14:52fliebelyou know what would be really helpful? a "see also" section for functions in the api. so if you look at print it will tell you there is also println.
14:56Drakesonhow should I use nailgun with clojure such that the context is also passed to the ns? (who should subclass NGContext? clojure or the ns?)
15:02alexykthe-kenny: there's apparently a nailgun plugin, but I didn't try it yet
15:03alexyk~google "leiningen nailgun"
15:03clojurebotFirst, out of results is:
15:03alexykhttp://clojars.org/lein-nailgun
15:06the-kennyalexyk: If I look at the sourvce inside the .jar, it looks like the plugin only starts the server, not running leiningen with it
15:08alexykthe-kenny: that's too bad
15:09alexyk~google lein nailgun
15:09clojurebotFirst, out of 484 results is:
15:09clojurebotRe: combining vimclojure, classpaths and leiningen: msg#01039 clojure
15:09clojurebothttp://osdir.com/ml/clojure/2009-11/msg01039.html
15:09alexykah, ok, so queries are not quoted.
15:15digashthis does not look right to me (concat [-1] (range 5))
15:16digashis this a best way to prepend element to the collection
15:16stuarthallowaydigash: why not cons?
15:16digashdoes cons work with all coll?
15:18stuarthalloway,(doc cons)
15:18clojurebot"([x seq]); Returns a new seq where x is the first element and seq is the rest."
15:19digashha, years of programming CL and I did not think of obvious cons, thank you
15:23qedoh man that's cool: (defn tally-map [coll] (reduce (fn [h n] (assoc h n (inc (or (h n) 0)))) {} coll))
15:43chouser,({:a 1} :b 0)
15:43clojurebot0
15:44chouserqed: so, (h n 0) instead of (or (h n) 0)
15:51fliebelI just finished writing my own prime number generator… it's about 10 lines of code. Can anyone have a look at it, to see if it's good and done "the Clojure way"? http://pastebin.com/m220ba365
15:55fliebelLol, for numbers below 100 or 1000 it's quite fast, but I'm still waiting for it to finish with 1000000 :D
15:55Chousukefliebel: why do you sort m if you put them into a set right away?
15:56Chousukealso it'd be more idiomatic to use the set itself as the filter predicate
15:57Chousuke(filter #(not (contains? non %)) ...) is equal to (remove non ...) :)
15:58Chousuke(or (filter (complement non) ...))
15:58fliebelok...
16:00fliebelchousuke: what do you mean with the second thing?
16:00ChousukeI mean (filter (complement non) ...) is equal to (remove non ...)
16:01fliebelI meant before that… the idiomatic stuff.
16:01Chousuke,(#{1 2 3} 3); sets are functions too
16:01clojurebot3
16:01Chousuke,(filter #{2 3} [1 2 3 4 5])
16:01clojurebot(2 3)
16:02fliebelhuh...
16:02Chousuke,(remove #{2 3} [1 2 3 3 4 1 2 5])
16:02clojurebot(1 4 1 5)
16:02fliebelwow....
16:02fliebelworks :)
16:03fliebelI agree that looks better...
16:03Chousukeyou need to use contains? if your set contains falses though :/
16:03Chousukebut that's not very common
16:03fliebelonly numbers...
16:04fliebelis there more I can improve?
16:04Chousuke,(#{false} false); using a set as a function return the item, if it's in the set, so...
16:04clojurebotfalse
16:04Chousukereturns*
16:04sethswow, that's subtle
16:04sethsneat tho
16:05Chousukeoften it's not a problem :)
16:06fliebelnil is the only thing besides false that evaluates to false isn't it?
16:07Chousukeas a boolean, yeah.
16:07Chousukethough you can construct objects of the Boolean class too
16:07fliebelhm
16:07ChousukeBut you shouldn't.
16:08Chousukeuse Boolean/TRUE and Boolean/FALSE if you need them :)
16:08fliebelwhat do you think of my prime thing as a whole? it's not very efficient is it?
16:09ChousukeI guess so :/
16:09sethsdoes clojure contrib have a prime # generator?
16:09fliebelyes
16:10ChousukeI don't see anything really wrong with it though, so maybe it's just a slow algorithm?
16:10fliebelit's in lazy-seqs
16:10Chousukeexcept for the sorting, of course. I don't understand why you put that there :/
16:11fliebelchousuke: I removed it… It was for my testing, to make it easy to check the output for a human.
16:12Chousukeah
16:12Chousukeif you wanted to make that more idiomatic the next step would probably be to remove the loop
16:12fliebelis a set the only thing you can call contains? on?
16:13Chousukebut I'm not sure which higher-order function is suitable :)
16:13Chousukethe loop might well be the easiest
16:13fliebelah, like map and filter instead of recur?
16:13Chousukeor partition or iterate or whatever.
16:14fliebelhow many of those are ther?
16:14notallamayou can call contains? on maps (for keys) and vectors (for index)
16:14Chousukefliebel: quite a lot
16:14Chousukefliebel: and you can of course write new ones yourself
16:15ChousukeI'm not saying loops are always bad, but I think it's good exercise to solve problems without explicit looping :)
16:15fliebelchousuke: some more structure and help would be welcome in the api… It's one of the few things I like about PHP.
16:16fliebelchousuke: like if you're looking at map it'll tell you that you can also look at filter, reduce, etc for similar behavior.
16:16notallamai generally treat loops as a code smell. they're not always bad, but they have the stench of premature optimization or not thinking the problem through enough.
16:16Chousukeyeah, well, the API doc is entirely generated from metadata right now, and the Clojure functions contain no cross-reference metadata
16:17sethsthe doc pages improved recently though, the urls are different
16:17Chousukeyeah. it's a work in progress.
16:17sethsclojure.org points to github for docs now?
16:18ChousukeI think so
16:18fliebelchousuke: If I only knew those functions I'd love to contribute :D It's a kind of chicken-egg problem, you see...
16:18ChousukeIf you want examples, reading core.clj itself is pretty good. Or contrib stuff.
16:18Chousukethere aren't that many functions :)
16:18Chousukeyou can keep almost all of core.clj in your head.
16:19fliebelnot at once I guess, having a good reference would ease the learning.
16:20sethsI am trying to understand how (alter) works. It almost seems like it merges... (code follows)
16:20seths,(def lunchbox (ref { :snacks [], :healthy_food [] } ))
16:20clojurebotDENIED
16:20sethsoh well
16:20seths(dosync (alter lunchbox assoc :healthy_food ["apples"]))
16:20seths(dosync (alter lunchbox assoc :snacks ["chips", "cookies"]))
16:20notallamafliebel: there's the cheat-sheet kicking around somewhere. also, it's handy to look at the sequences page on clojure.org
16:21sethsthe second call to alter (which would normally be inside the first's dosync?) makes no attempt to merge
16:21sethsbut the apples are there afterwards
16:21Chousukemerge?
16:21fliebelnotallama: The cheat sheet would be great! I read most of sequences and data_structures…
16:21seths,(doc assoc)
16:21clojurebot"([map key val] [map key val & kvs]); assoc[iate]. When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the mapping of key(s) to val(s). When applied to a vector, returns a new vector that contains val at index. Note - index must be <= (count vector)."
16:22Chousukeseths: of course. you altered the ref with the previous alter call
16:22Chousukeseths: so the next alter call uses the value which has the apples
16:22Chousukerefs are mutable, remember :)
16:22sethsright
16:23sethssorry, I was overcomplicating it in my head
16:23Chousukeyeah. it's pretty simple.
16:23sethslunchbox is derefed and then passed as the first argument to assoc?
16:23dabdhi I'm trying to start a Project REPL with netbeans's enclojure but it fails to start even though I have added clojure.jar and clojure-contrib.jar to the project. any ideas? thx
16:23Chousukeseths: something like that.
16:24sethsthanks!
16:24Chousukethe key thing to remember is that assoc itself never mutates anything. it works with values.
16:25Chousukeand dosync, alter and refs handle the icky stuff
16:31fliebel(defn odd? [n] (not (even? n))) is the same as (def odd? (complement even?)) right?
16:58the-kennyMaybe I'm finally going to write a log-converter from Pidgin to Adium§
17:06polypuswhat's the simplest xml emitter lib for clojure.
17:06polypus~ping
17:06clojurebotPONG!
17:29tolstoypolypus: prxml (clojure.contrib)
17:37polypustolstoy: yep found it a minute ago, but ty
18:00iMhello
18:02the-kennyhi, iM
18:02iMoops
18:03ssideriswrong nick
18:15polypuswhat should i bind to *out* to get a string instead of printing to stdout?
18:15tolstoywith-out-str
18:15tolstoyEr, or something like that. It's in core.
18:15polypustolstoy: thx again
18:16tolstoyI just did this stuff, using compojure for a resty thing.
18:47j3ff86i've been trying to find this in clojure book but didn't find an answer: what exactly does the ' macro do?
18:47j3ff86(quote)
18:48tolstoyprevents a symbol from being evalutated
18:48j3ff86ah, thanks
18:48j3ff86oh and what about the # sign?
18:48tolstoyDepends on context.
18:49qed#{}, #', #""
18:49scgilardimore detail here: http://clojure.org/reader
18:49j3ff86thanks
18:49qedif i have a route in compojure like (GET "/docs:entry" (example-entry (params :entry))
18:50tolstoyAlso: http://java.ociweb.com/mark/clojure/article.html#Syntax
18:50qedhow do i response to those params in an example-entry function
18:50qedrespond*
18:50tolstoyqed: You can just return a stirng, if you want.
18:51qedcould you give me an example?
18:51tolstoyOr, (html [:h1 "hello"])
18:51qedlike (defn example-entry [arg1] (html [:h1 :entry]))?
18:51qedhow do I use :entry
18:51tolstoyHm.
18:52tolstoy(GET "/docs/:entry" (let [value (. request route-params :entry)] (html [:h1 value]))
18:52tolstoySomething like that.
18:52qedah, thank you
18:53tolstoyYou can also return other things, like a map: {:body "<h1>..." :content-type "text/xml"} I think.
18:53qedi wish there were more docs
18:53qedi shouldnt probably even be using it without docs
18:53tolstoyhttp://groups.google.com/group/compojure/browse_thread/thread/3c507da23540da6e
18:54tolstoyTry that one. Seems to cover things pretty well, all told.
18:54qedcool ty
18:58PrinceOfAare there clojure equivalents for foldLeft and foldRight?
19:02liebkePrinceOfA: reduce is left fold
19:03PrinceOfAliebke: ok thx
19:03PrinceOfAi guess right fold would be reduce with reverse?
19:05tomojnot quite
19:06tomojyou'd have to also wrap the function argument to switch the order of its arguments, I think
19:14lghtngis there much interest in RDF for Clojure, yet?
19:16tomoj,(letfn [(foldr [fun val coll] (reduce #(fun %2 %1) val (reverse coll)))] (foldr cons nil '(1 2 3)))
19:16clojurebot(1 2 3)
19:22qedi cleaned up that ugly compojure tutorial doc
19:33qedanyone want a proper copy?
19:33qedw/ syntax hilighting and such
19:34tomojqed: sure!
19:34tomojguess it's out of date some now, though, huh?
19:34qedyeah i believe so
19:34qeddo you think i should put it online?
19:34qedit'd be easier that way for you to see the css and such
19:35qedotherwise youll need that too :)
19:35tomojis it just one file? gist?
19:36qedyeah i can do that too i guess
19:37qed1sec
19:39tomojI'm not sure how to proceed :/. on the one hand, clojure is beautiful, and I like compojure and enlive. on the other, erlang has webmachine which looks awesome, but as far as I can tell has nothing like enlive (and if it did, I think it would be ugly).
19:40the-kennyGoogle AppEngine would be perfect, if they would allow agents and such things.
19:40tomojdo they block you from making new threads?
19:41the-kennytomoj: Something like this.
19:44qedtomoj: http://gist.github.com/255697 <--pygmentize.css
19:44qedtomoj: http://gist.github.com/255696 --<compojure.html
19:47qedhttp://qriva.org/compojure.html
19:50the-kennytomoj: I've searched a bit and yes, you aren't allowed to create threads.
19:54tomojqed: cool, thanks!
19:57qednp
20:11qedtomoj: http://qriva.org/compojure.html it looks better now
20:11qedi added a bit more css
20:11qedokay, now that it's readable...
20:28kunleyHi!
20:29kunleyI encountered some code a while ago which was supposed to generate js from some subset of Clojure. I don't remember if it was in contrib or some bigger project like compojure.
20:30kunleyCan anyone give a clue where might it belong?
20:33the-kennykunley: It's called scriptjure
20:33the-kennyIt's on github
20:33the-kennykunley: http://github.com/arohner/scriptjure/
20:34kunleyThanks. Incidentally, I just found it via HackerNews in a recent discussion.
20:36kunleyBtw, the-kenny: thanks for your clojure-couchdb bugfix notice. I didn't have time to reply yet. I may merge our stuff when I get back to a project which actually uses Couch.
20:38the-kennykunley: No problem :) I'm glad I can help.
20:41tomojalso clojurescript?
20:52qedany advice or documentation for doing a simple database with clojure?
20:52qedlike connecting to mysql
20:52qedsomething along those lines
20:53qedim open to other databases, just whatever has the most docs and is fairly easy to maneuver
20:54the-kennyqed: CouchDB is fairly easy in my opinion.
20:54qedright now im messing with clojureql
20:54qedsince it was nice and easy to plug into leiningen
20:54the-kennyIf you have DB running somewhere, you can just start without any big setup-work like setting up tables.
20:54qedah, that's nice
20:55qedlike sqlite sort of
20:55qedthe-kenny: which couchdb clojar do you recommend
20:55qedthere's ato's yours, evil-couchdb
20:56the-kennyqed: hm.. mine has some "big" modifications, like an argument to every function for the server. The other forks use a global binding *server*.
20:57gilbertleunghi everyone
20:57the-kennyqed: Clutch is nice to. You can write view-function (they are mostly equivalent to a query in sql) in clojure with it.
20:58gilbertli'm using compojure and trying to figure out how to make the server instance log to a specific file
20:58gilbertldoes anyone know how to do it ?
20:58qedthe-kenny: could you give a use-case example?
20:58qedlike from the developer end i mean
20:59qedgilbertl: no clue man, i cant tell you there's not a single mention of "log" in any of the compojure functions
21:00the-kennyqed: In couchDB, "queries" aren't created on the client, but on the server-side and are called views. A view is a javascript function which gets called for every document (like an entry in sql, but without a predefined structure), and can emit the data to the view (and modify the data with the commit a bit, but these modifications are only in the view, not in the datastore itself). With clutch, you
21:00the-kennycan write these functions in clojure.
21:01the-kennyBut I've never tried clutch.
21:01qedahhh cool
21:01qedim not sure i even need a database at this point
21:31tomojqed: I think the question is, what do you want to store, and what do you want to do to it?
23:08hiredmanhttp://gist.github.com/255766
23:44tolstoyAnyone got a hint for compiling Clojure with ant? Gotta use it to fit in with some legacy. Is there a commmand line thing one can invoke from the jar to compile?
23:45tolstoyHm. clojure.lang.compile, maybe.
23:47hiredmanCompile
23:47nbuduroiHi everybody
23:47hiredmanyou can looks at the build.xml that comes with clojure
23:47tolstoyclojure.lang.Compiler.compile, I guess.
23:47hiredmanno!
23:47tolstoyhiredman: Ah, cool. I know I've seem something somewhere.
23:47hiredmanclojure.lang.Compile
23:47tolstoyOkay.
23:48nbuduroiI just have a simple question about slime
23:49nbuduroiis there a shortcut to make the repl go to the namespace of the file you're currently editing