#clojure logs

2010-05-16

00:00defnlespea: do you have a link to the requirements for this project?
00:00defni could try to write something and see if i have any stroke of genius
00:00defn(rare in my case, but always worth a try)
00:01lespeaI turned the warn-on-reflections on (or w/e the exact syntax is) and nothing is showing up?
00:01rhudsonlespea, the map function could just be second; #(second %) wraps an extra function call around it
00:01lespeahttp://code.google.com/codejam/contest/dashboard?c=433101#s=p2
00:01sexpbot"Qualification Round 2010: Dashboard"
00:02lespearhudson: wouldn't that just return the second item in the (take runs ...) list?
00:03defnis it too late to do the code jam lespea
00:03lespearhudson: the (take runs) returns a bunch of vectors [[2 1] [1 4] [2 5]] etc
00:03lespeadefn: I know I competed using perl since that's what I know, I'm just trying to learn clojure more
00:03rhudsonIt's that #(second %) === (fn [p] (second p)) , so map calls a function that calls second for every item
00:04defnyeah i feel like there is too much first, rest, and second going on in there, something is subtly wrong
00:06lespearhudson: oh cool didn't know you could just remove map like that
00:06lespeamaybe I should explain my logic an y'all can come up with a better way
00:07defnyeah sure, every bit helps
00:08lespeaso I have a structure like this: [[2 3][0 6][1 3]] and what I want to do is look at the first one, see the first element is a 2, return the 3 as the first item in a seq, get item seq[2], see that points to 1 and put 3 in the return seq, etc
00:09lespeaI just don't know how to return the second item every time so I return the the whole vector as each item in the sequence and then pull out the second item later
00:09lespeaso ideally the function would return (3 times) [3 3 6] whereas right now it should be [[2 3][1 3][0 6]]
00:10lespeai think the get-income-fast method probably shows my logic better
00:11defnlespea: okay, hmm
00:12defnlespea: will the length of that structure be consistent
00:12lespeawhich one? the [[2 3] etc one?
00:13defnyes
00:13lespeait won't change during the lookups (it's being setup before all the looping happens
00:13rhudsonYeah, I can see the correspondence between the two; I just don't see why get-income should be so much slower. Using (map second ....) vs (map #(second %)) is a slight inefficiency, but shouldn't make it 10 times slower
00:13lespea (let [ride-map (vec (map #(riders-for size % 0 riders)
00:13lespea (range (count riders))))]
00:13lespeaoh, no it's way slower than the loop version
00:13lespeamap second vs map #(second %) didn't make a difference really
00:15rhudsonI'd say just go with get-income-fast then. It's not actually evil to use loop/recur!
00:16rhudsonIt's actually a lot more readable than the other, aside from being a lot faster
00:16lespearhudson: okay, in the end I'm just trying to understand clojure better... I thought it was shunned upon to use loop haha
00:17lespeaI think it's pretty cool that the "lazy version" works at all honestly!
00:17lespeaI'm pretty new to functional programming :/
00:17lespeait's fun! but mentally taxing haha
00:17lespeais the way i'm doing parse-int bad?
00:17rhudsonIt seems to be frowned on when reduce (or doseq or for or whatever) gives you cleaner code, but that doesn't seem to be the case here.
00:18lespeathat's the other thing that looks "bad" to me
00:18lespearhudson: makes sense
00:19defnrhudson: can you type hint to parseInt?
00:19defnrhudson: like can you pass the final container type as an argument or hint the var or something?
00:20lespeaI just stole that code from some guys blog because I was getting angry it wasn't detecting the numbers as such like perl haha
00:20rhudsonYou mean the Integer/parseInt call?
00:20rhudsonparse-integer looks ok to me, assuming you know your numbers are going to be in range.
00:21defnlespea: this might just be superficial but...
00:21lespearhudson: yeah the string is always ints
00:22lespeasurrounded by spaces
00:22lespeathere isn't an easier way?
00:23defn,(let [ [[k k2] n n2] [[2 3][0 6][1 3]]] [k k2 n n2])
00:23clojurebot[2 3 [0 6] [1 3]]
00:24defn,(let [[[k k2] &ns] [[2 3][0 6][1 3]]] [k k2 ns])
00:24clojurebotjava.lang.Exception: Can't take value of a macro: #'clojure.core/ns
00:24defnoops
00:24defn,(let [[[k k2] & nz] [[2 3][0 6][1 3]]] [k k2 nz])
00:24clojurebot[2 3 ([0 6] [1 3])]
00:24defnack, ugly
00:24defni was thinking you could maybe set yourself up by destructuring and remove some of the stuff going on inside like the firsts and rests
00:25lespeadefn: sounds above me haha
00:26defnlespea: nah not at all, i might be misunderstanding your problem
00:26defnlespea: destructuring is your friend
00:27lespeaexamples i could read up on?
00:27seths,(map #(vec %&) [1 2] [3 4])
00:27clojurebot([1 3] [2 4])
00:28defnlespea: http://getclojure.org:8080/examples/let
00:28defnthat might take awhile to load, especially if a few people click it :X
00:28defnlots of destructuring examples in there
00:29rhudsoncould do (reduce + (take runs (for [[nxtpos money] (iterate ....)] money))
00:29technomancywho wants to maintain swank-clojure.el? take in an orphan under your wing.
00:30lespearhudson: oh that's a cool idea
00:31lespeawtf does ->> do?
00:31rhudson,(->> 3 (- 7))
00:31clojurebot4
00:32lespealost me...
00:32rhudson,(- 7 3)
00:32clojurebot4
00:32sethstechnomancy: ask again after you come back from Hawai'i :-P
00:32rhudsonIt takes the first arg (3) and makes it the last arg of the next form (- 7 ,,,)
00:33rhudson& keeps doing that for more forms
00:33rhudson,(doc ->>)
00:33clojurebot"([x form] [x form & more]); Threads the expr through the forms. Inserts x as the last 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 last item in second form, etc."
00:33technomancyheh
00:33lespeahuh that's cool, so like you can chain things together?
00:34rhudsonso you can write (--> a (b c) d e) instead of (e (d (b c a)))
00:34rhudsonsorry, ->> not -->
00:35sethstechnomancy: does swank-clojure need someone for the Clojure 1.2 release?
00:35technomancyseths: no, I'm about to push out a new release of the swank server
00:35technomancyseths: but I'm no longer maintaining swank-clojure.el
00:36sethstechnomancy: will that go to ELPA or technomancy.us?
00:36technomancythe recommended way going forward is to launch your swank server using lein or mvn and connect via raw slime
00:36sethsah
00:37technomancyseths: http://p.hagelb.org/swank-readme.html
00:37sexpbot"README.md"
00:38sethstechnomancy: that .html file is an .org file, but no -*- mode:org -*-
00:38sethsor maybe markdown
00:39technomancyseths: it's actually a markdown file that's been rendered as markdown-as-HTML
00:39technomancyseths: it's from my personal pastebin, it's not the official docs
00:40rhudson,(->> 5 range (map #(* 2 %)) (reduce +))
00:40clojurebot20
00:44defnme no likey the ->> on that expression! :D
00:46lespea,(->> 5 range (map #(* 2 %)))
00:46clojurebot(0 2 4 6 8)
00:46lespeaI don't understand whey it goes up by 2 :(
00:47lespeaooooh
00:47lespeanevermind
00:47lespeait's doing range 5 first
00:47lespeathen the map
00:47lespeacool beans
00:49technomancyOK, swank-clojure 1.2.0 is released.
00:49technomancynext up: leiningen 1.2.0 (/me gulps)
00:49technomancy(still a week or two away)
00:50defnbravo, technomancy
00:50sethstechnomancy: yay! looking forward to lein 1.2
00:50defnlespea: get it figured out?
00:51sethstechnomancy: package-list-packages shows swank-clojure 1.1, should I reconfigure it for technomancy.us?
00:51lespeadefn: yeah I think so, it's pretty neat
00:52sethslespea: technically it does map first
00:52lespeaso I was reading that java7 will have closures (officially) will that help out clojure a lot?
00:52seths,(macroexpand '(->> 5 range (map #(* 2 %))))
00:52clojurebot(map (fn* [p1__16558] (* 2 p1__16558)) (clojure.core/->> 5 range))
00:52technomancyseths: I don't think you need any new elisp to use the latest swank-clojure.
00:52technomancyjust upgrade in your project.clj
00:52sethstechnomancy: awesome, thank you
00:53technomancyseths: you can get the latest slime (20100404) from my git, and I've submitted it to ELPA, but I haven't actually put it up on technomancy.us yet
00:53technomancybut there's not a big difference
00:53lespeaseths: right, i just thought it was going (range (map #(* 2 %) 5))
00:54lespeaso does anybody else use vim for clojure programming?
00:57dakronelespea: yes, quite a few people
00:59lespeadakrone: I'm using slimv and I was wondering if there is a way to stop the .... "results buffer" from stealing focus ever time you eval a statement
01:00dakroneahh, sorry can't help, not a slimv user
01:01lespeaI tried using the other one (clojure-vim or something) but couldn't get it working in windows
01:01dakronecould you map a <c-w><c-w> to the end of it?
01:02lespeadakrone: yeah that would probably work, not sure how it'd work if it took a while... i'll test
01:03defnhow do i install to another drive from my current drive
01:07lespeadakrone: well it sorta works, just doesn't refresh the buffer if the call takes a while; don't know why i just didn't think of that haha
01:11ninjuddNetBeans is setting my hair on fire! cemerick must really hate me to trick me into proving that my patch doesn't break it...
01:12ninjuddis there anyone here who can help me set up a simple clojure netbeans platform application?
01:12rdsrIs there a way to dynamically plugin in method definitions to a class which is to be generated by "gen-class" macro?
01:13lespeaso i'm just using plain old clojure 1.1.0, am I crazy for not using the latest dev version or does it not matter too much?
01:13rdsrI'm thinking of writing a wrapper macro on top of gen-class which could add new method definitions
01:14ninjuddlespea: this is the killer new feature that's in clojure 1.2: http://clojure.org/datatypes
01:15ninjuddrdsr: it may also solve your use case
01:16rdsrSo I think I have to declare a var bound to the namespace in which the wrapper was called and create a method definition and bind it to the var
01:16ninjuddrdsr: http://clojure.org/protocols
01:16rdsrniinjudd: oh I'll havea look at it thanks
01:16ninjuddnow, can anyone help me with fucking NetBeans?
01:20_brian2_noob quetion> I'm trying to call this java in clojure twitterStream = new TwitterStreamFactory(this).getInstance() , thi doen't work > (def twitterStream ( . (new TwitterStreamFactory) getInstance ))
01:20ninjuddok, time to send hate mail to cemerick... i'm not waiting until monday
01:22rdsr_brian2_@: that looks weird to me, getInstance is a static method of TwitterStreamFactory right?
01:22rdsrrdsr: does this work hi all, is there a way I could plug in function definitions
01:22_brian2_i'm not really sure, just a sec
01:22rdsrsorry about that
01:23rdsrbrain2 : does this work ? (def twitterStream (TwitterStreamFactory/getInstance))
01:23_brian2_yea, maybe, I gues I never understood the difference
01:24_brian2_i need to open a repl
01:31ninjuddtechnomancy: let me just say, compared to NetBeans, lein is so easy
01:32ninjuddwhen oracle bought sun, they should have offered them more it the didn't include NetBeans
01:33ninjudds/it the/if they/
01:33sexpbotwhen oracle bought sun, they should have offered them more if they didn't include NetBeans
01:36ninjuddclojurebot: don't forget, NetBeans is evil, and i want you to tell people that whenever they mention it
01:36clojurebotAck. Ack.
01:37ninjuddAck Ack Indeed.
01:37brixenclojurebot: I'm thinking about using NetBeans for a project, good idea?
01:37clojurebotproject euler is http://ProjectEuler.net
01:37brixenheh
01:48_brian2_rdsr : doesn't seem to work , but I don'tknow if its a static method, at least the docs don't say it is
01:48_brian2_Click here to find out more!
01:48_brian2_ * Research Centers
01:48_brian2_ * + Core Java
01:48_brian2_ o Client-side Java
01:48_brian2_ o Design Patterns
01:48_brian2_ o Java Language
01:48_brian2_ o Java Platform APIs
01:48_brian2_ o Java Programming Concepts
01:48_brian2_ o Swing/GUI Programming
01:48_brian2_ o Threads/Concurrency
01:48defnuh oh
01:48_brian2_ * + Enterprise Java
01:48_brian2_ o Ajax/RIA/Web 2.0
01:48_brian2_ o Architecture & Scalability
01:48_brian2_ o Enterprise Best Practices
01:48_brian2_ o Java & XML
01:48_brian2_ o Java Web Development
01:48_brian2_ o Web Services & SOAs
01:49_brian2_ * + Mobile Java
01:49_brian2_ * + Tools & Methods
01:49_brian2_ o Application Servers
01:49_brian2_ o Data Management/RDBMS
01:49_brian2_ o Enterprise Middleware
01:49_brian2_ o Java IDEs
01:49_brian2_ o Java Security
01:49_brian2_ o Open Source Tools
01:49_brian2_ o Scripting/Other Languages
01:49defn_brian2_: part the channel and rejoin now please
01:49_brian2_ o Software Development Lifecycle
01:49_brian2_ o Software Development Methodologies
01:49_brian2_ o Testing & Debugging
01:49_brian2_ o Web Application Frameworks
01:49_brian2_ * + JavaWorld Archives
01:49_brian2_ o Design Techniques
01:49_brian2_ o How-to Java
01:49_brian2_ o Java 101
01:49_brian2_ o Java Design Patterns
01:49_brian2_ o Java Q&A
01:49_brian2_ o Java Tips
01:49_brian2_ o Java Traps
01:49_brian2_ o Server-side Java
01:49_brian2_ o Under the Hood
01:49_brian2_ * Site Resources
01:49_brian2_ * Featured Articles
01:49defn_brian2_: please part the channel, you are spamming
01:49_brian2_ * News & Views
01:49_brian2_ * Community
01:49_brian2_ * Java Q&A
01:50_brian2_ * JW Blogs
02:20defndid he part or quit?
02:20defni turned down my logging
02:35hiredmanping?
02:35clojurebotPONG!
03:20dsantiagoIf I'm trying to do a macro, and I want to pass the name of a variable as an argument to it, is there some way I can inside the macro's implementation get both the name and the value of the variable without fully evaluating it? (It's a list structure)
03:27tomojdsantiago: maybe you can instead explain what you're trying to do?
03:29dsantiagoI can try. I'm trying to write some macros that will let me define a named set of functions as a "default" protocol implementation, and then mix those in with overrides as specified by the user. All of which is passed to extend.
03:29dsantiagoSo I want to be able to write something like (mixin SomeType DefImpl), where DefImpl is a function map, and have that be turned into an extend.
03:30tomojok, I don't think I will be able to understand what you're trying to do :/
03:30dsantiagoHeh, OK.
03:30tomojbut, does this satisfy your original question? (defmacro foo [x] `[~x ~(eval x)])
03:30tomojI mean, that is a terrible macro, of course, but macroexpand-1 it
03:30tomoje.g. with (def z '(1 2 3)), (macroexpand-1 '(foo z)) is [z (1 2 3)]
03:31dsantiagoYeah, that hasn't worked for me.
03:31tomojactually, a simpler version is (defmacro foo [x] [x (eval x)])
03:33dsantiagoThe contents of x aren't something that can be evaluated.
03:34tomojyou said "name of a variable"
03:34tomojI assumed you meant a symbol
03:34dsantiagoYeah, I did.
03:34tomojsymbols can be evaluated..
03:35tomoj(eval (eval x)) in my case above will try to eval (1 2 3), which will break, of course
03:35dsantiagoYeah, but it's something like (def test '((this) 1)). You don't want to evaluate test.
03:35tomojbut x is 'z, and (eval 'z) is just '(1 2 3)
03:35tomojif you evaluate 'test you'll get '((this) 1)
03:35tomojdon't evaluate the result of that, though
03:36dsantiagoOooooh.
03:36dsantiagoRight on.
03:36dsantiagoThat does the trick! Thanks.
03:36tomojnote that the symbol must resolve at macro-time
03:36dsantiagoYeah, it would in my case.
03:37tomojso you couldn't do e.g. (let [z '(1 2 3)] (foo z))
03:37tomojgood luck, then
03:37dsantiagoThanks man.
03:37tomojI feel like the language I've been using just now is very imprecise :/
03:39dsantiagoNo more imprecise than mine.
03:50ravahello
03:54ravamind if i ask a few simple questions about compojure not importing?
03:57ravanvm, looks like i just needed to find more up to date information
04:35Borkdude,(clojure-version)
04:35clojurebot"1.1.0-master-SNAPSHOT"
04:38RaynesBorkdude: sexpbot is running 1.2
04:38Borkdudechouser: I am reading section 5.3.3 of TJoC, but I'm not sure I get the example
04:38BorkdudeRaynes: aha..
04:39Borkdude$(let [r (range 1e9)] [(first r) (last r)])
04:39sexpbotExecution Timed Out!
04:39Borkdudehmm
04:39Borkdude,(let [r (range 1e9)] [(first r) (last r)])
04:40clojurebotExecution Timed Out
04:44BorkdudeIn Clojure 1.2 the example doesn't generate a heap space problem, because last r doesn't hold on the the head and local r gets cleared when (last r) starts executing?
04:46Borkdude$1e9
04:46sexpbotCommand not found. No entiendo lo que estás diciendo.
04:46Borkdude$(print 1e9)
04:46sexpbotresult: 1.0E9
04:47Borkdude$(let [r (range 1e9)] (last r))
04:47sexpbotExecution Timed Out!
04:47RaynesBorkdude: You can do $eval for stuff like that.
04:47Raynes$eval 1e9
04:47sexpbotresult: 1.0E9
04:48RaynesThe reason it didn't work before is because the way I do $() is hackish. ( is seen as a command. :p
04:48Borkdude$+ 1 2 3
04:48sexpbotCommand not found. No entiendo lo que estás diciendo.
04:49Borkdude$(+ 1 2 3)
04:49wooby$'1e9
04:49sexpbotCommand not found. No entiendo lo que estás diciendo.
04:49sexpbotresult: 6
05:11kotarak$(do 1e9)
05:11sexpbotresult: 1.0E9
05:29eleanis there an easy way to do something like "1 -> [1]" "[1] -> [1]"
05:30eleanin other words make a number, one-element list; and if given a list keep it a list ;]
05:32kotarak,(let [to-vector #(or (and (vector? %) %) [%])] [(to-vector 1) (to-vector [1])])
05:32clojurebot[[1] [1]]
05:33tomojwhy not use if?
05:33kotaraktomoj: sheesh... if... ;)
05:34eleankotarak: yeap.. does the trick, but after few weeks of clojure I though there was some magic "x" function already ;D I guess I'd use this one then
07:30r0manhi all, some months ago i was using incanter-chrono in one of my projects. it seem like it is no longer maintained. what's the new way to go? what are you using? clj-time?
07:37AWizzArdMoin r0man, simplesimon2k und robo___ :-)
07:37esjr0man: try clj-sys
07:38esjit has chrono in it now
07:38r0manesj: ok thx, that's what i wanted to hear :)
08:38TheBusbyer, what's the current (1.1.0) code to generate a lazy fibonacci sequence? (all the old posts don't seem to work any longer with lazy-seq in 1.1.0)
08:44TheBusbyarg, nmind realized a typo was throwing me off...
09:05emhcan I override toString on a record?
09:05Raynesemh: Yes.
09:08emhRaynes: I specified Object as the protocol and (toString [this] (java.lang.Integer/toBinaryString (:subset this))) as the method. I can call it, but print doesn't use it. what's wrong?
09:08RaynesI don't know. I don't think I've ever done that before. I just know that it's possible.
09:18mmarczykemh: you should probably look into print-method
09:22AWizzArdemh: or print-dup
09:22AWizzArd(defmethod print-dup YourRecord [r, writer] (.write (str "Name: " (:name r)))) something like that
09:23AWizzArdfor (defrecord YourRecord [name a b c])
09:23AWizzArd(binding [*print-dup* true] (print (YourRecord. "emh" 1 2 3)))
09:23AWizzArdsame with print-method
09:24AWizzArdthough, print-dup should really write something readable.
09:37stribbhi there, trying to work out why lein isn't working for me...
09:38stribbhttp://pastebin.org/241659 is a brief synopsis of the problem
09:41stribblein uberjar; java -jar <jarfile> works
09:42stribbbut lein repl and lein swank both fail
09:45rdsrhey all, is it possible to define a var in namespace "A" from namespace "B"
09:45rdsr?
09:55Borkduderdsr: I get a "java.lang.Exception: Can't create defs outside of current ns" if I try to do that
09:55Borkdudeso I think not
10:01rdsrBorkdude: hmmmm, what I really wanted was to plug a function definition dynamically while calling gen-class
10:11otfromstribb: I'm having a similar problem to you moving to clojure 1.2.
10:13otfromdoes anybody have a basic project.clj that works with swank-clojure and clojure 1.2?
10:14otfromThe project I have at the moment works fine with clojure 1.1, but I want to try out some of the new defrecord stuff in 1.2.
10:16otfromstribb_: did you get your lein swank stuff fixed?
10:16stribb_nope
10:17otfromme neither
10:17otfromgoogle isn't providing much clarity atm either (though that is probably my failure)
10:18otfromstribb: Stuart Halloway has something that works under labrepl - http://github.com/relevance/labrepl/blob/master/project.clj
10:18otfromthough I get problems with my unit tests when I make my project.clj look like that.
10:19otfromstribb: are you using emacs-starter-kit and elpa as a start?
10:20stribbbeen using emacs for years
10:20stribbbut elpa, yeah
10:21otfromI dumped my 4kloc .emacs for emacs-starter-kit. ;-)
10:24stribbno way I could do that, got my org-mode just right and there are some custom functions I can't do without
10:24stribb<shrug>
10:24stribbdon't think emacs is the problem here
10:25stribbthe expected workflow is lein swank, in the console, then M-x slime in emacs, right?
10:26otfromI've been pulling some of my org-mode bits and others into a separate file, but yeah I did dump a lot.
10:26otfromI'm doing M-x slime-connect from a clojure file
10:26stribbstill, the "lein swank" bit has to work first, right?
10:27otfrommy project.clj is here: http://pastebin.org/241679
10:27otfromso I get swank up and running, but then I can't actually do any work with it.
10:27otfromThe only change is moving from clojure 1.1 to clojure 1.2.
10:28otfromand adding :repositories
10:28otfromyes, the lein swank needs to work first to connect to
10:29stribbinteresting: I haven't qualified the lein-swank as leiningen/
10:30stribbit's just plain in my .prj
10:30stribbmaybe that's my problem
10:30tcrayfordstribb: slime-connect
10:30tcrayfordM-x slime-connect
10:30tcrayfordunless swank is still failing
10:31tcrayfordif it is, shoot for what the errors are
10:31otfromI was having trouble with 1.2. lein swank started working when I went to lein-swank 1.1.0
10:31tcrayfordheh
10:31tcrayfordthat might be my fault
10:31otfromoh?
10:31otfromIt would be nice to have fixed before the next dojo. ;-)
10:31tcrayfordI authored xref support (slime-who-calls) into swank
10:31tcrayfordalso hi otfrom
10:31otfromhi
10:32tcrayfordI'll probably be doing my talk on monads at the june dojo, unless uncle bob makes his blog post on em before then
10:32stribbso when I look at swank.clj -main
10:32stribbit just runs start-repl
10:32stribbwith no args
10:32otfromtcrayford: that'd be cool
10:33stribbbut start-repl requires at least one arg
10:33tcrayfordstribb, none of that should be any problem
10:33tcrayfordcan you paste the error you get?
10:33stribbtcrayford: http://pastebin.org/241659
10:34tcrayfordthat's weird
10:34otfromtcrayford: I got the same before rolling back to swank-clojure 1.1
10:34otfromI'm using emacs, emacs-starter-kit and elpa, btw
10:34tcrayfordyeah
10:34tcrayfordweird, because I have EXACTLY the same setup
10:34clojurebotdirt simple setup is http://www.thelastcitadel.com/dirt-simple-clojure
10:34rdsrstribb: I have clojure-1.2 and swank-clojure compile from source
10:34tcrayfordand 1.2.0 works here
10:35rdsrstrib: it works fine for me
10:35rdsronly problem is that "lein help" fails
10:35otfromtcrayford: can you post your project.clj?
10:35stribbit's possibly alo interesting that when I make the uberjar, it includes 1.1.0 and 1.2.0-snapshot for both clojure and clojure-jar
10:35tcrayfordrsdr: can you try using `slime-who-calls` over a function name
10:35otfromor paste rather
10:36rdsrin which ns is the fn defined
10:36rdsr?
10:37tcrayfordrsdr: using emacs
10:37tcrayford
10:37rdsroh ok
10:37tcrayfordM-X `slime-who-calls`, over like defn or summat
10:37tcrayfordotfrom: http://pastebin.org/241685
10:38rdsrsomething like the var shoul
10:38rdsrsorry
10:38rdsr1 sec
10:38rdsrerror in process filter: who-calls is not implemented yet on clojure.
10:38rdsrthis is the result I get
10:39tcrayfordheh, emacs just crashed because I pressed some crazy slime thing by accident
10:39tcrayforddid you get who-calls working?
10:39tcrayfordit should take a while (depending on the speed of your HD)
10:41rdsrtcrayford: it gives me the following error "error in process filter: slime-check-xref-implemented: who-calls is not implemented yet on clojure.
10:41rdsrerror in process filter: who-calls is not implemented yet on clojure."
10:42tcrayfordrsdr: and that's with swank 1.2?
10:42otfromTried a cut down version here: http://pastebin.org/241686
10:42otfromand still get java.lang.Exception: Unmatched delimiter: )
10:42otfromwhen I do a M-x slime connect in the unit test file
10:42tcrayfordah
10:43tcrayfordyou need the latest version of clojure-test-mode
10:43tcrayford(from technomancy's github)
10:43otfromok, do I need the latest clojure-mode as well?
10:43tcrayforddon't think so
10:43tcrayfordI don't have it anyway
10:43rdsryes 1.2.0-SNAPSHOT
10:43tcrayfordit isn't on elpa yet, waiting for upload
10:44tcrayfordrdsr: can you try with just 1.2.0?
10:44tcrayfordthat should have who-calls in it
10:45tcrayfordnote that who-calls only works if you have loaded each namespace by using 'use' or 'require' at the repl, otherwise :file metadata doesn't get set
10:45tcrayford(something I can't fix at all, unfortunately)
10:46rdsrlet me try that
10:46stribbI get the impression lein and swank-clojure are in a state of flux at the moment and that if I try again in a couple of weeks everything Might Just Work
10:46otfromneeds latest clojure-mode as well
10:46mmarczykrdsr: for creating Vars in other namespaces, check out e.g. intern
10:46tcrayfordthey're both waiting for clojure 1.2 to be released proper, then they should be stable enough
10:47tcrayfordrdsr: though using intern is kinda icky
10:47rdsrI have clojure-mode 1.6
10:47stribbtcrayford: any idea how soon that's likely to be? are we talking days, weeks or months?
10:47rdsroh thks mmarczyk
10:47mmarczykrdsr: Leiningen uses something like "with-ns" (not sure about the name or where it comes from right now) to inject defproject into clojure.core
10:47tcrayfordno idea
10:47stribbfair enough
10:48tcrayfordmost stuff *should* keep on working
10:48tcrayfordclojure 1.0 isn't compatible with the latest version of the tools though
10:48otfromtcrayford: installing the latest clojure-mode and clojure-test-mode from github seems to work
10:48otfromthx
10:48tcrayfordno worries then
10:49rdsrtcrayford: it works now
10:49tcrayfordand properly?
10:49rdsryes
10:49rdsrlet me paste the result
10:49rdsr1 sec
10:49tcrayfordit'll be long if you're doing it on defn
10:49rdsrI ran slime-who calls on source
10:49rdsrclojure/repl.clj
10:49rdsr source
10:49rdsrclojure/contrib/repl_utils.clj
10:49rdsr source
10:49rdsrthis is what is gives me
10:49tcrayfordthat sounds about right
10:50tcrayfordawesome then
10:50tcrayfordnote, if you (use 'some-ns) at the repl, then you can use who-calls inside that ns as well
10:50rdsrcool
10:50rdsrthks
10:50otfromcool. Looks like I'm cooking with clojure 1.2 now. :-D
10:50tcrayfordotfrom: same to you with who-calls
10:50otfromthx tcrayford
10:51tcrayfordit was scary how easily that was to implement
10:51tcrayfordalso gogo push latest version of clork
10:52otfromslime-who-calls works for me
10:52technomancyotfrom: yeah, sorry--there were some issues with lein-swank 1.1.0
10:52technomancyI should have released a 1.1.1 to fix the bad stuff while 1.2.0 was cooking
10:53tcrayfordtechnomancy:
10:53otfromtechnomancy: no problem. Just wanted to get things working for the dojo.
10:53tcrayfordthe only real issue with who-calls is that it won't work on functions you compile interactively, only on things made by `use` or `require`
10:54otfromtcrayford: yeah. I'll push the latest version with just the changes for 1.2. I suppose I'll need to include instructions on how to get newest versions of clojure-mode and clojure-test-mode for people though.
10:54tcrayfordtechnomancy: not sure how to fix that though, as getting the metadata set correctly is probably a pain
10:54technomancyotfrom: when's the dojo? clojure-test-mode should be in elpa soon
10:54technomancyI can bug the elpa maintainer; that might help.
10:54tcrayfordlast tuesday of each month
10:55otfromthe dojo is 25 May
10:55technomancywhere is it again?
10:55tcrayfordlondon
10:55otfromThoughtWorks, High Holborn, London
10:55technomancycool
10:56technomancyis it mostly collaborating on projects then?
10:56otfromand occasionally at Fry-IT, and possibly other places to
10:56tcrayfordone project
10:56otfromtechnomancy: mostly just us flailing around learning clojure.
10:56tcrayford(mostly flailing around learning emacs)
10:56otfromno one really knows what they are doing so it is quite fun. :-)
10:56tcrayford*coughs*
10:57otfromsorry, no one really knows what they are doing, but tcrayford is really bad so he makes us all feel better as we have to help him a lot. ;-)
10:57technomancynice
10:57tcrayfordthat's better
10:58technomancywe just started doing more coding at the Seajure meetings, which I like a lot more than our past meetings of all talk
10:58tcrayfordare you just collaborating on projects?
10:58otfromwe seem to be doing short talks and then the dojo
10:58otfromhttp://github.com/ldncljdojo
10:58technomancytcrayford: we did this at the last one: http://github.com/technomancy/serializable-fn
10:59technomancyjust coming up with a tricky problem to try to solve as we start out the meeting and then collaborating on it
10:59technomancy"swarm coding"
10:59otfromabout a 50-50 split between Java coder and Pythonistas
10:59tcrayforddoes seriazable-fn do locals properly?
10:59tcrayfordmight be able to use that for refactoring-mode
11:00technomancytcrayford: yeah, it has a few issues with serializing the closures though; not all types can be serialized if they're closed over
11:00technomancyI think it could be made to work reliably; I'm just focused on other things right now
11:00tcrayfordI only really care about what vars are bound in a given subexpression
11:00tcrayforddon't really care about values
11:00technomancyyou should try it
11:01tcrayfordit'd save a lot of pain if it does
11:01tcrayfordthere's like 150 lines of recursive pain for looking at vars
11:01tcrayford(in refactoring-mode)
11:02technomancytcrayford: actually that probably won't work
11:02tcrayfordbecause?
11:02technomancyyou have to use serializable-fn's fn var rather than clojure.core
11:02tcrayfordI can just nick bits of its implementation
11:02tcrayford(whichever bit cares about locals for closures)
11:03technomancyit can't serialize just any fn; it's a way of generating special fns that are serializable
11:04tcrayfordI can redefine an fn when I'm examining a users code
11:04tcrayfordin a different namespace
11:05tcrayfordbut yeah, thats kinda hacky
11:29mattrepltechnomancy: swank-clojure-project is deprecated?
11:36emhmmarczyk: AWizzArd: thx! that worked. trying to figure out how to make it work with pprint now
11:38otfrommattrepl: yes, use lein swank and M-x slime-connect now.
11:41technomancymattrepl: deprecated is not quite it. it's "in search of a maintainer"
11:41technomancymattrepl: if it works for you, continue using it
11:42technomancyI'm just concerned about it confusing folks new to the language; lein swank is a lot more foolproof
11:47mattreplis there a discussion of the issue(s) anywhere?
11:51otfromtcrayford: changes pushed to ldncljdojo repo
11:54tcrayfordotfrom: cheers
12:02mattreplotfrom: just came across a paste you made about the "unmatched delimiter )" when connecting to swank-clojure. did you figure out what was wrong?
12:22mattreplnm, re: "unmatched delimiter", found in log
12:25otfrommattrepl: yes. Fixed it with the help of technomancy and tcrayford. Posted about it here: http://wp.me/ppA5G-K
12:25sexpbot"leiningen, clojure 1.2 and emacs « Wifi and Coffee"
12:25mattreplotfrom: thanks
12:26otfromnp
12:32LauJensenEvening all
12:35emhoverriding pprint was done same way, but overrididing simple-dispatch instead of print-method
12:44mattreplotfrom: interestingly, after installing clojure-mode 1.7.1 from a buffer, installing clojure-test-mode from a buffer fails saying that 1.7 isn't available, only 1.6 (even though 1.6 was deleted via the list-packages buffer and verified that it was, in fact, removed from elpa dir)
12:55mabeshrm.. I can't seem to "use" a ns with a defrecord and then use the constructor of the type defined... I get a "Unable to resolve classname" error. I've tried compiling it but no luck.. Is there a trick to use records defined in another ns?
12:57KjellskiCan someone give me a hint why this snipped does not create a JFrame that has a GridLayout?
12:57Kjellski(def frame
12:57Kjellski (doto (new JFrame "Test")
12:57Kjellski (.setLayout (new GridLayout height width))
12:57Kjellski (.setSize 400 400)
12:57Kjellski (.setVisible true)))
12:58AWizzArdKjellski: what happens instead?
12:59KjellskiI'm getting a JFrame with a BorderLayout =(
12:59AWizzArdsieht eigentlich gut aus soweit...
12:59AWizzArdWell, in his example at http://clojure.org/jvm_hosted Rich gave four arguments to the constructor.
13:06otfrommattrepl: not sure, possibly try restarting emacs? Worked all at once for me.
13:17arohnermabes: what version of clojure are you running? recent 1.2 snapshots got rid of the var constructor
13:17arohnermabes: so if you do (defrecord record) in ns foo.bar, it just makes a class foo.bar.record
13:17arohnerso just do (foo.bar.record. args)
13:24otfromdo you still have to do foo.bar.record. if you do :use foo.bar?
13:46emhotfrom: (:import foo.bar.record) enables the unqualified name, since a record is a Java class. idk if it's a good way to do it
13:51KjellskiAnybody here with the rights to change examples on clojure.org?
13:53KjellskiThe example from http://clojure.org/jvm_hosted seems to use a JFrame, but it is not... weird as swing is, there needs to be an underlying JPanel in order to set the layout correctly...
13:54Kjellski*err* replace JFrame with GridLayout
14:03otfromemh: thanks. Does anyone know if there are there any good examples out there?
14:14qbgKjellski: JFrames contain a contentPane in which the components go
14:15_brian2_technomancy : is the compojure tutorial still current?
14:19Kjellskiqbg: Yes, but the example from that page is missing that point... this setLayout leads to nothing but an BorderLayout in that JFrame... ;)
14:19LauJensenThere wouldn't happen to be a real X11 + Nvidia + Ubuntu expert hiding in here? :)
14:20KjellskiLauJensen: What would he need to answer?
14:20LauJensenI would tell him in private as not to clutter #clojure :)
14:23qbgKjellski: The layout manager in the content pane should be a GridLayout with that code
14:27maaclDoes anyone have an example of how to do file uploads using compojure 0.4 / ring?
14:35_brian2_maac1 : there is also a compojure mail list
14:36shevrondelucaHey everyone. I'm trying to write an article 'bout clojure. For that I try to find some great examples. Are there any good collections with great programs using clojure?
14:39tomojthe other day my cousin (known for his bullshit) tried to talk to me about programming: "so are you using any new programs?" "uh, yeah, there's this one called clojure that's kinda new" "oh, yeah, they used that for this database I worked with at motorola" "...awesome" "no, it was a shitty program. cool way to program, but they screwed it up"
14:42maacl_brian2_: yeah I know, but people here are usually really helpful with compojure
14:42LauJensenmaacl: The old routines from 0.3.x arent working?
14:43maaclLauJensen: nope - they are gone
14:43LauJensenoh - I used some apache lib, didnt know compojure had its own
14:43LauJensenapache commons FileUpload
14:44maaclah - is there an example somewhere?
14:44LauJensenI never published it, but I can go look
14:45_brian2_noob question > how to do this java instantiation > http://clojure.pastebin.com/DJu5pi0F ?
14:46LauJensenmaacl: went something like this http://gist.github.com/403077
14:47maaclLauJensen: thanks
14:47LauJensennp
14:48qbg_brian2_: The last line would be (.getInstance (TwitterStreamFactory. this))
14:48tomojring has stuff to do this
14:48tomojtrying to extract an example now
14:48_brian2_qbg : ok thnks !
14:49AWizzArdbtw, does ring have something for encoding handling?
14:49qbg_brian2_: you are going to need this from somewhere though
14:49maacltomoj: thanks a lot!
14:49AWizzArdFor example, when I request (via jnlp) a .jar for Web Start, then this could be encoded in pack200 or at least gz
14:49_brian2_qbg : not sure "from" means
14:50_brian2_I'm using it locally
14:50qbgIn Java, you would probably be executing that in a class, right?
14:50AWizzArdIs there a ring handler that can manage to send out one of the three files that I have (file.jar, file.gz or file.jar.pack.gz), depending on what the Client is requesting?
14:50_brian2_right
14:51_brian2_why does that matter?
14:52qbgThere really isn't a 'this' concept in clojure unless you are using proxy/reify/etc.
14:52maaclLauJensen: I think the syntax for routes has changed to because the gist doesn't work - I get Unsupported binding form: (:servlet-request request)
14:52_brian2_ok, this is another form of the method that calls string arguments
14:53_brian2_there is, i mean
14:53LauJensenmaacl: As I recall thats now tucked away in some multipart middleware
14:53LauJensenI have used it with C4.0 now that I think of it
14:53_brian2_ twitterStream = new TwitterStreamFactory().getInstance(args[0], args[1]);
14:55qbgDo you want to get the arguments from a java array?
14:56_brian2_no,they are strings (i guess), username and password
14:56_brian2_or maybe char[]
14:56qbg(.getInstance (TwitterStreamFactory.) "something" "otherthing")
14:56qbgFor instance.
14:57_brian2_hmm. I think I forgot the period in back of factory
14:59maaclLauJensen: You mean ring middleware?
14:59_brian2_qbg > "Can't call public method of non-public class"
14:59LauJensenyea
15:04qbg_brian2_: That's weird
15:04_brian2_qbj : it is called within a class that implements another class : http://clojure.pastebin.com/t1VvTCjC
15:05_brian2_i'm digging into the source code
15:12tomojis it just me or is compojure RC2 borked
15:16tomojwell, anyway, maacl, look at ring.middleware.multipart-params/wrap-multipart-params
15:17maacltomoj: yeah, got that far but I can't get it to work
15:17tomojdo you see the file info in the request?
15:18_brian2_ (def twitterStream ( . (new TwitterStreamFactory) getInstance "brw314" "sera1024" ))
15:23maacltomoj: trying to find out now :-)
15:39islonwhy this code doesn't need a "do" special form? (defn stuff [] (assert (= 2 3)) (assert (= 5 4)))
15:41Licenserislon: becase def has in implict do :)
15:44Licenserhrm when I work with java IO how is the best way to make it thread / transaction save.
15:44islonLincenser: thanks =)
15:44LicenserI have an transaction that HAS to do IO, it is not bad if it happens more then once as long as the latest running transaction does the last IO.
15:44LicenserAre agents the right way?
15:45Licenserthen again I need it to finish within the transaction and agent's delay so they are not a good way I fear
15:46islon" However, sometimes you
15:46islonwant a side effect when a transaction succeeds. Agents provide a solution. If you send an action to an agent from within a transaction, that action will be sent exactly once, if and only if the transaction succeeds." Stuart's book
15:47Licenserislon: and thank you in return!
15:47Licenserthat is VERY nice :)
15:49islonthe book is amazing =)
15:51tomojproblem with that is that the transaction might complete without the IO happening
15:51tomojthe action will be sent iff the transaction succeeds, but some if a catastrophic failure happens right after the action is sent...
15:52tomojor some IO error maybe
15:56islonyou can do the IO right inside the transaction in a try catch if you don't mind the "happen more than once"
15:57islonbut transactions + IO are a bad mix
15:59emhusing deftype instead of defrecord makes overriding toString() and seq() work
15:59emhbut (doc defrecord) says: You can also define overrides for methods of Object.
16:16tcrayforduse paredit
16:16tcrayfordprofit
16:16tcrayfordhttp://www.slideshare.net/mudphone/paredit-preso might help
16:16sexpbot"Paredit Preso"
16:16oberalt-return. there it is
16:17oberit's ??\n profit
16:17tcrayfordthere isn't any ?? in using paredit
16:17tcrayfordafter you know the keybindings at least
16:18KjellskiCould someone give me a hint how to tell netbeans that I would like to do something with the libs I´ve included? I´ve added the jars to my library with it and clojure can not find the added dependencies...
16:19oberoh it's a minor mode
16:19oberthought it was an alternative editor
16:19tcrayfordnope
16:19tcrayfordparedit is king once you know how to use it
16:19oberoh look who wrote it. yeah that guy....
16:19tcrayfordI think its the reason lisp isn't that popular: editing sexps without paredit is painful
16:23tomojKjellski: do you really want to let netbeans handle that?
16:23KjellskiI would like to, yes. What solution would you recommend?
16:23tomojI think that would mean other people won't be able to run your project easily (which may not be a problem for you)
16:24tomojthe most popular solution right now is leiningen
16:24islonleiningen is a solution, don't know if it works with netbeans
16:24Kjellskitomoj: I´m actually on windows... and there it's not that comfortable to use leiningen =(, what do you recommend?
16:24tomojah
16:24tomojyou wouldn't like my recommendation
16:25tomojgood luck :(
16:25Kjellski;) reboot to ubuntu?
16:25Kjellski=P
16:25tomojyeah, something like that
16:25Kjellski^^ damned... thought you would think of something like that...
16:26islonor use clojure box
16:26tomojI think people are working on windows support for leiningen
16:26tomojsome maybe one day soon it will be comfortable
16:26tomojanyway clojure should find deps just like java would -- the jars just need to be on the classpath
16:27KjellskiActually I've set it up... and it seems like it's building project from git repos... but I won't end up using something like notepad++ for coding clojure =8
16:27Kjellskitomoj: Install cygwin and vim ... *grml* thought of an easier way... ^^
16:28Kjellskiislon: is the actual clojurebox aware of leining projects?
16:28maacltomoj: I only seem to get a ArrayMap with {file <filename>}
16:29islonKjellski, i dont think so, but it's better than netbeans
16:30tomojmaacl: ring version?
16:30islonand you can put your dependencies in ~/.clojure
16:30tomojputting deps in ~/.clojure doesn't sound better than much to me
16:30Kjellskiislon: Whoot? Just stuff the jars in there?
16:30maacltomoj: 0.2.0
16:30tomojunless you only work on one project...
16:31KjellskiWhat about creating a leining project and edit the files and so on with clojurebox?
16:31islonKjellski, yeap, and configure your .emacs
16:32Kjellskiislon: Would you assist if I run in trouble?
16:33maacltomoj: this is my code http://paste.lisp.org/display/99317
16:34islonsomething like that (setq swank-clojure-jar-path "~/.clojure/clojure.jar"
16:34islon swank-clojure-extra-classpaths (list
16:34islon "/whatever"
16:34islon "~/clojure"))
16:35tomojmaacl: check the html source of your form
16:35tomojmultipart true?
16:35technomancyKjellski: the simplest thing to do is launch a swank server from leiningen and use M-x slime-connect within Emacs to join it
16:35Kjellskiislon: thanks so for, I´ll give that a try... =)
16:35technomancyyou just add [swank-clojure "1.2.0"] to your dev-dependencies in project.clj
16:36Kjellskitechnomancy: okay, that sounds even better =)
16:36technomancyKjellski: I just updated the swank-clojure docs to explain this: http://github.com/technomancy/swank-clojure#readme
16:36technomancyKjellski: that should let you work around some windows quirks if you've already got lein running
16:37Kjellskitechnomancy: *lol* read that two seconds ago, thanks for that specific thing I'm looking for! ^^ I owe you a coffee ;)
16:37technomancyheh; great
16:37technomancyhope it works
16:38Kjellskitechnomancy: I´ll let you know
16:38technomancyI don't have a windows box to test on, so I rely on others to help with platform-specific issues.
16:39Kjellskitechnomancy: Is there a better way to bring the necessary stuff working on windows than installing the clojure box?
16:39technomancyKjellski: sorry, I don't know. I've heard good things about clojure box, but I don't know if it's been updated in a while.
16:39Kjellskitechnomancy: I´m right into that, update in about 20 min ;)
16:40technomancyhope it works well
16:41maacltomoj: nope - that's annoying
16:41tomojyes, not sure how to get hiccup to make the form multipart
16:42tomojah, map as first argument I think
16:42tomoj(form-to {:multipart true} ...) or something like that?
16:48Kjellskitechnomancy: damnes, that rocks! Just added the dependecy, installed clojurebox, ran "lein deps", in emacs "M-x slime-connect" and here I am. Running like a charm on Windows 7 64 Bits. You did a great job! Thanks.
16:49technomancyheh; that's nothing new. the only difference is one of making documentation clearer. =)
16:49technomancywhich I guess is a big deal.
16:50Kjellskitechnomancy: Yes it is. For me, relatively new to clojure and it's great projects, it's extremely important...
17:00tcrayfordtechnomancy: I wasn't even using clojure before lein came along
17:00tcrayfordtechnomancy: I tried, but got annoyed at it
17:10maacltomoj: (form-to {:enctype "multipart/form-data"} works :-)
17:11tomojbizarre
17:11KjellskiHow can I add a dependency to a lein project like clj-pivot? What exactly needs to be typed?
17:13tomojoh, I hadn't written a file upload field by hand in so long that rails tricked me into thinking it was <form multipart="true"> :(
17:16maacltomoj: no prob - trying to find out how to control which dir it places the tempfile in
17:17tomojmaacl: why does it matter?
17:18maacltomoj: I am a control freak :-)
17:19tomojI think you need to .setRepository on file-upload
17:20tomojunfortunately it seems to be private
17:20tomojoh, actually, it's not file-upload you want anyway, but the factory, hmm
17:20tomojI think you will not be able to change it without hacking the middleware
17:21maacltomoj: I seem to recall seeing an option on the middleware somewhere
17:22tomojnot the one I'm looking at
17:22tomojonly option is encoding
17:23tomojaren't you just going to move them out of the temp directory immediately anyway?
17:23nollidji've new to clojure and have a question about the hash type. is there a way to get a reference to the object that is used to key an entry?
17:24nollidjsomething along the lines of (get-key map key), which resolves to a referene to the key that is actually used in the map entry?
17:24Chousukehmmh.
17:24nollidjthis isn't possible with a vanilla java.util.Map, so if clojure doesn't offer a special way to do that, i don't think there's an easy way to get it
17:25ChousukeI think there might be a java method for it.
17:25maacltomoj: yeah, that might be the solution
17:25ChousukegetEntry or something?
17:25maacltomoj: I guess that a move isn't that expensive
17:25tomojFile/renameTo I think
17:25nollidjChousuke: i'm looking at http://java.sun.com/javase/6/docs/api/java/util/Map.html now, and it doesn't look like it
17:25sexpbot"Map (Java Platform SE 6)"
17:25Chousukenollidj: no, I mean in the clojure map interface.
17:26tomoj(well, it's not static)
17:26nollidjah, cool
17:26Chousukenollidj: but I'm not sure; I just have a vague feeling I've seen something like that somewhere :P
17:26nollidjis there a doc for that somewhere? i'm still not up on where to look
17:26nollidjhttp://richhickey.github.com/clojure/ is all i know now
17:27Chousukeno docs for the java APIs but contrib has the "show" function in some namespace which might help you
17:27nollidjhow might i load the show function?
17:27Chousukejust figure out the namespace it is in (I think repl-utils?) and require it
17:28Chousukelook at the contrib docs
17:28nollidjokay. thanks
17:28tomojyeah, clojure.contrib.repl-utils
17:29Chousukebut if you can't find a suitable method then one probably doesn't exist
17:30Chousukewhat kind of key do you have that you need the exact object?
17:31nollidji'm getting a quick course in clojure by writing a chart parser
17:31nollidjusing the cky algorithm
17:32nollidja chart entry is keyed by something like (span-start, span-end, span-symbol) with a value like (probability backpointers)
17:32nollidjbackpointers is a list of chart entry keys
17:32nollidjso, ideally, i'd be able to make it a list of already allocated chart entry keys
17:32nollidj...if that makes sense
17:34tomojso you're just trying to save memory?
17:34Chousukehmm, right.
17:34nollidjmore or less. it's a relatively trivial issue, but i'd like to be able to do it this way if i can
17:34Chousukenollidj: maybe you need some kind of a lookup cache for them?
17:34nollidji could just write my own cache or make the chart map a subclass of map that keeps track of its key objects
17:34nollidji was hoping there'd be a way around that
17:35Chousukenollidj: use a set to store the keys you allocate maybe?
17:35nollidjthat's what i would do if there weren't an easy way to pull the key out of the map, yeah
17:36rhudsonnollidj, hashmaps just aren't designed to map backwards (value->key)
17:36nollidjrhudson: i don't want to do that. i want to go (object that has identical fields to key)->(key already in map)
17:37nollidjso that i can pass around references to a key without creating dozens of identical key objects, instead using the one in the map
17:37nollidjbecause, in my case, certain map values will have references to map keys
17:37nollidjso if i have 300 map values that all refer to the same entry, i don't want 300 unnecessary duplicates of what's really the same key object
17:38nollidj...now that i think about, i can just make a function to generate key objects and have it intern/memoize values as necessary
17:38rhudsonyep
17:39tomoj,(key (.entryAt {:foo :bar} :foo))
17:39clojurebot:foo
17:39tomojlike that?
17:39Chousukeah, so there was a method.
17:39nollidjtomoj: yeah... i just found select-keys, which looks like it's similar
17:39nollidjproblem solved
17:40nollidjstill getting the hang of working with a repl loop and having a lot to command quickly. it's nice
17:40tomojselect-keys will be O(n) instead of O(1) for entryAt
17:40nollidjyeah
17:40nollidjah, and there's also find
17:40tomojoh, yeah
17:41tomojactually, I suspect find won't work
17:42rhudsonIt does return a MapEntry
17:42tomojit seems to work despite my suspicion
17:42tomojah, find is just entryAt on Associatives
17:43tomojbut if the thing isn't Associative, it casts to Map and then returns a MapEntry with the key you passed as the key, instead of the key in whatever the thing is
17:43nollidjinteresting
17:43tomojI guess that is for java maps
17:44zakwilson_It appears that strings are faster as map keys than keywords. Can someone explain why?
17:47rhudsonWhat leads you to believe they're faster? (How did you measure?)
17:51zakwilson_rhudson: I have an application that involves a very large number of map lookups. Changing the keys to strings resulted in a substantial (~30%) speedup.
17:52rhudsonAre the keys dynamically generated, or are they literals in the code?
17:53zakwilson_Not entirely sure what you're asking. The maps in question are in-memory at the time the CPU-intensive operation takes place.
17:54rhudsonBasically, I'm wondering if some input is being converted to a keyword (which essentially involves a map lookup) before the keyword is used for the lookup in the target map.
17:54zakwilson_They're serialized to disk with (spit (str the-map)). It's also noteworthy that reading the string version back in is five times faster than the keyword version.
17:55zakwilson_Oh. No, that's not happening.
17:55zakwilson_http://github.com/zakwilson/zutil-clj/blob/master/map.clj <-- the application is calling intersection and difference on in-memory maps
17:59tomojfor me, 100000 keyword lookups is faster than 100000 string lookups, it seems
17:59rhudsonOut of ideas then. It seems like keywords should be faster, in that once you've found the right hashbucket you can just use identity rather than string equality to find the key
17:59rhudson[ you can just => the implementation can just]
18:01tomojthis is probably a trivial case and the results are probably meaningless, but:
18:01tomoj,(let [m {"foo" 3}] (time (dotimes [_ 10000000] (m "foo"))))
18:01clojurebot"Elapsed time: 607.041 msecs"
18:01tomoj,(let [m {:foo 3}] (time (dotimes [_ 10000000] (m :foo))))
18:01clojurebot"Elapsed time: 607.719 msecs"
18:01tomojhah
18:01tomojfor me, the keyword one is faster
18:02zakwilson_I think the fact that it's always the same keyword has an impact.
18:02tomojand that the map only has one key anyway..
18:02tomojI tried it earlier with maps with keys like :1 :2 :3.. and "1" "2" "3"... and then ran through all the keys, and the keyword one was faster
18:03tomojbut I probably screwed up
18:03zakwilson_I have a 27k-element map containing many multi-thousand element maps and I'm looking at all the data at once.
18:06rhudsonCurious, on my machine I'm seeing longer times for keywords on 2-element maps.
18:07rhudsoni.e. {:a 1 :b 2} vs. {"a" 1 "b" 2}
18:07tomojreading keywords is definitely a whole lot slower than reading strings
18:16rhudsonIn Java source, Keyword.hashCode() is sym.hashCode() + 0x9e3779b9
18:16rhudsonsym.hashCode() returns the value of a final field
18:16rhudsonwhich is presumably what String does
18:17rhudsonSo there's an extra function call + addition for keywords.
18:17rhudsonWonder if that's enough to explain the difference.
18:18rhudson(seems unlikely offhand)
18:20zakwilson_I haven't tried symbols, but I'm assuming they would have similar performance characteristics to keywords.
18:22rhudsonI see times more like strings than keywords (for symbols)
18:22rhudsonwith {'a 1 'b 2}
18:22tomojbut
18:22tomoj,(identical? (read-string "foo") (read-string "foo"))
18:22clojurebotfalse
18:24tomojtemporarily hacking clojure's source to remove that addition wouldn't severely break anything as long as you don't put symbols and keywords in the same map, I bet?
18:24rhudsonRight. But they'll have the same hashcode. So if the hashbuckets are small, lookup time is dominated by finding the right hash bucket.
18:24rhudsontomoj: seems unlikely it would break anything
18:25tomojI don't have a good solid benchmark to run anyway
18:25zakwilson_No need to mix types. Using keywords was actually premature optimization: I assumed they'd be faster than strings.
18:25rhudsonI would have assumed so too!
18:25zakwilson_The only bad thing about strings is that they take more memory
18:25tomojkeywords are the most idiomatic choice as well, I think
18:26zakwilson_Strings are more correct in that I had to strip out some characters to represent the values as keywords. Memory use is really the only down side.
18:27rhudsonIt seems like Keyword could be sped up by calcing the hash on construction & just return that, just like Symbol (and presumably String) do
18:29rhudson... it'll make you really appreciate using someone else's
18:30nollidjquick terminology question: do you call 'a an "atom" (as i learned when studying scheme) or something else?
18:30zakwilson_'a is a quoted symbol
18:31tomojrhudson: but we should probably know how much that slows it down before doing so, no?
18:31tomojI mean, whether the addition is actually causing the slowdown
18:31zakwilson_In traditional Lisp terminology, something that isn't a cons cell is an atom. Clojure has something entirely different that's also called an atom.
18:32nollidjthat's an important point, then
18:32zakwilson_So... I'm not sure what to call a non-collection value in Clojure.
18:32rhudsontomoj, it's not just the addition, there's an extra method call as well.
18:32tomojah, yes
18:33technomancyzakwilson_: the Joy of Clojure calls them scalars
18:33technomancywhich is uncomfortably close to "scala" for me
18:33tomojdo you have a good benchmark I can run that shows that keywords are slower?
18:35nollidji've got a question related to this keyword vs string issue. i've mentioned that i'm making a toy natural language parser. from my somewhat vague background in lisp-like languages, i know that sometimes people implement such parsing on the basis of quoted symbols. so, a grammar rule might be something like {:parent 'NP :left-child 'DT :right-child 'NN}. i could also represent it like {:parent "NP" :left-child "DT" :right-child
18:35nollidj"NN"}. i'm going to be keying some hashtables with these values, as in (get rules-by-parent "NP")
18:35zakwilson_If it wasn't part of a proprietary super-secret potential startup, I'd give you the actual application I'm working on as a benchmark.
18:36rhudsonI don't know if it's good, but I was doing (def m {:a 1 :b 2}) then (time (dotimes [_ 10e6] (m :a)))
18:36rhudsonmutatis mutandis for strings and symbols
18:36hiredman(:a m) is a good habit to get into
18:36zakwilson_hiredman: doesn't work for string keys
18:37tomojI get only tens of milliseconds difference there
18:37hiredmanzakwilson_: I am aware
18:37tomojthat like what you're seeing?
18:37zakwilson_Why is it a good habit?
18:37hiredmanbut if you are using keywords you should get into the habit of (:a m)
18:38hiredmanbecause if you move from maps to records, (:a m) will get you fast field access for records, (m :a) and (get m :a) won't
18:38hiredmanthe compiler recognizes (:a m) specially
18:38rhudson(:a m) actually takes longer than (m :a) on my trivial benchmark
18:39zakwilson_rhudson: I increased that to 10e7 and got faster results with keywords than strings
18:40rhudsonzakwilson_: Hmm, I don't see that. I'm running Clojure 1.1 on Java 5 on Mac OS X.
18:40tomojzakwilson_: same here
18:41zakwilson_I'm running Clojure 1.1 on Java 6 on Linux (amd64)
18:42rhudsonHmm. I think Hotspot's a lot brighter in J6 than J5
18:43nollidjzakwilson_: i'm on a similar environment (clojure 1.1, java 6, linux amd64), and (if i'm doing this right) keywords are faster
18:43nollidjfor 10e6
18:44zakwilson_Keywords are faster for this trivial benchmark, but not for my application.
18:44nollidjah, right
18:45zakwilson_Records are new in 1.2?
18:45rhudsonyes
18:46zakwilson_How much faster should a record lookup be than a map lookup?
18:47rhudsonI think hiredman's point was that it's constant time (for the (:a m) form) for records
18:47zakwilson_It's probably not faster enough to matter in this application - the part that could be a record only has a few lookups per call.
18:50rhudsonWell, you need to decide if faster + more correct > bigger
18:50tcrayfordand less flexible
18:53zakwilson_The application involves text classification, so... I kinda like more correct.
18:54nollidjapologies for triviality, but when using reduce, as in: (reduce (fn ...) (range 10)), the function supplied must be able to handle the form (reduce (fn ...) ()). how can i write this in-line so that the function accepts 2 or 0 arguments as appropriate?
18:54zakwilson_It also involves lots of clock cycles, so... faster is nice. Memory use could be an issue. We'll see.
18:54tcrayfordnollidj: (reduce (fn [x y] blah) [])
18:55tcrayfordof
18:55tcrayfordoh
18:55tcrayfordumm
18:55tcrayford(reduce (fn ([] blah) ([x y] bork)) [])
18:56nollidjah, interesting. thanks.
18:56zakwilson_(fn [& stuff] (let [[x y] stuff] do-things...)) works too
18:56nollidjyes, i hadn't quite gotten the & syntax down
18:56nollidjmakes sense. thanks.
18:56tcrayfordI think the multiple arity version is somewhat cleaner though
18:56tcrayfordthan that destructuring one
18:57tcrayfordthough depends what you're doing
18:57tcrayfordyou could use if-let to check if you have two args
18:57tcrayford(fn [& more] (if-let [[x y] stuff] do-things...))
18:58tcrayford(fn [& more] (if-let [[x y] stuff] do-things... do-other-things...)) even
18:58zakwilson_There isn't really a clean way to supply default values in this situation, which I find unfortunate.
18:58tcrayfordyou can use the default parameter for reduce as one of them
18:59tcrayford(defn my-map [f coll]
18:59tcrayford (reduce (fn [xs x] (conj xs (f x))) [] coll))
18:59tcrayford
18:59zakwilson_I miss CL's &optional in this case.
18:59tcrayfordnever used CL, explain?
19:01zakwilson_(defun foo (bar &optional (baz 3)) ...) uses 3 for the value of baz unless the caller supplies one.
19:01tcrayfordlike pythons def foo(x=1) stuff then
19:01tcrayfordgotcha
19:02zakwilson_Yes
19:02zakwilson_There's also &key, which uses keyword arguments (also with optional default values) and &rest, which is like Clojure's &
19:03tcrayfordyou can get keyword arguments with defnk, which is nice
19:04tomoj,((fn [foo & {:keys [bar baz]}] [foo bar baz]) 1 :baz 2 :bar 3)
19:04clojurebot[1 nil nil]
19:05tomojworks in 1.2
19:05tomoj(i.e. you get [1 3 2])
19:05tcrayfordI thought clojurebot used 1.1?
19:05tcrayfordoh, it does
19:05tcrayfordyeah
19:28tcrayfordwhat's a good way of getting clojure's working directory?
19:28tcrayfordI'm using (sh "pwd) atm, but not happy
19:29tomoj`(System/getProperty "user.dir")? :/
19:31tcrayfordworks fine here
19:31tcrayfordcheers
19:32tcrayford*is killing dependancies*
19:33jColeChangedThis is probably going to be a stupid question, but in what situations would one want to use 'when-first'?
19:34tcrayford,(when-first [x [1 2 3]] 1)
19:34clojurebot1
19:34tcrayfordoops
19:34hiredmanhuh
19:34tcrayford,(when-first [x [1 2 3]] x)
19:34clojurebot1
19:34hiredmanwhen-let-first
19:34tcrayfordits not named too well
19:36hiredmanand whats the diff with (when-let [x (seq [1 2 3])] x)
19:44tomoj,(when-first [x [nil 2 3]] 24)
19:44clojurebot24
19:44tomoj:/
19:44tomojoh
19:44maxhodakis there a library for zookeeper in idiomatic clojure?
19:45tomojmaxhodak: I don't know of one, but I'd love to help, or please let me know if you find one
19:45tomojvery interested
19:46maxhodaktomoj: i might write something that wraps the java api
19:47maxhodakmy concern is that zk is a such a sophisticated system
19:47maxhodakit's not something that you'd just write a wrapper for in a few hours
19:47tomojyeah..
19:48tomojI was planning to just wrap whatever I needed
19:48tomojwhich would probably lead to ugliness
19:48maxhodakwell i mean, it just wouldn't work
19:48maxhodakit's all based on push notifications and watches
19:49maxhodakand dealing with the million error states that arise
19:49maxhodakits more than just a wrapper, since you need to be able to receive the watch triggers
19:58tomojerror states sound annoying, but why are watches a problem?
20:09etatewhats the difference between a SNAPSHOT and a master-SNAPSHOT?
20:11hiredmanuse the first for contrib and the second for clojure
20:15tcrayfordtechnomancy: ping
20:26tomojis the name "seq heil" offensive? :)
20:27jColeChanged"seek hell" or "sequel"?
20:29tomojare you asking how it's pronounced?