#clojure logs

2010-12-11

00:31harishtelladoes anyone here use rlwrap for spicing up their clojure repl?
00:34jk__harishtella: i have it that way on my linux box. set it up before i knew about lein/cake and it works very well
00:36harishtellajk__: I really like, but I couldn't get paren highlighting to work. Was that working for you?
00:37jk__harishtella: doesn't highlight, it jumps the cursor to the matching one when you close
00:39jk__harishtella: to be honest, i only use that now when i want to try something very quickly. usually i use CCW in eclipse so i can have a nice editor (never learned emacs)
00:53harishtellajk__: maybe it just doesn't work in mac osx, thanks anyways
01:28ossarehwhat is "holding onto the head of a seq"? where can I read more about this?
01:37amalloyossareh: ##(let [x (range)] [(nth x 1e6) (first x)])## is no good cause you keep the whole seq in ram all at once; ##(nth (range) 1e6) is fine
01:37sexpbot(let [x (range)] [(nth x 1000000.0) (fir... ⟹ [1000000 0]
01:37sexpbot(nth (range) 1000000.0) ⟹ 1000000
01:37amalloy(for a larger number than 1e6 the first would fail)
01:38amalloyin the second case, since you no longer have any reference to the first element of the seq while you're computing the last, the GC can safely throw it away
01:39lancepantz_wow, that's awesome, raynes has been going to town on sexpot
01:39amalloylancepantz_: that was me :P
01:39lancepantz_oh shit, i'm sorry!
01:39amalloyhaha np
01:39amalloyglad you like it
01:39lancepantz_love the inline evaluation
01:40amalloy$markov
01:40sexpbotYou need if you have been bitten by writing.
01:40amalloymine too, but not looking so clever
01:42ossarehamalloy: am I holding onto the head of a seq ? https://gist.github.com/737179
01:42ossarehline 1 in exceptions.log shows what I'm running to eventually result in the exceptions below.
01:44amalloyossareh: i've never seen that traceback before, but it doesn't look like that's your problem
01:44amalloyusually you just get OutOfMemoryError: Java heap space
01:44ossarehnah
01:45ossarehthis is my first use of agents - first OOM's in clojure too.
01:45amalloyossareh: tbh i can't make heads nor tails of the trace
01:46ossarehwonder if I'm causing some issues within the thread pools
01:47ossarehwhat is very interesting is that running that code results in the first 60-100 companies being printed out almost immediately - far too quickly for http requests to really be taking place (though without any knowledge of the thread pool size it is hard to be sure)
01:47ossarehthat said - same things happens if I don't use pmap.
01:49amalloyossareh: looking over your code, here are a few functions i think you will find very helpful, though probably not to fix your bug
01:49amalloyfnil, assoc-in, update-in, condp
01:50amalloyand imo your (let [b (f a), c (g b)]) forms would be cleaner as (-> a f g) threaded forms, but that's style
01:51_atoossareh: heh.. was just about to type a reply to your mail. I think you might be being bitten by the way java strings share data
01:52_ato(slurp (stream agnt)) <-- loads whole JSON feed in as a string
01:52ossarehamalloy: I'm familiar with the assoc-in update-in, I'll take a look at the other two. TBH this isn't any type of long lived code - I just needed to work out the spread of employees..
01:52_atowhen you take a substring of a java string, it doesn't copy the data, it just points at the original
01:52_atoso the "name" field you're hanging onto will probably hang onto the whole JSON file
01:53ossareh_ato: srsly?
01:53_atoyep, they do it for permformance, but it drives me insane sometimes
01:53amalloyossareh, _ato: java strings are very sticky
01:54ossarehso the json itself isn't thrown away when I (read-json) ?
01:55_atoyeah. You'll want to explicitly copy any strings you hang onto. I think the copy structor should do it, so (let [name (String. ^String name)] ...)
01:55_ato,(let [x "foo"] (identical? (str x) x))
01:55clojurebottrue
01:55_atoso str won't do the trick
01:56_atos/copy structor/copy constructor/
01:58ossarehI don't get it - where am I likely to be holding onto that json file?
01:58ossarehthe (:name co) bit in process-company?
02:00_atoyeah, so that gets passed into update-emp-range! and then: (assoc v name emp-cnt) which gets put into emp-ranges
02:00_atohttp://fishbowl.pastiche.org/2005/04/27/the_string_memory_gotcha/
02:00ossarehI'm still reeling from the fact that read-json doesn't lose the json file. Or am I mis understanding you there?
02:01_atoread-json loses it, but the substring hangs onto its parent string's data, if you get what I mean
02:02_atosubstring doesn't copy, it just holds a reference saying I am chars 37 to 49 of the-big-string
02:04ausercan you subclass a module? I mean... can I have (ns a) and then (ns b :subclass a)?
02:04auseror something like that
02:04ossarehauser: (ns) is a namespace - similar to a java package.
02:05amalloyauser: you can do some things like that, but not exactly that; since it's unclear what you want i'm not sure what to recommend
02:05auserwell... I have a few clojure packages that will share a lot of functionality
02:05ossarehauser: if you have the directory structure project/src/a/b/c/core.clj - the ns would be (ns a.b.c.core)
02:06ossarehthe ns in core.clj that is
02:06auserit's event handlers, so I want to fire an event and have each handle their events differently, to be specific
02:06auserossareh: I know that, what should I call them, then?
02:06auserin erlang, they would be modules
02:06ossarehauser: namespaces in clojure.
02:07auserk
02:07amalloyauser: i'd be inclined to have one "parent" namespace with the common functionality, and several namespaces that all depend on that one
02:07auserso they all (:use parent_ns), you mean?
02:07amalloyright
02:07auseryeah, that's what I was thinking after I typed the question
02:07auserI think that's probably the way to go
02:08ossareh_ato: so that link does a great job of explaining the substring thing. Thanks. I'm not sure I get where I'm doing tha.... I get it!
02:08auserthanks amalloy
02:08amalloyauser: if you like you can pretend :use is :subclass :)
02:09auserlol
02:09ossareh_ato: so as a result of not copying it I'm holding onto all the references
02:09lancepantz_auser: have you looked into protocols?
02:09lancepantz_that's my kneejerk
02:09amalloyhaha
02:09ossareheven when I throw it into the map
02:09auserno, protocols?
02:09_atoossareh: yep, exactly
02:09ossarehOMG
02:09amalloyauser: they are the magic fairy dust you wave on things to make everything right, except it rarely works that way
02:10lancepantz_http://clojure.org/protocols
02:10auseruh oh
02:10auseram I going to toss some cookies?
02:10_atoossareh: huge JVM gotcha that bites everyone who ever processes large data sets
02:10lancepantz_hahaha
02:10amalloyhaha no, protocols are cool
02:10auseroh yeah
02:10auserI've seen this in the clojure book
02:10ossarehauser: Joy of Clojure made the them far more approachable than /protocols
02:10auserlooks super neat
02:10amalloyi've just found that i always try to use them as a substitute for interfaces, and they're not
02:10lancepantz_how are they not?
02:10auserdo they do "pattern matching?"
02:11ossarehauser: from my very rudimentary understanding of clojure I think amalloy is right though.
02:11auserhm, guess I'll have to see how they work
02:11amalloyhiredman said something about protocols the other day that really helped me though
02:11lancepantz_i've only implemented one into production code, so i'm not the expert
02:11ossarehauser: they're ways of defining how something should work and you can later supply implementations for how they do work. like gen_server, etc.
02:11auserah
02:11ausercool
02:12lancepantz_you can extend them
02:12ossarehauser: a lot is lost in that description from me - on both sides of the equation.
02:12auseryeah
02:12auser<~ confused
02:12auserbut looking in my pdf
02:13ossareh_ato: I'd not considered 50k requests a large data set :)
02:13auserto no avail though
02:13lancepantz_stuart halloway had a good screencast on them
02:13lancepantz_i should say, presentation that was recorded
02:13auserhttp://vimeo.com/11236603 ?
02:13_atoossareh: eh, true. "medium" then. medium = larger than RAM ;-)
02:13lancepantz_thats the one
02:13auserswweeeeetttt
02:16ossareh_ato: nice, so as a result of that change 4x more data processed before the OOMs start
02:17_atoheh, I guess eventually you are going to be legitimately running out of memory
02:18_atoyou know how up the heap size right? java -Xmx500m for 500MB max heap
02:18ossareh_ato: yup, cheers. - got a clue on how to do that for lein swank?
02:19_atoI think you can put it in project.clj somehow.. just a sec
02:20ossareh:jvm-opts
02:20_atoah yep
02:21ossarehI love how thorough technomancy is!
02:22ossareh_ato: potentially stupid question here - the fact I'm passing the number through from the slurped json isn't going to be doing the same thing is it? this is limited to just strings.
02:25amalloyossareh: yeah, not sure what you mean by passing the number through, but of the core java data structures only strings do interning afaik
02:32ossarehheh - think my wifi router *hates* what I'm doing
02:33_atoyep, safe with numbers, just strings that have that problem
02:38ossareh_ato: cheers - this has been an interesting arc in my "simple report" :)
02:41amalloyhow does with-open work? if i generate a lazy sequence of calls to reading from a with-open resource, and realize the seq outside of with-open, is that a bad thing to do?
02:41chouseryes, bad
02:41amalloyboo
02:41_atowith-open just expands to a (try ... (finally (.close foo)))
02:41amalloywell, +1 for realizing the potential for problem before just doing it, this time
02:41chouserthe file will be closed, so if you then realize an item that requires reading from the file, you'll get an exception
02:42chouseramalloy: yep. good catch. :-)
02:42_atothe lack of some sort "lazy" file handles mechanism is very annoying. One thing refcounting instead of GCing is very nice for
02:43chouser& (with-open [r (java.io.StringReader. "hello")] (take 5 (repeatedly #(.read r))))
02:43sexpbotjava.lang.IllegalStateException: Var clojail.core/tester is unbound.
02:44chouserhm
02:44amalloy*blink*
02:44chouser,(with-open [r (java.io.StringReader. "hello")] (take 5 (repeatedly #(.read r))))
02:44clojurebotjava.lang.RuntimeException: java.io.IOException: Stream closed
02:44chouserthere you go
02:44chouser,(with-open [r (java.io.StringReader. "hello")] (vec (take 5 (repeatedly #(.read r)))))
02:44clojurebot[104 101 108 108 111]
02:44amalloychouser: (repeatedly 5 #(.read r)), btw
02:44chouserd'oh
02:44chouserthanks
02:45amalloyi'll send Raynes the sexpbot/clojail hiccup
02:46amalloyhelped a bit with clojail, but not on that part
03:04auserhere's a dummy question, but is there a way to get the name of the current namespace?
03:09_atoauser: (ns-name *ns*)
03:10auserah thanks :)
04:27bytecolorwoo hoo, I could answer the last question. That's progress.
04:28cpfrbytecolor, clojure-quiz?
04:29bytecolorcpfr: who wrote that? I've been wanting to try that out. hell of a good idea
04:29cpfrno idea
04:30bytecolorit's based on (doc foo), no?
04:32bytecolorthat, to me is the next gen in language learning. Some flavour of game, mixed with hard questions. It can't be easy, else every retard would get it.
04:33bytecolorretards don't push the envelope.
04:39auserso... I'm interested in writing an event driven system... um... similar to gen_event (in erlang)... anyone here have an experience writing events in clojure?
04:39auserjust out of curiosity, really
04:40amalloybytecolor: fliebel is responsible for clojure-quiz, i think
04:40amalloy(though i totally take some credit for steering him in that direction)
04:42amalloyauser: you might be interested in...what is it, that i/o library with channels and siphons and whatever? those probably have some similarity to events
04:43amalloyauser: aleph
04:43amalloyor lamina? i guess aleph uses lamina. lamina claims to be an event-driven data structure for clojure
04:43amalloyeither way, i'm off to bed. enjoy
04:46auseroh good links!
04:46auserhm, event-driven data structure
04:46auseroff to be google-informed
04:46bobo_links?
04:50auserthat's perfect amalloy_ thanks!
04:58UnlogicHello guys! I wonder if you can help me with the following question: how to implement multimethods in pure Clojure withous using Java interop? I need this for research reasons only, so performance is not an issue
05:18kotarakUnlogic: atom holding map of dispatch values to method functions. function which invokes the dispatch function on the arguments, finds the appropriate method function from said map and invokes it. another function ("defmethod") which swap! in a new map with the given method function assoc'd to the given dispatch value.
05:23Unlogickotarak: thank you! i first thought just like that, by I still want the multimethod be a macro so you can call it just like normal function
05:27Unlogickotarak: well, this is still possible if i define an atom and a function separately, but i don't want to pollute the namespace
05:53kotarakUnlogic: Here is a rough sketch. http://paste.pocoo.org/show/303462 Haven't tested it. But only one function is introduced. The dispatch-map atom is attached to the Var metadata.
05:53kotarakUnlogic: so minimal namespace "pollution"
05:53kotarakUnlogic: Untested, though. But I think you get the idea.
06:29djinohi, is there anything particulary wrong with this code? http://ideone.com/dRHz8 , I am getting out of memory etc. If I try to access for example (nth (p) 2000) on this sequence.
06:54mfexdjino, add a (doall ...) around the (remove ...)
06:59mfexhmm, that only turns a stackoverflow error into the out of memory error
06:59djinomfex: hmm, well since the seq is infinite, doalling it wouldnt work
07:17mfexI still think there are eventually to many nested lazy-seqs from remove because each previous item adds another, indeed doall isn't an options so it's best to check one of the existing implementations
08:07fliebelCan someone give me a hand with java.io stuff? For fastcgi-ring I need to convert an output stream to an input stream. I googled it, and it seems the 2 most common approaches are using a byte array or PipedInputStreams. The problem is that the piped approach seems superior, but requires 2 threads. I'm not sure how t implement that in here: https://github.com/pepijndevos/fastcgi-ring/blob/master/src/fastcgi_ring/core.clj#L27 ot that currently at l
08:09fliebelI had 2 piped streams defined around line 27, but that got me into a deadlock, even though the rwites logically occur before the read, at least until the buffer is full, which I think is the problem.
08:42Rayneschouser: Fun bug you found there.
08:42kumarshantanuhi, is it possible to create a lazy function given a regular regular function?
08:42kumarshantanus/regular regular/regular/
08:42sexpbot<kumarshantanu> hi, is it possible to create a lazy function given a regular function?
08:42fliebelkumarshantanu: ??? lazy-seq?
08:43kumarshantanufliebel: lazy-seq generates a seq when realized?
08:43fliebelkumarshantanu: What ind of lazy, and what is a 'general' function?
08:43kumarshantanu(defn foo [] (println "Called foo") 10)
08:44kumarshantanuhow can I create a lazy-version of foo?
08:44fliebelkumarshantanu: lazy-seq only evaluates the expression when you consume the seq. ##(doc lazy-seq)
08:44sexpbot⟹ "Macro ([& body]); Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the body only the first time seq is called, and will cache the result and return it on all subsequent seq calls."
08:45fliebelkumarshantanu: foo doesn't really produce a seq, does it?
08:45fliebelBut you could have a look at repeatedly and iterate.
08:45kumarshantanufliebel: no
08:46fliebelkumarshantanu: What is it that you want, then?
08:46kumarshantanuI need to lazily evaluate a function
08:47kumarshantanupass around the lazy fn until required to be eval'ed
08:47fliebelkumarshantanu: Define lazily, if the function is not a seq. Maybe future is what you want then?
08:47Rayneschouser, amalloy_: I think the problem here is that I may not be realizing the lazy-sequence created by repeatedly and take before I leave the proper scope. Very nice catch. I'll deal later.
08:48kumarshantanufliebel: perhaps I am being ambiguous
08:49kumarshantanuI want to wrap function name and args
08:49kumarshantanuand pass them around until I need to execute
08:49fliebelkumarshantanu: Then partial or an anonymous function is what you want I think.
08:50kumarshantanufliebel: yeah! curried as a no-arg function
08:50kumarshantanuthanks
08:52kumarshantanufliebel: but is there an equivalent of partial that takes no args for the fn?
08:52fliebelkumarshantanu: #(the-fn with some args)
08:53kumarshantanufliebel: Oops! Sorry I am embarrassed -- I think "comp" is serving this purpose
08:54fliebel&((comp inc inc) 2)
08:54sexpbot⟹ 4
09:02G0SUBkumarshantanu
09:03kumarshantanuGOSUB: hey
09:03kumarshantanuG0SUB: or maybe this is the handle
09:03G0SUBkumarshantanu: yep :)
09:04G0SUBkumarshantanu: trust your editor, err client to do the autocomplete.
09:04kumarshantanuG0SUB: I use Pidgin (no joy)
09:07G0SUBkumarshantanu: too much Java programming has made you a masochist.
09:07kumarshantanuG0SUB: LMAO! what client do you suggest? better if cross-platform (currently have to use Windows 7)
09:08G0SUBkumarshantanu: if you are on Emacs, try RCIRC or ERC. XChat works fine on Windows too.
09:08kumarshantanuG0SUB: downloading mIRC and X-Chat
09:09G0SUBkumarshantanu: XChat please. mIRC is to last century.
09:09G0SUBs/to/so
09:09sexpbot<G0SUB> kumarshantanu: XChat please. mIRC is so last century.
09:09G0SUBwtf!
09:09G0SUBztyu: hey!
09:09ztyuhi
09:09ztyu.
09:10G0SUBRaynes: dude, you are breaking IRC's tradition with that overloaded command.
09:10G0SUBRaynes: please don't extend a protocol that you don't own! :)
09:10G0SUBztyu just donated to the Clojure project. Cheers to ztyu!
09:10Rayneskumarshantanu: If you already use Firefox, Chatzilla is an okay option as well. However, it isn't worth running on XULRunner if you don't. I use XChat. Very satisfying.
09:11RaynesG0SUB: But... but... :p
09:11ztyui donate to clojure , to just thank to G0SUB
09:14shantanuk_hello world (from XChat)
09:14G0SUBsexpbot: tell ztyu about clojure
09:14G0SUBRaynes: will that work? ^^^
09:14RaynesNo.
09:15Raynes$learn clojure Clojure is a programming language: http://clojure.org
09:15sexpbotMy memory is more powerful than M-x butterfly. I wont forget it.
09:15Raynes$whatis clojure
09:15sexpbotclojure = Clojure is a programming language: http://clojure.org
09:15RaynesThat's the closest you can get right now.
09:15RaynesI've got plans to improve that system.
09:15G0SUBRaynes: hmm. how do I add the tell via PM feature?
09:16RaynesLike you tried to above?
09:16G0SUBRaynes: yes.
09:16RaynesThat probably belongs in the whatis plugin. It shouldn't be exceedingly difficult. Just need a tell command that does what you want.
09:17G0SUBRaynes: great.
09:17RaynesG0SUB: http://github.com/Raynes/sexpbot/blob/master/src/sexpbot/plugins/whatis.clj This is what you're looking for.
09:17G0SUBRaynes: btw, we met at the Conj, but rarely got to talk.
09:17RaynesG0SUB: Right, we ate together at lunch, didn't we?
09:18G0SUBRaynes: I think so.
09:20G0SUBRaynes: where is the PM functionality of the bot? "$tell" will PM the recipient with the answer (if it knows about it)
09:21RaynesG0SUB: You just want to send a message where the channel is the nickname of the user you want to PM. You would do something like (send-message (assoc com-m :channel (first args)) "some text")
09:22G0SUBRaynes: you are right. are you accepting patches?
09:22RaynesAlways
09:22G0SUBRaynes: OK. I will send you a pull request in a while.
09:23RaynesNice. If you run into any problems, let me know. Recently added some multiprotocol support and broke+fixed everything. ;)
09:23G0SUBRaynes: heh
09:24RaynesI use the word 'fixed' loosely, of course.
09:47G0SUBRaynes: sent a pull request. please accept if the patch is OK.
09:47G0SUBRaynes: I looked at the sexpbot code for the first time today. very nice work!
09:51RaynesG0SUB: I'll check that out in a few. :)
09:51G0SUBRaynes: sure. take your time.
09:52RaynesLooks good.
09:53RaynesI think that brings the number of sexpbot contributors to a explosive 6. :>
09:56G0SUBRaynes: cool!
09:56G0SUBRaynes: is there a TODO list that I can target for some more serious work?
09:56RaynesG0SUB: Did you actually test this?
09:57G0SUBRaynes: yes. in my own whacky way. please use your own testbed to be sure.
09:57RaynesIt's simple enough that I'm pretty sure it works just by looking at it. My testing just consists of running the bot and running the command. :p
09:57RaynesI was just curious as to whether or not you got the bot running.
09:58RaynesMostly just to confirm that the default configuration isn't borked.
09:59RaynesI'm lazy about testing in a 'clean' setting, like a user would be on their first run.
09:59RaynesWell, I'm just lazy in general. ._.
10:00RaynesThere isn't any TODO list right now.
10:00RaynesIt's mostly just amalloy and I working on it, so we tend to keep TODO lists in our head. :p
10:00RaynesI'm sure I could think of a few low-hanging things.
10:01G0SUBRaynes: please write down all the to do items in a file and put it in the repo for others :)
10:01G0SUBRaynes: starting the bot was not hard at all.
10:01RaynesGreat
10:08G0SUBRaynes: do I have to do anything else to get the patch accepted?
10:09RaynesG0SUB: Nope. I've already pulled it into master. Just haven't pushed yet.
10:09G0SUBRaynes: oh, great. many thanks!
10:14RaynesG0SUB: A git shortlog tells me that you're the 7th contributor.
10:14RaynesPushed to master.
10:14G0SUBRaynes: interesting.
10:17RaynesG0SUB: There is a todo list in master now. I put a bit of low hanging fruit in there that you might be interested. amalloy and I will compile a more comprehensive list later.
10:18G0SUBRaynes: awesome! you rock.
10:18Raynes<3
10:25studybot_what is the difference between n and (int n)?
10:33studybot_sorry
10:33studybot_anybody here?
10:39kumarshantanustudybot_: any example?
10:40studybot_http://paste.lisp.org/display/69952
10:40studybot_I find this code through stack-overflow
10:40studybot_it seems to be written by rich hicky
10:41kumarshantanu,(type (long 10))
10:41clojurebotjava.lang.Long
10:41kumarshantanu(type (int 10))
10:42kumarshantanu,(type (long 10))
10:42clojurebotjava.lang.Long
10:42kumarshantanu,(type (int 10))
10:42clojurebotjava.lang.Integer
10:42kumarshantanuso, int coerces a number into an int
10:43studybot_yeah
10:43kumarshantanu,(type (int (short 10)))
10:43clojurebotjava.lang.Integer
10:43studybot_,(type 3)
10:43clojurebotjava.lang.Integer
10:43studybot_ahha
10:43studybot_I see
10:43studybot_so there's no difference, right?
10:43kumarshantanu,(type 55325327815637163912639129)
10:43clojurebotjava.lang.ExceptionInInitializerError
10:44kumarshantanu,(type 553253278156371639)
10:44clojurebotjava.lang.ExceptionInInitializerError
10:44kumarshantanu,(type (long 553253278156371639))
10:44clojurebotjava.lang.ExceptionInInitializerError
10:44kumarshantanu,(type (long 5532532781))
10:44clojurebotjava.lang.ExceptionInInitializerError
10:44kumarshantanu,(type (long 5532532781))
10:44clojurebotjava.lang.ExceptionInInitializerError
10:44kumarshantanu,(type (long 55325))
10:44clojurebotjava.lang.Long
10:45kumarshantanu,(type (int (long 553253278)))
10:45clojurebotjava.lang.Integer
10:45kumarshantanu,(type (int 553253278))
10:45clojurebotjava.lang.Integer
10:45kumarshantanu,(type 553253278)
10:45clojurebotjava.lang.Integer
10:45kumarshantanu,(type 55325327875843)
10:45clojurebotjava.lang.ExceptionInInitializerError
11:21jk__technomancy: ?
11:47jk__$seen technomancy
11:47sexpbottechnomancy was last seen talking on #clojure 12 hours and 26 minutes ago.
12:48jk__is this considered bad form? http://pastebin.com/6B1TWWXP
12:48jk__the call to setup() returns void, as does the call to setAuthenticationManager.
12:50jk__the function actually returns a usable repository, not a factory. bad name
12:50chouserI would use _ instead of x since you don't care about that value
12:50chouseror just move the call to setup out to before the let
12:50jk__ok
12:51jk__but having one function call after another if an individual call is just used for side effects is ok?
12:51jk__i mean, no more idiomatic way to do it?
12:51chousernot that I can think of
12:52jk__ok thanks. just trying to learn good style as i'm learning the language
12:52chouserit's ok to rely on each 'let' value being evaluated in order, and to use locals created in previous pairs
12:52jk__yes, i've seen that a lot
12:52chouseran also ok to rely on the body of a fn and the body of a let being "implicit do's" that will also happen in order
12:53jk__ok. thanks very much for the feedback
12:53chouserit's worth trying to isolate code that's stateful and messy like this, imo
12:54chouserbut no better way to do it in general.
12:54jk__yes that's what trying to do. isolate it. i think this will come up again and again using java interop
12:55chouseryes. some java libs are pretty clean -- immutable value objects, side-effect-free methods, etc. Not much value in isolating usage of those
12:56chouserbut if you can provide a function that does mutable stuff internally (because it has to) but presents a clean functional interface to the rest of your code, that's a real win.
12:56jk__that's the idea i'm going for
12:57kotarakI think the let* behaviour of let is a feature and guaranteed.
12:57jk__kotarak: what does that mean? the let* behavior?
12:58kotarakjk__: In Scheme there is let, let* and letrec. The difference between (let [a 1 b a] ..) and (let* [a 1 b a] ...) is that a in the first comes from the environment, while in the second is 1 from the first let pair. In Clojure there is only "let*": the let we know.
12:59kotarakjk__: so you can rely, that (let [a (f1) b (f2)] ..) does first f1, before f2 is called.
13:00jk__kotarak: ahh, I see. I'm new to Lisp in general and don't know Scheme . I understand what you're saying though. Thanks for explaining
13:01jk__so I guess with let* the evaluation is free to occur in any order
13:01jk__oops, i mean let
13:01kotarakjk__: In Scheme, yes.
13:01jk__(in scheme that is
13:01jk__:)
13:02jk__kotarak: one thing that really helps a lot in clojure for us newbies is the fact that there are a lot of very knowledgeable people here who are quite willing to help
13:03kotarakjk__: I remember rhickey stating in the ancient days, that he doesn't see the benefit of two let forms and that you in usually want let* anyway. So it is the default for Clojure's let and - I think - it is save to rely on this fact.
13:04kotarakjk__: Yup. Listen to rhickey, chouser, cgrand, cemerick, lpetit, ... :) Treasure chest here. :D
13:04jk__kotarak: i see. without any experience it's hard to say, but it's not inconceivable that somebody would want the other style of let. i guess that's what macros are for :)
13:05kotarakjk__: A noticeable exception to the []-binding forms (let, with-open, ...) is binding. binding in fact works like the Scheme let.
13:09raekyou can do the other let with let and destructuring: (let [[a b] [b a]] ...)
13:10raekso in clojure there is little need for having two...
13:12kotarak(defmacro let+ [bindings & body] `(let [~(vec (take-nth 2 bindings)) ~(vec (take-nth 2 (next bindings)))] ~@body))
13:12RaynesG0SUB: Actually, you're the 8th. I forgot about ninjudd's one (count 'em, one) commit.
13:14ninjuddRaynes: one commit to what?
13:14Raynesninjudd: sexpbot
13:15RaynesYou have one commit.
13:15ninjuddi also wrote the logging code, though you committed it, right?
13:15RaynesOf course, you also co-wrote the logger plugin, but we mostly exchanged that over gist and irc.
13:15RaynesYeah.
13:15RaynesYou wrote the logging code and gisted it, I fixed the logging code and committed it. We're a team. <3
13:15ninjuddso really it is two
13:16RaynesYup. I just robbed you.
13:16ninjuddlike I robbed lrenn :(
13:16Raynes:(
13:17ninjuddso he has 0 cake commits instead of 1
13:26amalloyRaynes: mind if i pull in the $tell commit to a side branch, remove some code duplication, and bring it back to master?
13:29amalloyG0SUB: that's your commit, right?
13:41miltondsilvaHi, can somebody help me with this? http://pastebin.com/ps2A8Ez9
13:55kotarakmiltondsilva: This is a gross misuse of the agent system. You shoud use a dedicated thread. (.start (Thread. #(server-requests 8080)))
13:57kotarakmiltondsilva: also for serving the request: use a custom thread pool. Not an agent.
13:58amalloyG0SUB, Raynes: i see you did that already :P. either way i've tidied up whatis.clj now: http://is.gd/izw2O
14:29LauJensenkotarak: That looks like a future to me
14:45mibnkhi just new to clojure and i have a fast question how can i execute more than one sentence inside an if form
14:45mibnksomething like this
14:46mibnk(defn a [x] (if (> x 0) ((println "Hello") (println "World"))))
14:46LauJensen,(if (odd? 3) (do (println "one") (println "two")) "its not odd")
14:46clojurebotone
14:46bobo_(do (println "hello") (println "world))
14:46clojurebottwo
14:46mibnkthankyou
14:46LauJensenmibnk: But in that case, you might want 'when' instead of 'if'
14:46LauJensen,(when (odd? 3) (println "one") (println "two"))
14:46clojurebotone
14:46clojurebottwo
14:47LauJensenIf there's not (else) clause, you get the (do) for free
14:48mibnkthanks again i was a little bit lost with that
14:55amalloymibnk: incidentally, my experience with learning lisps was like "why do i have to type this dang (do) all the time, can't the language give me some sugar for something as common as doing more than one thing"
14:55amalloyfollowed eventually by "hey, i realized i never use (do) anymore, because my programs don't have side effects and you don't need them otherwise"
15:02djinohttp://ideone.com/O5i0Q : How would I prevent this from blowing the stack?
15:03mibnkamalloy: I try to achieve that but some times is difficult
15:04pdkif you run iterate it's going to try to return everything in the sequence defined by the iterate form
15:04pdkin that case it's not just going to pass back the seq generator but instead the whole contents of the seq
15:04amalloydjino: try wrapping the remove with a doall
15:05djinoamalloy: since iterate is infinite i can't, thats the problem i cant figure out : o
15:05amalloypdk: he knows that; he's calling (nth (p)) and (take p)
15:05djinoamalloy: if I had doall'd it it would try to realise iterate
15:05amalloyyeah, i see that now
15:07mibnkdjino it works fine on my system
15:07amalloyhave you looked at the implementation in c.contrib.lazy-seqs?
15:08djinombink: Can you try it with larger indexes for nth?
15:08mibnkok
15:09djinoamalloy: well its not that i need a prime generator, just been playing and i stumbled upon this problem
15:10amalloydjino: sure
15:10amalloybut c.c probably had a similar problem
15:10amalloytheir solution might be interesting
15:11mibnkdjino: it blowed at 3800
15:11mibnkdjino: 3500 worked fine
15:11amalloyto me it looks like they're chunking it - where you're doing a (remove), they first (take n lst) so that they can doall
15:25djinowell i guess this doesnt play nice with lazyness, a doall is fine however for a fixed size seq, thanks for the suggestions
15:29kotarakLauJensen: even a future feels a bit heavy-weight. it feels like waste powering up all the return value stuff for a thread which will never return....
15:30LauJensenkotarak: I'd say its fairly idiomatic and in the context of starting a server, it hardly adds any overhead
15:30kotarakLauJensen: it's not about overhead. It just feels like waste. Ugly like (dorun (map ...))
15:31kotarakBut that's maybe the premature optimiser in me.
15:37amalloykotarak: you could optimize yourself by disabling the premature optimizer. see if that helps :)
15:37Lajlaamalloy, you are my one true love.
15:40amalloy:)
15:40jk__i've been fighting this problem for about 2 hours now! http://pastebin.com/75yvycDQ is there some trick to passing nil as a particular type for the purpose of calling some java api?
15:40amalloyLajla: and i live in san francisco, so regardless of your gender we could live happily every after
15:41Lajlaamalloy, well, I don't.
15:41LajlaTHat's an obstacle.
15:41Lajlafliebel, you live nearbye right?
15:41LajlaYOu are my one true love henceforth then.
15:41amalloyjk__: maybe try (.getDir repo dir (long -1) ^Collection nil lst)?
15:42amalloyouch
15:42jk__line 11 should be "nil"
15:42jk__i mistyped that
15:42jk__amalloy: let me try that
15:42amalloy^Collection is a type-hint, which comes reasonable close to a cast
15:45jk__amalloy: that syntax is wrong but i'm still fooling with it. was trying all sorts of type hinting earlier. the only way i ever made it call the right one is if i passed an actual instance of Collection (which I didn't want to do)
15:46amalloy&^{:tag Collection} nil
15:46sexpbotjava.lang.IllegalArgumentException: Metadata can only be applied to IMetas
15:46KirinDavePrice is wrong.
15:47amalloy&(let [x nil] ^{:tag Collection} x)
15:47sexpbot⟹ nil
15:47amalloy&(let [x nil] ^Collection x)
15:47sexpbot⟹ nil
15:47amalloyjk__: like that instead?
15:52jk__amalloy: no matching method found :\
15:54jk__amalloy: ok i give! i'm just going to pass an actual instance. i think the only diff is that the api will populate my collection rather than create one internally. in either case, the return value is a collection with the right stuff
15:54jk__i'm tempted to put that snipped in a groovy class and call that instead. took me like 2 seconds to do that in groovy :\
15:55jk__amalloy: this is svnkit i'm playing with, btw
16:05amalloyjk__: i think you have to type-hint the object you're calling on too, to make the method call be resolved at compile time (before it knows the object is going to be null)
16:06amalloy(let [^Collection c nil] .getDir ^Whatever myobj c)
16:06amalloyer, but with more parens :P
16:07jk__amalloy: lol man what in incredible PITA this has been thanks to the closeness of the API calls colliding with the dynamic typing. first time i had such a problem in my very short clojure career :D
16:07jk__i'll go back to that later. i want to get some code working right now
16:08jk__amalloy: thanks very much for the suggestions. i'll dig into that further a little later.
16:08jk__amalloy: that's one of those problems that isn't even satisfying to solve because it's just damn ugly!
16:08amalloyyeah
16:13sivajaghi everyone
16:14Pie`hlo sivajag
16:15sivajagdoes anyone know how to add git submodule to leinengen
16:21sivajagnever mind got it
16:21sivajagwe should checkout to "checkouts" folder
16:24fliebelSomeone mentioned my nick way up? I'm not able to figure out what's it about.
16:27amalloyfliebel: Lajla was asking where you live, but just for fun
16:28fliebelamalloy: I believe them knows… roughly.
16:28fliebels/knows/knowses/
16:28sexpbot<fliebel> amalloy: I believe them knowses… roughly.
16:44sivajagso relieved that I can git submodules with Lein
16:44sivajag:)
16:47MayDanielrr
17:19nickikwhere to start with emacs and commen lisp?
17:24LauJensennickik: Perhaps in #commonlisp ?
17:31raekI'm doing a macro that has multiple levels of syntax-quote
17:31raekis calling gensym myself the best way to make a unique symbol that can span two syntax-quotes?
17:34bmhhas anyone about used the QuickCheck port in ClojureCheck? If so, can you steer me to documentation?
17:42kotarakbmh: docstrings are the documentation
17:42kotarakbmh: what problem do you have in particular?
17:42kotarakraek: I believe it's the only way to span two syntax-quotes.
17:45raekyes, browsing thought the mail arhives, I come to the same conclusion
17:45raekkotarak: thanks!
17:49bmhkotarak: I'll check out the source, thanks.
18:31bmhkotarak: I'm having a bit of difficulty generating lists of a particular length. My understanding of this is: (list <key generating function> <length generating function)
18:57krumholtcan someone explain to me the difference between send and send-off? why shouldn't i use send on blocking io? if i make a thread wait with Thread/sleep should i use send-off?
19:08arrummzenI feel like being evil. How can I import all classes in a package... the import macro appears to require I enumerate all the classes I will use.
19:09raekkrumholt: the actions of agents are processed by threads in a thread pool. clojure has two thread pools: one with fixed number of threads and one with a dynamic number of threads.
19:10raekkrumholt: if you send multiple blocking action to the fixed size thread pool, they will keep all other agents from doing work
19:11raek(send = fixed size, send-off = unbounded size)
19:11raekso, you should use send-off for an action that includes a call to Thread/sleep
19:13krumholtraek: unbounded size?
19:14krumholtraek size of what?
19:14raeknumber of threads
19:15krumholtraek: ok thanks
19:16raekin the send-off case, no action will wait for a thread to become free. if there is no free thread, a new one will be allocated
19:59arrummzenDoes Clojure support C++/Java style function overloading?
20:00arrummzenIt seems to support "multimethods" but those seem to only work for overloading by argument type not argument type and argument count.
20:01dnolenarrummzen: multimethod are more general than that. They can overload on lots of things, including argument count.
20:02dnolenarrummzen: with deftype/record and protocols you can do more traditional overloading on the type of the first arg and the arity.
20:06arrummzenI have this: (defmulti show-image (fn [& args] (map class args)))
20:07arrummzenBut I keep getting errors relating to "wrong number of arguments"... I don't see why?
20:07dnolenarrummzen: what do your methods look like
20:08arrummzen(defmethod show-image '(BufferedImage String) [image display-name] ...) and (defmethod show-image '(String) [image-file-name] ...)
20:09arrummzenClojure seems to believe the wrong number of arguments are being passed to (fn [& args] (map class args)) but shouldn't that function take any number of arguments?
20:11dnolenarrummzen: does your call to the method look like?
20:12dnolenarrummzen: should maybe paste your code somewhere.
20:12arrummzen(ImageProcessing/show-image "032_0003.jpg") is the initial call.
20:18dnolenarrummzen: the problem is your dispatch values.
20:18dnolen,(= '(String) [String])
20:18clojurebotjava.lang.RuntimeException: java.lang.Exception: Expecting var, but String is mapped to class java.lang.String
20:18dnolen,(= '(String) [java.lang.String])
20:18clojurebotjava.lang.RuntimeException: java.lang.Exception: Expecting var, but String is mapped to class java.lang.String
20:18dnolenerg
20:19dnolenanyways that on my machine evaluates to false.
20:19dnolen'(String) is a list with the symbol 'String in it.
20:19dnolenarrummzen: replace '(x ...) with [x ...] for your dispatch values.
20:24arrummzenWell, that was one problem...
20:26jtokleHow would you use datatypes for something analogous to: MyClass extends AnAbstractClass implements AnInterface?
20:27chouserjtokle: extending abstract classes is about implementation inheritence, which is not supported by deftype, defrecord, or reify. You could use 'proxy' though.
20:28arrummzenhttp://pastebin.com/R6AVc62d . I'm still getting the same error java.lang.IllegalArgumentException: Wrong number of args (1) passed to: ImageProcessing$eval1701$fn
20:29dnolenarrummzen: are you 1.2.0? What dev environment are you using?
20:30arrummzen1.2.0, why does it work for you?
20:30arrummzenI'm using eclipse with counterclockwise as an environment.
20:31dnolenarrummzen: trying restarting your REPL
20:32dnolenarrummzen: I recall that redefining multimethods as you go may have issues in 1.2.0
20:32jtoklechouser: Thanks. I guess what I want is different types with the same data fields but with different implementations of some protocol
20:33jtokleI thought there might be a smart way to do this, other than writing a bunch of nearly identical defrecord statements
20:34dnolenhmm, is it possible to have a version of interleave that keeps going even if some sequences become exhausted?
20:34dnolenwell I mean I know it's possible. but is it possible to combine some standard functions together get that behavior.
20:36dnolenweave might be a cool name for that fn.
20:36arrummzendnolen: that was it.... after restarting the REPL it works. Thank you !
20:36dnolenarrummzen: np.
20:37dnolenarrummzen: that issue is fixed in 1.3.0, not sure if it'll get backported tho.
20:50DeusExPikachuanyone know how code to obtain the cookies for a secure web session so, for example I could then use htmlparser to parse a page?
21:24studybot_,(reduce #(if (even? %2) (+ %1 %2)) 0 (range 5))
21:24clojurebotjava.lang.NullPointerException
22:21rata_hi
22:21rata_I need some help
22:21rata_I'm getting this error: GC overhead limit exceeded
22:21rata_is there a way to work around that?
22:22rata_perhaps some java command line option or something like that?
22:40dnolenrata_: increase the memory to the JVM ?
23:04rata_dnolen: I'm trying with that now :)
23:13arrummzenI have an odd Java method which takes a int or an Object. How can I tell clojure to pass it an int and not an Integer?
23:16dnolenarrummzen: in 1.2.0 you can cast to a primitive int with (int x)
23:21arrummzendnolen: that didn't fix my problem, but thanks anyway =D
23:30arrummzendnolen: actually, that doesn't even work in 1.2.0. (class (int 5)) shows java.lang.Integer
23:30dnolenarrummzen: class is just casting it back to Integer
23:32dnolenarrummzen: are you calling a constructor or something?
23:32arrummzenI'm trying to use java.awt.image.ColorModel.getRed
23:32dnolenarrummzen: what's your call look like?
23:33arrummzen(let [rgb (. image getRGB x y) red (. colorModel getRed (int rgb)) ...
23:33arrummzenI want to call getRed(int pixel) but getRed(Object inData) is being called.
23:33dnolenarrummzen: try (.getRed colorModel (int rgb))
23:34arrummzenSame problem.
23:36dnolenyou need to fix getRGB as well
23:36dnolenit doesn't look like getRGB takes two arguments either, http://download.oracle.com/javase/1.4.2/docs/api/java/awt/image/ColorModel.html#getRGB(int)
23:37dnolenarrummzen: oh different object
23:37arrummzenI'm on Java 6, not 1.4.2
23:37dnolenstill, (.getRGB image (int x) (int y))
23:37arrummzenThat call doesn't have the problem. It is the getRed one which causes the error.
23:39dnolenarrummzen: what is the exact error?
23:42arrummzen#<ClassCastException java.lang.ClassCastException: java.lang.Integer cannot be cast to [B>
23:42arrummzenThe javadoc for getRed(Object) says : "ClassCastException - if inData is not a primitive array of type transferType " so I assume this is because the Object version is being called.
23:43dnolenarrummzen: I think it's trying to convert a primitive int into an array of bytes.
23:44dnolen(.getRed colorModel (byte-array [(byte 1)])) ?
23:45dnolenarrummzen: it can be done, hopefully someone else will chime in, but I gotta jet.
23:46arrummzenmeh, I'm just going to use bitwise operations to extract the RGB components myself.
23:46arrummzenThis is a typical example of Java making things to damn complicated.
23:46dnolenarrummzen: totally.