#clojure logs

2009-09-18

00:29fulletsWhat's the equivalent of CL's find in clojure? (some #(= item %) collection)?
00:31JAS415find?
00:31fulletsThat's just for maps, no?
00:32JAS415what do you want to do with it?
00:32JAS415you just want to filter the collection?
00:32JAS415or you want to get an index or something?
00:34JAS415you could try filter
00:36JAS415you can do .indexOf
00:36JAS415at least on vectors
00:36JAS415,(.indexOf [1 2 3 4 5 6] 4)
00:36clojurebot3
00:36JAS415i think index of is closest yes
00:37hiredman,(find [1 2 3 4 5 6] 4)
00:37clojurebot[4 5]
00:37hiredmanhmm
00:37hiredmaninteresting
00:37hiredman,(doc find)
00:37clojurebot"([map key]); Returns the map entry for key, or nil if key not present."
00:37JAS415kind of like an assoc list
00:40arbscht,(doc clojure.contrib.seq-utils/find-first)
00:40clojurebotPardon?
00:40arbscht,(doc find-first)
00:40clojurebot"clojure.contrib.seq-utils/find-first;[[pred coll]]; Returns the first item of coll for which (pred item) returns logical true. Consumes sequences up to the first match, will consume the entire sequence and return nil if no match is found."
00:40arbscht,(doc positions)
00:40clojurebot"clojure.contrib.seq-utils/positions;[[pred coll]]; Returns a lazy sequence containing the positions at which pred is true for items in coll."
00:41somniumgetting null pointer exception trying to serve static files via compojure, anyone who might be able to help?
00:41hiredman,(use 'clojure.contrib.seq-utils)
00:41clojurebotnil
00:42arbschtsomnium: sure. you might want to ask in #compojure though :)
00:42hiredman,(find-first (partial (comp = key) :a) {:a 1 :b 2})
00:42somniumah, didn't know it existed
00:42clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: core$key
00:43hiredman,(find-first (comp (partial = :a) key) {:a 1 :b 2})
00:43clojurebot[:a 1]
00:43somniumarbscht: well, since you seem helpful and knowledgeable, it serves the template defined in the file ok, but throws an exception looking for static files, so something is wonky
00:44somniumrunning (start-server) from slime, don't know if that affects things
00:44arbschtsomnium: can you paste your code?
00:45hiredman:D
00:46hiredman,((partial find-first (comp (partial = :a) key)) {:a 1 :b 2})
00:46clojurebot[:a 1]
00:46arbschtbrought to you by the department of redundancy department :p
00:55hiredman,((comp (partial apply find-first) (partial (flip update-in) (comp (partial apply comp) reverse (partial list key)) [0]) (partial (flip update-in) (partial partial =) [0]) vector) :a {:a 1 :b 2})
00:55clojurebot[:a 1]
00:55hiredmantoo bad flip isn't in core
00:56somniumarbscht: okay, in the act of pasting it I found a typo that was probably causing the null pointer, now I'm getting a 404 so its some improvement
00:56JAS415i like the one where the guy does church calculus in clojure
00:56arbschtsomnium: great
00:56hiredmanactually
00:57hiredman,((comp (partial apply find-first) (partial (flip update-in) (comp (partial apply comp) reverse (partial list key) (partial partial =)) [0]) vector) :a {:a 1 :b 2})
00:57clojurebot[:a 1]
00:58hiredmanremoves the second update-in, because you can just compose the update-in functions
00:59lisppaste8somnium pasted "compojure" at http://paste.lisp.org/display/87269
01:01somniumnm, finally got it
01:03somniummy typo led me to screw with my paths...they were right to begin with. thanks for your help arbscht :-)
01:03arbschtsomnium: no problem
01:17danlarkinrhickey: Hey Rich, four of us clojure guys were in seattle this week hacking and we heard you spoke at microsoft earlier in the week
01:17rhickeydanlarkin: yes, I was there Tuesday
01:18rhickeyI did a talk and an interview for their Channel 9
01:18dysingerwhat would M$ want with clojure ? we are curious :D
01:19hiredmanthere are a lot of haskell guys in MS research
01:19hiredmanand they have that STM project for .NET
01:20dysingerneat
01:20MakoryuMS figured out pretty early that Java was a bad idea, so they made a point internally to stop copying Java and start copying (and funding!) functional languages
01:20danlarkinrhickey: we were bummed that you didn't come hang out with us :-D
01:21rhickeydanlarkin: I was only in town for one evening and the day and was booked up - it would have been fun to get together
01:22rhickeydysinger: They have a monthly talk in the languages group and have invited speakers. They invited me and were very gracious hosts.
01:23dysingerawesome
01:26danlarkinrhickey: we understand... next time, though!
01:27danlarkinwe won't be so understanding again
01:28dysinger:) lol
01:29dysingerrhickey: we did have an awesome team-sonian week in Seattle pair programming (technomancy, gjahad, dysinger & danlarkin)
01:29rhickeydysinger: cool
01:32rhickeykeynote went well today, slides are here: http://wiki.jvmlangsummit.com/Clojure_Keynote
01:32rhickeydirectly: http://wiki.jvmlangsummit.com/images/a/ab/HickeyJVMSummit2009.pdf
01:33travisbradyrhickey: is there video anywhere?
01:33rhickeytravisbrady: not yet, as far as I know
01:33travisbradyok, i'll keep an eye out
01:34rhickeythat may end up being an InfoQ thing, so many months away
01:34hiredmanthere is a vidoe of the last 3 minutes on youtube
01:34Makoryurhickey: I like these slides
01:35dnolenrhickey: very inspiring slides! i posted it on Hacker News people seem to be digging it there.
01:35rhickeyMakoryu: It could be a bit hard to get the full ideas behind the talk from the slides
01:35Makoryurhickey: I know :(
01:36rhickeydnolen: I saw that, thanks
01:42cgrandrhickey: inspiring slides indeed!
01:59JAS415I'm pleased that there are Whitehead quotes sprinkled throughout those slides
03:02LauJensenGood morning gents
03:14cgrandmorning Lau!
03:33sgtarrhowdy
03:33sgtarr(+ 1234 567)
03:33clojurebot*suffusion of yellow*
03:33sgtarrerr
04:23pixelmanshould I look for native clojure methods to do string operations or just go for (. message toLowerCase) or (. message beginsWith "foo") ?
04:24hiredman(.toLowerCase message)
04:24hiredman(.beginsWith message "foo")
04:25pixelmanthanks!
04:25pixelmanthat's simpler :)
04:26hiredmanstatic methods are (Class/method args)
04:26hiredman,(Class/forName "String")
04:26clojurebotjava.lang.ClassNotFoundException: String
04:26hiredmanbah
04:27hiredman,(Class/forName "java.lang.String")
04:27clojurebotjava.lang.String
04:42licoresse...
04:43adityoare there any other alternatives to clojure.contrib.zip-filter.xml to query the parsed xml from clojure.xml/parse?
04:44Chousukewell, it's just a map so you can of course access it directly :)
04:44pixelmanI cant find how to make a regexp case insensitive other than writing it in the regexp (re-find #"foo|FOO" message)
04:46hiredman,(re-find #"(?i)foo" "FOO")
04:46clojurebot"FOO"
04:46hiredman,(re-find #"(?i)foo" "FoO")
04:46clojurebot"FoO"
04:46pixelmanthanks!
04:46Chousukepixelman: http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html :)
04:47pixelmanthanks! I did not know about the special constructs in java. I've always used the constants option to regexp!
04:53mtdanyone know of good discussion behind http://wiki.jvmlangsummit.com/Clojure_Keynote 's statement that "Static/Dynamic typing" is "not so different"? Seems an unusual thing to say.
04:56mtd(s/"not so different"/"superficial differences"/, sorry)
05:07Chousukemtd: where does it say that?
05:08Chousukemtd: you mean the statement in the "background" section?
05:09pixelmanis there a more clojure variant of (Integer/valueOf "1") (int "1") doesn't seem to do the trick
05:09Chousukenope. use the java method
05:09mtdChousuke: yes..."Not so Different -> Differences are superficial -> Static/Dynamic typing".
05:09pixelmanok!
05:10mtdChousuke: was it not meant to be interpreted as "static/dynamic typing is a difference that's superficial and at the level of semicolons/indentation"?
05:10ChousukeI don't even see where it mentions typing at all.
05:10mtdChousuke: I admit I was nodding along with the presentation until I was hit by that bullet and stunned for a second.
05:11mtdChousuke: it's a great presentation overall :)
05:11Chousukebut yeah, I don't think he meant that.
05:11Chousukethough usually static vs. dynamic typing really only changes *when* the typing happens rather than based on what
05:11mtdChousuke: ah, ok.
05:11Chousukeso it's not that big a change, fundamentally :P
05:12mtdChousuke: I guess I can only speak from a pragmatist perspective, and say "with mature java and python source code trees in front of you, it sure seems to matter a lot"
05:12mtdChousuke: but yeah theoretically I can see your point :)
05:13Chousukeand you have to admit that most languages are simply clones of each other :P
05:13ChousukeC# and Java for example. the differences aren't *that* big :)
05:18mtdChousuke: I have no argument with that as a casual statement :).
05:18licoressereligiously, the diff. is great
05:18adityowhats the diff between xml-seq and clojure.zip/xml-zip
05:18vyI use http://pastebin.com/d7f205d67 file as my clojure launcher script and while there exists clojure-contrib.jar in the given path, in the REPL, (use clojure.contrib.str-utils) throws a ClassNotFoundException. Any ideas?
05:20licoresse'
05:20vyPerfect!
06:25rafsoakenstarter question: why does (take 10 (iterate #([(last %) (reduce + %)]) [1 1])) give me an IllegalArgumentException ?
06:26JAS415,(doc iterate)
06:26clojurebot"([f x]); Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects"
06:27JAS415,(take 10 (iterate #([(last %) (reduce + %)]) [1 1]))
06:27clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: LazilyPersistentVector
06:27jdzthe anonymous function is wrong
06:27jdzthe first thing in #( must be a function
06:28JAS415,(take 10 (iterate #([(last %) (apply + %)]) [1 1]))
06:28clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: LazilyPersistentVector
06:28JAS415right
06:29jdzwell, anything that implements IFn or something
06:29jdzin this case it is being given a vector, which is fine
06:29jdzbut then, no arguments are passed to it, and generally it's not what rafsoaken wants
06:30JAS415,(take 10 (iterate #(vector (last %) (apply + %)) [1 1]))
06:30clojurebot([1 1] [1 2] [2 3] [3 5] [5 8] [8 13] [13 21] [21 34] [34 55] [55 89])
06:30JAS415i think vector the fn rather than vector the data-structure
06:32jdz,(take 10 (iterate (fn [[a b]] [b (+ a b)]) [1 1]))
06:32clojurebot([1 1] [1 2] [2 3] [3 5] [5 8] [8 13] [13 21] [21 34] [34 55] [55 89])
06:33jdz#() is not always shorter
06:34rafsoakenthanks jdz and JAS415, I see some light there, although I didnt entirely understand the difference
06:34jdz,([:x :y :z] 2)
06:34clojurebot:z
06:34rafsoakeni also like the unpacking of arguments..
06:35jdzvectors can be called like functions, too
06:35jdzand that's what you were doing, originally
06:35rafsoakenahhhh, now i got it! thx a lot!
06:56spuzhello, I was asking yesterday how to compile and run a clojure program with the ClojureBox package. However, when I type Ctrl-C Ctrl-K it simply says "Compiling c:\clojure\celcius.clj..." and does nothing...
06:56spuzThis program is taken from here by the way: http://clojure.org/jvm_hosted
06:57spuzany idea what i
06:57spuz'm doing wrong...?
07:09jdzdon't know about clojurebox, but works for me without it.
07:11spuzI can use the normal java -cp clojure.jar etc. method, just trying to setup a proper editor though.
07:12spuzClojureBox uses emacs+SLIME and that's what I can't seem to get my head around
07:22spuzClojureBox uses emacs+SLIME and that's what I can't seem to get my head around
07:22spuzwhoops, wrong window...
07:43crioshi
07:48cgrandcrios: hi
08:01criosFYI: http://bestinclass.wordpress.com/2009/09/17/scala-vs-clojure-round-2-concurrency/
08:04LauJensencrios: Did you like it ?
08:05ambientinteresting article
08:05criosinteresting comparison, for a newbe on Clojure like me
08:06ambienti find it amusing how emotionally charged some programming discussions can get
08:06LauJensenambient: I find that very tedious :)
08:06ambientamusing is better for my mental health :p
08:06LauJensenTrue - I'm glad you both liked it
08:07criosThe author is... /Lau
08:07criosmmm :)
08:07LauJensenThat's me
08:07criosI was guessing it
08:10criosI found amusing this sentence: "If your team is not able to adobt and fully appreciate Clojure in all it’s aspects I would not hesitate a moment in recommending Scala"
08:10crioshow do you know if the team is Clojure-compliant?
08:10LauJensenYea, did you see I got quote of the week on ycombinator? :) For my remark on Static typing having it's place
08:10ambientwell in Clojure the functional style is the only way to do things properly, afaict
08:10LauJensencrios thats a management issue :)
08:11criosAre you meaning that the team should already know a functional language, in order to adopt Clojure ?
08:12ambientit certainly would shorten the time required to grok it
08:12LauJensenNo - If the average IQ in the room is above 120 and the lowest IQ is > 110, then you should give it a whirl
08:12ambientbut im a noob, so my knowledge of this is very limited
08:12ambienti do well in IQ tests but dont do so well in clojure D:
08:13LauJensenambient: Then just give it some time and read cgrands blog, you'll get in shape in no time
08:13ambientdo i have to use monads for stuff?
08:13LauJensenWell, I never do :)
08:13ambientwhat is the idiomatic way of doing side effect-y stuff?
08:13jdzambient: you just do it
08:14jdzambient: you just have to be careful about it, and the consequences
08:14jdzambient: for instance, doing logging in the wrong place may log the same thing more than once
08:14LauJensenhehe, there should be NO idiomatic way for doing that :)
08:18criosLauJensen: about the IQ: what if an average Java team IQ is lower < 80?
08:18criosjust joking :)
08:19ambienthmm, i dont have cgrands blog bookmarked, got link?
08:19kunleyHi.
08:20AWizzArdCompojure users: can I force to return html error codes? For example, if someone gave a wrong user/pass during Basic Auth, then I want to return 403 Forbidden
08:20kunleyWhat's the idiomatic way of serializing Clojure stuff? Say I don't need to store Java objects, just Clojure immutables.
08:21kunleyThink sth as easy as Erlang's term_to_binary
08:21cgrandambient: clj-me.blogspot.com
08:22ambientcgrand thanks
08:24LauJensencrios, I was actually considering answering that as a blogpost, but I'm afraid people will get offended
08:25ambientone shouldn't worry about people who get offended by impassionate rational arguments
08:25ambienti mean dispassionate
08:28cgrandkunley: pr and read
08:30FossiAWizzArd: return [401]
08:30cgrandif you want to serialize to something more compact, pipe it through a GZIPOutputStream
08:31criosLauJensen: sure people will get offended if you discard their IQs :)
08:31kunleycgrand: just checked, but it doesn't work for lambdas
08:32kunleycgrand: or does when i write to real stream instead of a terminal?
08:32cgrandno it doesn't work with closures
08:33AWizzArdFossi: I have a (GET "/fossi" (return [401])) but when I visit /fossi I see only a blank page.
08:34kunleyf
08:35kunleyoops. Anyway is it possible/easy to store a portable representation of a closure? Assume we lost its source forms and we only have a compiled closure
08:38criosfrom the mailinglist: http://www.azulsystems.com/events/javaone_2009/session/2009_J1_JVMLang.pdf
08:40cgrandkunley: possible yes, easy no. eg: terracotta does it under the hood
08:40FossiAWizzArd: for authentification you also have to return a WWW-Authentificate header field with a challenge
08:40Fossitry returning something more visible like 500
08:41FossiAWizzArd: also "return" was just me saying that you should return it, not using "return" in the code
08:56kunleycgrand: will check that underhood then. I lost a track what's going on in the Java world in a couple of days. Now when it's easy to marry FP with JVM, there's lots of new stuff discovering on the way.
08:57kunleycgrand: s/days/for years/. Huh time for coffee ;)
09:39criosin a word, what is the exact sequence from text to executable code? reader -> compiler (to byte code) -> jit ?
09:39manic12just one word?
09:40criosthree ;)
09:40crioswell just an overview
09:41criosthe APIs name also a "loader"
09:42manic12read compile [link] run[on runtime possibly with jit]?
09:42knoboIs it possible to load clojure-swank through beanshell?
09:42knoboI don't know so much about Java and beanshell and stuff like that..
09:44jdzwhat's beanshell?
09:44manic12i dunno what beanshell is but as long as swank loads and it doesn't take the swank/slime ports it should work
09:46knobosorry I'm a bit foggy today. I mean to load just clojure, not swank
09:47knoboAs logn as I can load clojure, I could start swank from there
09:47manic12I have successfully made some clojure code look like C
09:47manic12isn't that wonderful?
09:47knoboI can also make diamonds look like sh..t
09:47knobo:p
09:48knobomanic12: what do you mean? and why is that wonderful?
09:49manic12i have to either rewrite a large and highly mathematical library in a lisp or the ff calls make the program look like a c program
09:49knobojdz: http://www.beanshell.org/
09:50jdzknobo: why do you want beanshell if you got Clojure?
09:50manic12it passes lots of double float arrays by value and also does a lot of `&' and `*&'
09:50knobojdz: I want to boot clojure from beanshell
09:51manic12looks like beanshell has it's own repl
09:51manic12gotta pick one or the other or take the source of both and write your own
09:53manic12i'm sure if you take compiled clojure code you can call it from bean shell just like any jvm program
09:53manic12but i agree with jdz, porque?
09:57knoboI'm thinking it would be easy to add support for making extension clojure for openoffice.org if I could load and boot clojure from beanshell
09:57knoboas openoffice.org has support for beanshell
09:58jdzknobo: well, you have clojure.jar, don't you?
09:58manic12I am sure you can make an extension for openoffice without beanshell just with clojure
09:58knobomanic12: yes, that should also be possible
09:58manic12i once made a plugin for excel out of allegrocl
09:58clojurebotfor is a loop...in Java
10:00manic12i am sure clojure & open office would be even easier
10:03knobojust use this recipes http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Scripting/Writing_a_LanguageScriptProvider_UNO_Component_using_the_Java_Helper_Classes
10:05knoboI would have to learn java, then..
10:08manic12java is easy enough to stumble through if you know any other languages
10:37pixelmanomg the java interop JUST WORKS LIKE A CHARM!!!!!!!!!!! :)
10:37pixelmanone (.. to rule them all!
10:39AWizzArd~max people
10:39clojurebotmax people is 164
10:43cgrandpixelman: no, -> beats ..
10:44pixelmanwhat do you mean ->?
10:46Chouser(doc ->)
10:46clojurebot"([x form] [x form & more]); Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc."
10:48pixelmanwow
10:50pixelmanfirst day coding with clojure, but I've managed to build a pretty decent website with compojure and mysql connectivity, a full test suite, and I can leverage all the java libraries we have. I'm hooked :)
10:55shooverpixelman: Nice work! Testing with clojure.test?
10:55pixelmanyep!
10:56pixelmantnx
10:57pixelmanthe only thing that's left is getting at the User-Agent header in compojure - I need to do some browser sniffing for mobiles
11:16weissji am trying to play around with error-kit and getting this message: java.io.FileNotFoundException: Could not locate clojure/stacktrace__init.class or clojure/stacktrace.clj on classpath: (error_kit.clj:0)
11:17weissji assume this is because my contrib isn't meant to be used with clojure-1.0.0.jar?
11:17Fossii've had a similar problem and updating everything (clojure & contrib) helped
11:17weissjso 2 questions - is there a good doc or example for error-kit (besides halloway's log file parse example) and what versions of clojure/contrib do you recommend
11:17stuartsierraweissj: yes, that's it
11:18weissjshould i just build my own clojure.jar then?
11:18weissjor is there something more stable than HEAD and less stable than 1.0.0?
11:19Fossilatest-greatest from git worked for us so far
11:19weissjk
11:19Fossithings tend to be really stable since most (major) development is done in branches anyway
11:19weissjFossi: right
11:20weissjjust wasn't sure if merges were synced with contrib or not
11:20stuartsierrano, no sync
11:22weissjanyone have hints what to read to understand error-kit?
11:22weissjbesides source :)
11:25cgrandweissj: I think stuart halloway wrote something about error-kit
11:27cgrandweissj: http://www.pragprog.com/magazines/download/1.pdf
11:27weissjcgrand yeah i read that already
11:29weissjhere's my problem, i have web UI testing program that moves thru the app, doing various tasks. the app (when there's a problem) puts up a red error bar. some of my tests *expect* an error bar, but I need to handle this error just on the page where it's expected.
11:29weissjso i can define a red-error-bar error, but i need a way to let the caller specify where he expects to see it
11:41criosthe private function legacy-repl in main.clj starts the real REPL ?
11:44criosthe commet says: "Called by the clojure.lang.Script.main stub to run a script"
11:44crios*comment
11:45criospardon: "called by the clojure.lang.Repl.main stub to run a repl"
11:45Chouserweissj: with-handler ?
11:46weissjChouser: and then how does the low-level callee unwind the stack to let the high level caller give the thumbs up on the expected error, and move on to the next test?
11:47Chouserweissj: I'm not sure I understand what you're saying. did you see the examples at the end and Halloway's writeup?
11:49criosah ok, legacy-repl in the end calls the repl function
11:50weissjChouser: yeah, but that's not quite what i'm trying to do. In java terms, i have a "RedErrorBarException" that can get thrown in 10 different places in a complex method, including methods it calls, etc. But my caller wants to know which of those 10 places threw it. becuase 9/10 of them are a problem, but the other 1 isn't.
11:51weissjnow, it doesn't need to figure this out by the stack trace, in java maybe i'd have a field in the exception with an enum value or something. but this is a crazy way to do this
11:51Chouserthe site that raise the exception have to somehow indicate which they are. Does CL provide something different?
11:51weissjChouser: i'm much more of a newb in CL than clojure :)
11:51Chouseroh, ok.
11:52Chouserso how do you *want* it to work?
11:52Chouserif not figuring out based on stack trace, what should it use?
11:53weissjChouser: well, it basically works in java when i put a field in the exception class. the caller catches that exception class, examines the contents, and if it is not a match, rethrows it. but i want to avoid the catch/rethrow
11:53weissjand just have it catch when there's a match.
11:54Chouserah. why do you want to avoid the rethrow?
11:54weissjwell, i want to avoid catching stuff that's not meant to be caught
11:55weissjjava only lets you catch by exception type
11:55Chouserok, I think you can do this.
11:55Chouserraise with some flag indicating which kind of raise it is, right?
11:56weissjChouser: yeah
11:56Chouserthen in your handler, check the flag -- if you really want to throw something, throw a new exception that's not being handled.
11:57Chouserotherwise do a continue-with
11:58weissjChouser: perhaps another way is to just have different error types. the reason i don't do that in java is because i'd end up with 8000 different exception types, but maybe in clojure the error types are cheaper (in terms of LOC at least)
12:00weissjto restate the problem, the caller says "try this procedure, which can throw 'not-found-error' in lots of places, but i want to make sure the thing that wasn't found is the thing i am working with, not some other low level thing that i know nothing about'
12:09weissjChouser: what is the args-destruct-map of deferror? it has something to do with raise only being able to take 1 arg?
12:11Chousergah, so much complexity. I really need to figure out what can be torn out of there.
12:11Chouserlooks like deferror can take either a vector of args or a map of args.
12:12ChouserI can't even think at the moment how you'd use the map version. but you can specify a vector of arg names in deferror, and a matching list of values in raise.
12:13duncanmsigh, i have to write Java code (and not clojure right now), but is there a method like 'map' in Java's collection library?
12:19Makoryuduncanm: No.
12:22Makoryuduncanm: Imagine for a moment what that would look like, actually.
12:23MakoryuThere would be, at a minimum, a multiparameter generic interface or abstract class describing the type of the function you'd be calling, with some arbitrary name for calling it.
12:24ChousukeFunctionalTools.map(new UnaryFunction() { public void invoke(Object o) { o.whatever(); ... } }); ? :P
12:24MakoryuPretty much.
12:25Chouserreturns an object not void, right? maybe should be generic...
12:25Chousukehmm, right.
12:25Chousukein any case, too horrible to actually use :)
12:32stuartsierraChousuke: that exists, it's called Functional Java http://functionaljava.org/
13:20dthomasWhat's the difference between clojure.contrib.greatest-least/greatest-by and the core function max-key?
13:21hiredman,(doc max-key)
13:21clojurebot"([k x] [k x y] [k x y & more]); Returns the x for which (k x), a number, is greatest."
13:21hiredman,(doc greatest-by)
13:21clojurebot"clojure.contrib.greatest-least/greatest-by;[[f & args]]; Return the argument for which f yields the greatest value."
13:21Chousukehm
13:21dthomasMaybe the difference there is "number" vs. "value"?
13:52crios_what is the function which unmap a symbol from a Var object?
13:52Chousukens-unmap? :)
13:53crios_mmm :)
13:54crios_thank you
14:17ambienthmm, arity based dispatching is supposed to be a good way to introduce helper functions in clojure, but wouldn't scheme's way of doing things with putting function definitions inside function definitions be better?
14:18ambientlike (defn foo [x] (defn bar [y] (+ y 1)) (bar x))
14:18hiredmanyou can, using letfn or plain let
14:18hiredman:||
14:18hiredmandon't do that
14:18ambientwhy?
14:18hiredmandef, defn, defmacro, etc
14:19hiredmanthey create global bindings of names to vars
14:19ambientaaaa..
14:19ambientso its not lexically scoped?
14:19hiredmanclojurebot: clojure is also not scheme
14:19clojurebotRoger.
14:19ambient:p
14:19hiredmanif you want lexical scope, use let or letfn
14:19ambientok
14:19hiredmanclojurebot: what is clojure?
14:19clojurebotclojure is a very attractive hammer with a nice heft to it
14:31deafmacrohello, I would appreciate it if someone could explain how to use 'constantly'. I have looked at the example on the site but could not think of real world scenario for it.
14:32ambientwell if my doctor is going to tell me to say "a" i shall write (constantly \a) ;)
14:32ambientand he can then take as many as he likes
14:32hiredmanit can be useful because the mutation functions for atoms, refs, and agents all take a function
14:32hiredman,(send-off (agent 0) (constantly 1))
14:32clojurebot#<Agent@4aca27: 0>
14:33hiredman,(let [a (send-off (agent 0) (constantly 1))] @a)
14:33clojurebot0
14:33hiredmanbah
14:33hiredman,(let [a (send-off (agent 0) (constantly 1))] (await a) @a)
14:33clojurebot1
14:33hiredman,(doc await)
14:33clojurebot"([& agents]); Blocks the current thread (indefinitely!) until all actions dispatched thus far, from this thread or agent, to the agent(s) have occurred."
14:34Chouserit doesn't get used a whole lot. You could say #(do 1) instead, but 'constantly' may be a bit clearer.
14:34hiredmanhmmm
14:34hiredmanChouser: #(do 1) takes no args
14:34Chouserah, good point!
14:34hiredmanwhat does await return?
14:34Chouser#(do %& 1)
14:34Chouseryuck
14:34deafmacrohiredman: didn't quite get it. from what ambient said it seems like some lazy thingy
14:34hiredman,(await (agent 1))
14:34clojurebotnil
14:35ambientignore me
14:35Chouserdeafmacro: 'constantly' just returns a function. that's it. Other things that return a function are the (fn ...) form and the #(...) form
14:35hiredmandeafmacro: if you had an agent A how would you set its value to 1
14:35deafmacroah
14:36deafmacroI get the picture
14:36deafmacroinstead of writing (fn [x] x) I can you constantly
14:36Chouseralmost
14:36Chouserwhat you wrote there is actually called 'identity'
14:37hiredmanconstantly is more like (fn [& x] 1)
14:37Chouser'constantly' is more like (fn [x y z & etc] 5)
14:38hiredman(fn [x] (fn [& y] x))
14:38Chouserheh
14:38hiredman(((fn [x] (fn [& y] x)) 1) :foo :bar :baz)
14:38hiredman,(((fn [x] (fn [& y] x)) 1) :foo :bar :baz)
14:38clojurebot1
14:40deafmacroah so is it basically like writing a function to return a function?
14:40hiredmanconstantly is a function that returns a function
14:40Chouser,(((((fn [x] (fn [] x)) (fn [] (fn [x] x))))) 5)
14:40clojurebot5
14:40Chousukewhoa, that's some paren soup :P
14:40Chouserthat, on the other hand, is just nonsense.
14:41Chouser:-)
14:41hiredman,(#(% %) #(% %))
14:41clojurebotjava.lang.StackOverflowError
14:41deafmacromy head is spinning looking at that :)
14:41Chouserdon't look at mine. It's nothing.
14:41hiredman~def constantly
14:41hiredmanclojurebot: well?
14:41clojurebotI don't understand.
14:41Chouseractually, it's 'identitiy'
14:41Chouseridentity
14:41hiredmanclojurebot: well?
14:41clojurebotexcusez-moi
14:41hiredman~def constantly
14:41wtetzner,(doc identity)
14:41clojurebot"([x]); Returns its argument."
14:42wtetzner,(doc constantly)
14:42clojurebot"([x]); Returns a function that takes any number of arguments and returns x."
14:43hiredmanugh
14:44deafmacroI still dont see the point. pardon me. let me ruminate over this for a while and get back
14:44Chouserdeafmacro: really, 'constantly' is hardly ever used.
14:44Chouser,(map (constantly 5) (range 10))
14:44clojurebot(5 5 5 5 5 5 5 5 5 5)
14:45Chousukedeafmacro: the point is that some higher-order functions take other functions as parameter and constantly is a good way to give a "constant"
14:45Chouser,(repeat 5 10)
14:45clojurebot(10 10 10 10 10)
14:45Chouser,(repeat 10 5)
14:45clojurebot(5 5 5 5 5 5 5 5 5 5)
14:45deafmacroah the higher order function thing made sense :)
14:46ambient(take 5 (whats-this? 10)) => [10 10 10 10 10] ?
14:46Chouserambient: repeat
14:46Chouser,(take 5 (repeat 10))
14:46clojurebot(10 10 10 10 10)
14:46Chousuke,(let [a (atom 1)] (println "atom is " @a) (swap! a (constantly 2)) (println "atom is " @a))
14:46clojurebotatom is 1 atom is 2
14:46ambientoh, it works like that too
14:46Chouserambient: yeah, there used to be 'repeat' and 'repeatedly', but that just ended up seeming kinda silly
14:47Chousuke(doc repeatedly)
14:47clojurebot"([f]); Takes a function of no args, presumably with side effects, and returns an infinite lazy sequence of calls to it"
14:47Chousukerepeatedly is different. :)
14:47Chousuke(take 5 (repeatedly rand-int)
14:47Chousuke,(take 5 (repeatedly rand-int))
14:47clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: core$rand-int
14:47Chousukehm, damn
14:47ambient(repeat 5) broke my repl :(
14:48Chousukewell, you tried to print an infinite seq :)
14:48Chouserambient: (set! *print-length* 103)
14:48ambientright...
14:48ChouserChousuke: you're right. what was I thinking of?
14:48Chouserreplicate!
14:49ambienthmm, exterminate
14:49ambientno such symbol :(
14:49Chouserrepeat has subsumed replicate -- repeatedly is indeed different.
14:50deafmacroambient, Chouser, hiredman : thanks!
14:50Chouser,(take 10 (iterate (constantly 5) nil))
14:50clojurebot(nil 5 5 5 5 5 5 5 5 5)
14:50Chouserhm
14:51ambientit seems iterate doesnt apply the function to the first value
14:51Chouser(take 10 (cons nil (repeat %)))
14:51Chouserambient: right.
14:54hiredman3
15:02hiredmanclojurebot: egal?
15:02clojurebotI don't understand.
15:02hiredmanclojurebot: egal is http://home.pipeline.com/~hbaker1/ObjectIdentity.html
15:02clojurebotOk.
15:11hiredman~def =
15:12hiredmanclojurebot: why do you treat me so?
15:12clojurebothttp://clojure.org/rationale
15:12hiredman$%@#$
15:13Chousuke:P
15:14hiredman~def =
15:14hiredman~def =
15:14hiredmanhmmm
15:14hiredmanwhoops
15:18hiredman~def =
15:20hiredman~def clojure.lang.Util
16:21stuartsierraUpdated Clojure-Hadoop with custom readers/writers. http://github.com/stuartsierra/clojure-hadoop
16:37ordnungswidrig1Can anybody enlighten me about multimethod dispatching on a keyword hierachy? I'd like to use sth. like (draw :rect 1 2) and (draw :ellipse 1 2) where :rect and :ellipse are of type :shape and there is a method instance (draw :shape) which shall be the fallback if no method was declared for a certain sub type
16:37stuartsierraWell, you (defmethod :rect...) (defmethod :shape ...) etc.
16:38dnolen,(doc derive)
16:38stuartsierraThen (derive :rect :shape)
16:38clojurebot"([tag parent] [h tag parent]); Establishes a parent/child relationship between parent and tag. Parent must be a namespace-qualified symbol or keyword and child can be either a namespace-qualified symbol or keyword or a class. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to, and modifies, the global hierarchy."
16:38stuartsierraBut you'll have to use namespaced keywords, like ::rect and ::shape
16:40Chouserand defmethod needs a method name (defmulti draw ...) (defmethod draw ::rect ...)
16:40dnolen,(isa? (derive ::rect ::shape) ::shape)
16:40clojurebotfalse
16:40Chouserbut yes, 'derive' is the key
16:40Chouser,(derive ::rect ::shape)
16:40clojurebotnil
16:40Chouser,(isa? ::rect ::shape)
16:40clojurebottrue
16:41Chouser,(isa? ::dnolan ::shape)
16:41clojurebotfalse
16:41dnolen,(do (derive ::rect ::shape) (isa? ::rect ::shape))
16:41clojurebottrue
16:41dnolenheh :) it's good to be a shape
16:41Chousukenote that hierarchies are completely separate from multimethods
16:41Chousukethat is, you can use them for your own purpose as well
16:41Chouserdnolen: derive modifies (yes, mutates!) a global hierarchy -- no need to scope it with 'do'
16:42dnolenChouser: yeah, but derive doesn't return the tag, returns nil right?
16:42ordnungswidrig1why namespace keywords?
16:42Chousukeordnungswidrig1: to avoid collisions
16:42ordnungswidrigok, I will try
16:43dnolenordnungswidrig: so that code in other namespaces can extend your multimethods
16:43ordnungswidrigdnolen: I see
16:43ordnungswidrigI'll talk to my repl now :-)
16:45Chouserdnolen: yes
16:47ordnungswidrigHow must I use defmulti?
16:47ordnungswidrig(defmulti draw) ?
16:49dnolenordnungswidrig: http://clojure.org/multimethods, look at the example at the bottom of the page.
16:52ordnungswidrigdnolen: the page confuses me. the second to last example is using namespaced keywords and the last one hierachies.
16:52ordnungswidrigdnolen: but the last one decides on the value of the :Shape attribute of the record, right?
16:57stuartsierrayes
17:14ordnungswidrighttp://gist.github.com/189297
17:14ordnungswidrigWrong number of args passed to: user$fn
17:16ordnungswidrigI'll better go to bed for now. see you all
17:18hiredman(println (draw ::triangle 1 2)) <-- three args
17:19hiredman(defmethod draw ::shape [x y] "shape") <-- two args
17:43scottjAnyone know if there was a recording made of the Rich's entire JVM Summit talk this year or if it's going to be posted?
17:52hiredmanscottj: I hear yes and yes
17:53spaceman_studanlarkin: boat computing, eh? nice
17:54scottjhiredman: cool. hopefully the one where you can see everyone's heads and the camera isn't on a tripod isn't the only one :)
17:58scottjIn Rich's slides he says "parallel code needs to be declarative - no loops!" and as examples of declarative he has "map/reduce etc." What other clojure functions fall under "etc"? Is this the seq library, or more or less than that?
17:59Chousukemap, reduce, filter, whatever? :)
17:59Chousukehmm, I wonder what a whatever function would do
17:59Chousuke"spend some CPU cycles if you like, I don't really care"
18:02scottjChousuke: haha
18:04Chousukethe ultimate in declarative programming would be the do-what-i-mean function, but the implementation is tricky :/
18:08danlarkinspaceman_stu: :)
18:14beutdeucehow can I do file input in Clojure?
18:14beutdeucewhere i can read by line
18:14spaceman_studanlarkin: cool. I'm jsut across the canadian border from you guys - nice day for it
18:14danlarkinspaceman_stu: yeah it's perfect out
18:14danlarkinlast day of our seattle trip, wrapping it up now
18:17scottjbeutdeuce: line-seq maybe
18:56beutdeucehow would i be able to iterate through the elements of a lazy sequence?
18:58spaceman_stubeutdeuce: whether it's lazy won't affect consuming it really
18:59beutdeucealright, how would i be able to iterate through each element of a sequence without specifying a binding for loop
19:00hamza`hey guys, is it possible use apply to turn a [:a 1 :b 2] vector to a map {:a 1, :b 2}?
19:01spaceman_stuhamza`: (into {} (partition 2 {:a 1 :b 2}))
19:02hamza`thx i was way of, been trying (apply {} [2 3]) :)
19:03spaceman_stubeutdeuce: is something like (doseq [c your-collection] (whatev)) what you're looking for?
19:03beutdeucenot really, that is just looping, i need iteration
19:08spaceman_stubeutdeuce: why iteration? and what specifically do you mean by looping rather than iteration
19:09beutdeucenvm, i was just thinking of a map
19:09m4nicHi all, I am working with clojure regexpes and am making a parser
19:09m4nicfor org-files, for this i need an multi-line regexp. Is there a nice
19:09m4nicway, without going to java that is, to define such a regexp.
19:12hamza`(into {} (partition 2 (re-split #":" "test: asd" ))) doesn't this work for sequences?
19:15ankouhi, is there a possibility to call the method of the superclass in proxy? or what would be a better way to override the paintmethod of a swingcomponent?
19:16hamza`m4nic: you can use flags in side regex's such as (?s)
19:17beutdeuceclojure cannot apply re-seq to a lazy sequence of a string?
19:18beutdeucewhy doesnt this work
19:18beutdeuce(defn runprogram [file]
19:18beutdeuce (with-open [buffer (java.io.BufferedReader. (java.io.FileReader. file))
19:18beutdeuce lines (line-seq buffer)]
19:18beutdeuce (map #(re-seq #"\s" %1) lines)))
19:21hamza`is it possible to get a map test->asd from (re-split #":" "test: asd" )?
19:25beutdeucehow can i convert a lazy sequence to a vector?
19:26_mst,(into [] (range 5))
19:26clojurebot[0 1 2 3 4]
19:26beutdeucethnx
19:26spaceman_stuor vec
19:27spaceman_stu(vec (range 5))
19:27beutdeucehuh. No matching field found: close for class clojure.lang.LazySeq
19:27beutdeuce [Thrown class java.lang.IllegalArgumentException]
19:27_mstbeutdeuce: you don't want that call to line-seq inside the with-open
19:27beutdeuceyeah,
19:27_mstit's going to try to call .close on the resulting seq, which won't work
19:28ankouanyone?
19:29_mstankou: does proxy-super do what you want?
19:30ankoumaybe for the moment it leads to very confusing behaviour
19:31ankouokay yes, thanks
19:36hamza`is it possible to get a map test->asd from (re-split #":" "test: asd"
19:36hamza` )?
19:38_mst,(apply hash-map (re-split #": " "test: asd"))
19:38clojurebotjava.lang.Exception: Unable to resolve symbol: re-split in this context
19:38_mstah :) That sort of thing anyway
19:39hamza`got it thx alot
19:48scottjm4nic: out of curiousity, what are you going to do with the org-files?
20:21deshkannahi