#clojure logs

2009-10-05

00:00arbschtconsider passing keyword arguments as a hash-map instead
00:01rongenreYeah I can do that also. Although it makes the function calls look a bit weird, don't you think?
00:01somniumyou could write a kwfn macro the binds them in a let for you
00:01somniumthough that might be getting carried away
00:02rongenreAh.. here I go http://groups.google.com/group/clojure/msg/51bb53ca077154f8
00:04arbschtrongenre: defnk is in clojure.contrib.def
00:04arbschtbut I've never seen it used in the wild
00:05rongenreGotcha -- trying to get a feel for what's idiomatic. Is the usual idea just not to use optional params?
00:05arbschtI have seen the hash-map of options, though, and it doesn't really look bad
00:05arbschtgenerally, optional args are taken care of with arity overloading
00:06poetAnyone using VimClojure have a problem where everything works but the local keybindings?
00:06poetfunction completion, rainbow paren, everything but the local keybindings that are supposed to be set when a .clj file is opned
00:07rongenrearbscht: thanks!
00:08arbschtclojure code tends to use simple function protocols. there's not much benefit in keyword args, since binding forms inside the function can destructure a hash-map just the same, and it's easy to construct them with literal syntax
00:09rongenreSure, or even a (let [foo (args :foo def) [...]]) looks ok
00:11arbscht,((fn [{:keys [a b]}] [a b]) {:a 1 :b 2})
00:11clojurebot[1 2]
02:54LauJensenasd
02:55LauJensenoops - Morning guys
03:17G0SUBHmm, so I am trying to parse an XML structure like this using c.c.lazy-xml http://pastebin.com/d18385f13
03:17G0SUB(zfxml/xml-> test-xml :item :email zfxml/text)
03:17G0SUB(zfxml/xml-> test-xml :item :name zfxml/text)
03:18G0SUBthese work fine for me.
03:18G0SUBbut I want to get the data out in groups all at once.
03:18G0SUBinstead of ("Foo" "Bar" "Fubar" "Baz") and ("a@b.com" "x@b.com" "s@b.com" "q@b.com"), I want it like (["Foo" "a@b.com"][][]), etc.
03:18G0SUBany tips?
03:24konrG0SUB: well, you can create a map, I guess
03:24konrsomething like
03:24konr,(map #(vec (list %1 %2)) (range 1 10) (list "foo" "bar" "baz" "bak"))
03:24clojurebot([1 "foo"] [2 "bar"] [3 "baz"] [4 "bak"])
03:25G0SUBkonr: yeah, but I was wondering if it can be avoided. I am not too well acquainted with the xml lib.
03:44Fossihi
03:47woobyhello
04:26snowwhiteIs there any debugging tool for clojure?
04:29LauJensen~google clojure debugging
04:29clojurebotFirst, out of 12900 results is:
04:29clojurebotClojure - getting_started
04:29clojurebothttp://clojure.org/getting_started
04:29Fossisnowwhite: any java remote debugger will more or less work
04:33snowwhiteFossi, ok
04:34Fossii rarely debug though. do people around here do it?
04:34Fossitests and log messages are so much more useful with a lisp imho
04:35LauJensenYea the only time I go out of Emacs is for profiling... but Im thinking now, that there probably is a 'java-profiler-mode' for emacs
04:50Raynes-I've never used a debugger.
04:50Raynes-Ever.
04:52RaynesWhoa, loloh has Factor listed in their languages, but not Clojure. O.O
04:54jdzlolwhat?
04:57Fossiohlo i guess
04:59RaynesOops.
04:59Raynesohloh*
04:59Raynesjdz: Sorry, I never even noticed I did that. It's quite late here.
05:41woobyhow would one generate a lazy sequence of random nums?
05:41woobyi think i need to use iterate but i'm not sure
05:41jdz,(doc repeatedly)
05:41clojurebot"([f]); Takes a function of no args, presumably with side effects, and returns an infinite lazy sequence of calls to it"
05:41woobyawesome thank you
05:41jdzthat was just a guess :)
05:42woobyi'm still working on my guessing skills ;)
05:47LauJensen~def memoize
06:13LauJensenWho was it that expressed an interesting in seeing an optimized version of Brians Brain ?
06:24G0SUBclojurebot: help
06:24clojurebothttp://www.khanacademy.org/
06:33namor_Hmm, #clojure has more people in it than #scala.
06:34arbschtnamor: how many bots does #scala have?
06:35namorGood question, I have no idea.
06:39wooby2 that i know of
07:10konrGuys, am I setting a constructor when I extend a class with (def foobar-extension (proxy [Foo] [] (foobar-extension ....)))?
07:12konrAlso, how can I call the superclass function?
07:12LauJensenno and you cant - if I understand proxy correctly
07:13LauJensen(doto (foo-extension. ctor1 ctor2) (proxy [foo] (bar foo)) ... will pass a constructor and return an object with the overridden method
07:22konrLauJensen: where ctor1 and ctor2 are the arguments of foo or foo-extension's constructor functions?
07:23LauJensenfoo
07:26konrso there is no way to write a constructor function for the extended class?
07:28LauJensen~proxy
07:28clojurebotproxy is <Chouser> proxy teases with its ease of use, then suddenly betrays.
07:28LauJensenProxy has some show-stopping limitations, when you need to get around them use gen-class or 'new new', which Im not is ready yet
07:29LauJensensgtzx_, licoresse and anyone else who read Brians functional brain, I have a follow up post: http://www.dzone.com/links/brians_transient_brain.html
07:31licoresseyup
07:31licoresse:-)
07:33LauJensenConstructive critisms are as always discouraged :)
07:33LauJensen(kidding ofc)
07:54licoressemy clojure does not understand transient
07:54licoresse,(doc transient)
07:54clojurebot"([coll]); Returns a new, transient version of the collection, in constant time."
07:54LauJensenplease update :)
07:56licoressetrying now
07:56LauJensenI'm just in a regular git clone && ant version
07:57licoresseI'm not that advanced
07:57licoresseafter a M-x clojure-update it's all the same
07:57LauJensenoh
07:58licoressethis is a mess
07:58licoresse*clojure-version* does not mention alpha though
07:59licoresseso I guess I need to go over to an alpha-jar or something
08:03FossiLauJensen: nice read, definitely another tool to look forward to
08:04Fossi(not being on latest/greatest)
08:04LauJensenYea
08:04LauJensenI actually thought this got into 1.0, but it seems I'm so bleeding edge I don't even notice it anymore
08:04Fossithen again we haven't even used type hints yet
08:05LauJensenwe haven't ?
08:05liwpLauJensen: have you done something to your syntax highlighting on the blog? Changed a font maybe?
08:05Fossias in, me and my collegue
08:05LauJensenliwp - Yea, font-family: mono
08:05licoresseLauJensen: It's too small
08:05liwpthe old one looks better IMO - on windows
08:05liwpthen again it's all subjective isn't it
08:06licoresseliwp: agree, on mac too
08:06LauJensenok - I changed it because of comments actually, so I'll see what people say this time
08:07liwpLauJensen: you could try not using bold faces and / or increasing the size a bit...
08:07LauJensenliwp, Could I trouble you to email me a screenshot ?
08:08liwpLauJensen: sure, give me a minute. DO I have your email address? PM me.
08:08LauJensenIf not it's in the right column on the blog
08:08liwpahh :)
08:11Fossiyeah, monospace fonts are very different size on linux/mac/win :(
08:11LauJensenSo what do people use? In Emacs I use inconsolata, but that's not gonna fly on the web
08:12Fossican't do much about it really
08:12liwpI have no idea what my emacs font is. Is there an easy incantation to find it out?
08:12liwpahh, got it
08:12LauJensenoh man that's ugly liwp
08:12liwpit's courier
08:13LauJensenFrom now on my blogposts will be a 800x9000 jpeg :)
08:14liwpI use courier on putty as well. I tried using other fonts, e.g. inconsolata, but courier seems to look better on an LCD without antialiasing or cleartype
08:14liwpI think I use monaco at home on OS X
08:21licoressehow can I stop the simulation without restarting slime?
08:21licoresseLauJensen: ^^
08:21LauJensenchange (while true...) to (while @running ..) and set a global atom to true, you can the use (ref-set! running false) to stop it
08:21licoressethx
08:22LauJensennp :)
08:23arbscht,(doc reset!)
08:23clojurebot"([atom newval]); Sets the value of atom to newval without regard for the current value. Returns newval."
08:24LauJensenthat's the one :)
08:24licoresseyou're always so helpful!
08:32mathias`I am using the clojure.contrib.shell-out package to execute a shell command. How can I make it asynchronous?
08:33LauJensen,(doc future)
08:33clojurebot"([& body]); Takes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block."
08:33chousermathias`: It doesn't support asynchronous [yet]. For now you can look at its code and use the Java libs directly as it does.
08:34mathias`LauJensen: Will try that.
08:34chousermathias`: what's your use case? I'm still thinking about the best way to add async support.
08:34ambientLauJensen thanks for yet another great blog post :)
08:34LauJensenambient, thanks :)
08:36mathias`chouser: I have a small compojure app running (started as a service, as root) and want to start mplayer within it. And when I do that I do not get the REPL back (I am using SLIME to connect to the server) until the player is done. To be able to control it (pause, quit etc) I need to get it released so that I can send it commands.
08:37mathias`chouser: future seems to work great though
08:37chousermathias`: you don't need to collect output from it along the way?
08:37mathias`chouser: nope
08:37mathias`chouser: this is just for playing movies via a small web app
08:37chouserah, yep. "future" it is. Or perhaps "agent"
08:43mathias`LauJensen: works, thanks!
08:44LauJensensweet, np
10:30rosejnCan anyone recommend a good way to block and wait for an asynchronous operation to occur? I'm writing a network client, and in some situations I want to block waiting for a response message. How is this best done in Clojure?
10:31rosejnA message handler thread gets all incoming messages, and then somehow I need to forward it to a waiting thread and wake it up.
10:31rosejnIt doesn't seem like awaiting agents or watcher functions or futures as they are setup in Clojure work for this case...
10:34rosejn?
10:34Fossipatience... ;)
10:35duck1123couldn't you just use an agent, have that agent perform the action that blocks on the IO, and then have it do something (send another agent) once it gets the data?
10:35duck1123or is that a bad thing to do in clojure
10:35duck1123um, I think it's send-off though
10:36rosejnSorry, I wasn't sure if I was connected to the room since it was so quiet...
10:36rosejnThe problem is that there isn't an action to perform
10:36rosejnI need to wait on a network packet
10:37rosejnso I can't use a future or an agent, because there isn't any code to execute.
10:38rosejnI can just use something from Java, like wait/notify or some kind of java.util.concurrent queue or something, but I was wondering if there was something that would be cleaner using clojure constructs...
10:39cgrandrosejn: promises?
10:39cgrand,(doc promise)
10:39clojurebot"([]); Experimental. Returns a promise object that can be read with deref/@, and set, once only, with deliver. Calls to deref/@ prior to delivery will block. All subsequent derefs will return the same delivered value without blocking."
10:39cgrand,(doc deliver)
10:39clojurebot"([promise val]); Experimental. Delivers the supplied value to the promise, releasing any pending derefs. A subsequent call to deliver on a promise will throw an exception."
10:39rosejnawesome!
10:40rosejnExactly what I was looking for.
10:40rosejnThanks cgrand. I guess I'd need to be checking diffs of the git tree to know about this?
10:41rosejnIf only it had a timeout option...
10:44cgrandrosejn: you can combine future and promises to mimick timeout
10:44duck1123hmm... You could send off an agent thet sleeps, then tries to deliver a null value to the ref. (catching the error on both sides)
10:46cgrandrosejn: (.get (future @my-promise) timeout unit)
10:47rosejnvery cool
10:48rosejnI hadn't thought about composing the reference type functionality like this... let alone promises. Thanks
10:52cgrandrosejn: or you can poll the future with future-done?
10:53rosejncgrand: how do you know about all of these secret functions?
10:55rosejnI guess I should be perusing core.clj...
10:55Fossieverybody should :D
10:56cgrandrosejn: read core.clj once and then stay up to date by reading commit logs and grepping irc logs -- it works for me
10:57Chousukeheh
10:58rosejnsounds good.
11:02ngocHow to compile a Clojure code to a class that has a static "main" method, so that I can run the method from command line?
11:03tomojngoc: see http://asymmetrical-view.com/2009/06/22/executable-clojure-jars.html
11:07vyngoc: Also see http://clojure.org/compilation
11:10ngocThank you, vy's link is much easier to follow
11:32ngocHow to access a static class inside a class? Like this one: http://jboss.org/file-access/default/members/netty/freezone/api/3.1/org/jboss/netty/handler/codec/http/HttpHeaders.Names.html
11:34ngocNames is not a function, so HttpHeaders/Names does not work
11:35stuartsierraThe real Java name for that class is HttpHeaders$Names
11:55ngocstuartsierra: Thanks a lot, this is really tricky
11:56stuartsierranp
12:04ngocWhen doing "assign then process then assign then process", I use (let [x = 1, y = 2...] (process1) (process2) ...). But this seems to create too many nested "let"s. How to solve this problem?
12:16stuartsierralet is sequential
12:16stuartsierra(let [x 1, y (process1 x), z (process2 y)]...)
12:24Chousukeif you don't need the intermediate values, you can do (-> x process1 process2) too
12:24Chousukeor just (process2 (process1 x)) :P
12:24snowwhiteHow can i check if "foo" is present in '("bar" "foo")
12:25Chousukeanyway
12:25snowwhiteChousuke, ?
12:25Chousukesnowwhite: you can use the .contains method
12:25Chousuke(provided by the Collection interface IIRC)
12:25snowwhiteChousuke, checked it only works on maps?
12:26Chousukenot contains?, .contains
12:26ngocChousuke: Do you mean (let [x 1, y (process1 x), (-> x process1 process2)]...) is valid? Sometimes I do not want to assign the result to anything.
12:26Chousuke,(.contains '("foo" "bar") "foo")
12:26clojurebottrue
12:27Chousukengoc: no
12:27snowwhiteChousuke, contains?
12:27Chousukesnowwhite: "contains?" does something entirely different from .contains
12:28chouser,(contains? #{"foo" "bar"} "foo")
12:28clojurebottrue
12:28chouser,(contains? '("foo" "bar") "foo")
12:28clojurebotfalse
12:28ngocChousuke: How to write like in C: x = 1, y = 2, do_some_thing(x, y), z = 3, do_some_thing2(y), ...
12:29mtm'contains?' vs. '.contains' seems to be a common point of confusion
12:29chouserngoc: you really don't care about the return values of the do_some_things? They're side-effecty?
12:30ngocyes
12:30Chousukengoc: side-effects are generally bad, but if you don't care about the return values, you can assign them to _
12:30Chousukewhich conventionally means "I don't care"
12:31Chousukeeg, (let [x 1, y 2, _ (evil-fn), z (+ x y)] ...)
12:33ngocFor serial programs, is "let" the most used form in Clojure?
12:33Chousukelet is very common in any kind of program :P
12:34Fossiand yet, you wouldn't need it at all
12:34Chousuketrue. you can use fn to do most of what let does
12:35danleimost?
12:35Chousukenot all, because fn doesn't support primitive locals.
12:35danlei"primitive"?
12:35Fossi"int" etc
12:35Chousukeas in, not Object or descendant :P
12:35technomancydanlei: unboxed
12:35danleiah, ok
12:36tomojngoc: serial programs? :(
12:36ngoctomoj: I mean x = 1, y = 2, do_some_thing(x, y), z = 3, do_some_thing2(y), ...
12:36Fossiimperative
12:36ngocI feel that most programs are in this way
12:37Fossingoc: why use a funtional language then?
12:37Chousukemost programs in Clojure should *not* be like that. except locally :)
12:37Chousukeyou do need some side-effects for every program
12:37Fossiwith a very good escuse
12:38Chousukebut it's not difficult to keep most of the code functional.
12:38Chousukewell, hm. not after you get used to it, at least :P
12:38tomojlet is such a beautiful thing
12:38tomojI feel you are trying to rape it
12:39Chousukengoc: let is sometimes useful like that, but you shouldn't see it as a tool to write imperative programs in Clojure.
12:39raek(do (side-effects1) (side-effects2) ...) is common when interfacing with imperative code
12:39raeklike printing or using java classes
12:42ngocThank you all, I think I must write more in Clojure to feel convenient with the syntax
12:43ChousukeI don't think the syntax is the issue. what you need to learn is a whole different way of thinking about your programs :)
12:44Chousukefunctional programs don't tell the computer what to do, they tell it what you want. :P
12:45chouserI've heard that before, but I'm still not sure I buy it.
12:45Chousukeof course, this being the real world and all, you often need to pay attention to what the computer actually does, too, eg. when dealing with performance.
12:55ambienti dont see any other differenct in functional programming except that mutation is just an implementation of time. with functional programming one has to model time separately
12:56ChousukeI don't know if imperative programming languages model time either :/
12:56Chousukeit just exists, and you have to deal with it.
12:56ambientwell they have state and state by definition exists in a point of time
12:57ChousukeRich makes a good point in his newest presentation why having variables is a broken model for state :)
12:58jfieldsI'm trying run a Clojure script with java -classpath "/path/to/jars/*:" clojure.main my_file.clj and I get Exception in thread "main" java.io.FileNotFoundException: my_file.clj (No such file or directory) - my_file.clj is in a jar file that's in the dir that my -classpath points to. Any ideas?
12:59chouserjfields: try @my_file.clj instead
12:59ngocHow to refer to Java's "this" in a proxy method?
12:59Chousukengoc: it's "this"
12:59ngoc:D
12:59Chousukengoc: the symbol is implicitly bound inside a proxy form
13:00jfieldschouser: thanks
13:00clojurebotchouser is ruthless about breaking other people's code
13:00chouserclojurebot: botsnack
13:01clojurebotthanks; that was delicious. (nom nom nom)
13:01rsynnottheh
13:03ambienti wish there was a video archive of clojure talks. i hate to use flash :/
13:03technomancy+1
13:03technomancysorry, inc
13:04chouserhow would the archive be distributed?
13:04ambientbittorrent if no else
13:04chouserah
13:05technomancyyoutube and bitly let you download the videos
13:05technomancywell, you have to use a script for youtube, but it beats watching it in the browser
13:07ngocWhy when declaring a namespace, we write (ns a.b), but when using a namespace we write (use 'a.b) (with a quote?)
13:07technomancyngoc: ns is a macro, while use is a function
13:07technomancyso the args to use get evaluated
13:08ngocWhy not make them all macros or all functions? So that Clojure looks consistent.
13:09technomancyngoc: you're not supposed to use "use" directly; you should use the ns macro
13:09sproingiens is the thing making it consistent :)
13:12hiredmanblip.tv lets you download the talks as well
13:12hiredmanthe only clojure talks you cannot download are the ones on infoq
13:12chouserimport used to be a function but is now a macro
13:14chouserThe package-importing API isn't finallized yet, I think -- there's been some talk of replacing both 'require' and 'use' with something else, maybe called 'uses'
13:14hiredmanchouser: it's finalized for 1.0
13:14chouserhiredman: so true!
13:14chouserprobably for 1.1 as well
13:29danleiwhat would the semantics of that "uses" roughly be like?
13:29danleisince require and use are quite distinct to me
13:30chousermost of what use and require do are in common (finding a clj or class file for a given namespace, loading that and making the namespace available)
13:31danleiwell, use is a superset of require, ok
13:31chouserboth even support :as for aliasing the namespace
13:31danleibut still they do different things and I can't imagine atm how they shall be merged
13:31danleior, if it's feasible to merge them
13:32danleiI always felt about require more as a "module" thing, whereas use is more "namespace" to me
13:32danlei(not well said, but maybe it's comprehensible)
13:33chouserso the weaknesses I see are (1) use by default refers in all the foreign var names, but I think this should be discouraged, and (2) require doesn't provide any way to refer in specific vars
13:34chouserso I'd want a single thing that discourages refering all vars but makes it easy to refer specific vars and/or alias the whole namespace.
13:34danleihm ... I do follow clojure-user but somehow I completely missed this discussion :)
13:35danleiI see the point, though
13:35konrThe first version of my code has 109 lines. A simple java widget that I'm import has almost the triple.
13:35chouserthere's also been talk of having a default alias per namespace, so perhaps (uses clojure.zip) would be default use the alias zip ... and I like that except that then new words may show up without ever explicitly declaring their origin.
13:35konr*ing
13:36chouserkonr: but half the .java lines are blank except for close-curly-brace. You might have to let those slide. :-)
13:36danleiI somehow like that idea (default alias)
13:37danleion the otherhand, typing :as ... doesn't bother me that much
13:37chouserdanlei: this conversation has come up once or twice here -- I don't think it's ever made it to email.
13:37danleiah, ok
13:37G0SUB_Is there any way to write a http client which downloads files in parellel using agents?
13:42danleichouser: about use referring all vars; how about a more "traditional" approach, in that vars are local to a namespace and must be exported in order to be referred by use?
13:42danleis/exported/explicitly exported/
13:43chouserdanlei: well, that's sort of how it is now. defn creates a "public" var, and defn- a private one -- only public vars are pulled in by 'use'
13:43danleiyes, but I'm talking about switching the semantics of defn- and defn
13:43danleior intruducing an (export ...) facility
13:43chousermy problem with it is if you 'use' a namespace (or worse a few of them) and then I'm trying to read your code, I can't tell what most of your functions are.
13:44chouserthat is, I read (fix-up foo) and I have no idea which namespace is providing fix-up
13:44technomancyslime helps a lot with that
13:44stuartsierraGOSUB_: that's exactly what clojure.contrib.http.agent is designed to do
13:44G0SUB_stuartsierra: cool.
13:44danleihm ...
13:45chousertechnomancy: yes, once you've downloaded and installed all the dependencies, and loaded up the source you're trying to read, right?
13:45technomancychouser: well that's a whole nother mess
13:45technomancya lousy build process is orthogonal to readability
13:46technomancynot that I don't think that's important; it bugs me how people act like it's not a problem
13:46chousermy point is a perfect build process is orthogonal to readability. :-)
13:47technomancyI do agree that it's better to be readable to the un-augmented reader as well; I'm just saying what works for me.
13:48chousertechnomancy: I'm looking forward to someone solving the dependency and build problem. But even then, all it takes is for some code I'm trying to help with or borrow to use a single proprietary namespace and a few 'use' calls, and I no longer have any clue at all what's going on.
13:49technomancyyeah. I tend to do that for "glue" namespaces only. (the shell-zapper namespace calls shell commands on zap-related data, etc.)
13:49danleichouser: I guess I'd prefer aliases to explicitly listing all imported vars as far as that is concerned. I still think that making exported vars the special case and private the default would be feasible.
13:50chouserdanlei: I don't have an opinion on that -- either default seems fine to me at the moment, I would just like people to be explicit about where they're getting their functions from.
13:51danleichouser: I see ... I already have that problem in my mud client, which is split in 5 namespaces, and I think I'm going to switch to short aliases
13:52chouserdanlei: yes, I find that to be a nice solution for app-specific namespaces. 3-letter (or even 2- or 1-letter) aliases
13:53danlei*nods
13:56danlei(btw, that's one thing I really dislike about CL's packages: aliases are there written in the package definition, not when using that package)
14:00G0SUB_stuartsierra: is it possible to somehow put some extra meta data in the http-agents? I could use that info in the handler to determine the file name to save the reponse to.
14:10jfieldswhat's the correct way to convert "2" to 2?
14:10jfieldsInteger/parse?
14:10drewr,(Integer/parseInt "2")
14:10clojurebot2
14:10LauJensen,(Integer. "2")
14:10jfieldsthanks.
14:10clojurebot2
14:10drewr,(type (Integer/parseInt "2"))
14:10clojurebotjava.lang.Integer
14:11stuartsierraGOSUB_: not sure what you mean
14:11drewroh I didn't realize there was constructor for string
14:12G0SUB_stuartsierra: the handler function takes only one arg (the agent). I am dealing with many agents and want to save each response in a different file.
14:13G0SUB_stuartsierra: for that purpose I thought I would keep some extra data in the agent itself.
14:13G0SUB_stuartsierra: right now, I am doing this (:file-name (:clojure.contrib.http.agent/options @ag))
14:14G0SUB_stuartsierra: to access the file name. is there a better way?
14:14stuartsierrahmm, I intended the agent to be an opaque object.
14:14G0SUB_I need to download data from a bunch of URLs.
14:14stuartsierraI'd recommend making your handler function a closure, and creating it with the file name
14:14G0SUB_stuartsierra: makes sense.
14:20woobyhas anyone tinkered with neural networks in clojure?
14:22G0SUB_stuartsierra: worked fine. many thanks for the awesome work.
14:23stuartsierrawelcome
14:32namorHmm, why does println not work from within an agent?
14:32clojurebothttp://clojure.org/rationale
14:33chouser,(let [a (agent 42)] (send-off a println))
14:33clojurebot#<Agent@916ab8: 42>
14:33chouserhm. worked here.
14:33chousernamor: happen to be using slime?
14:33LauJensennamor, in SLIME it'll show up in the *inferior-lisp* buffer
14:33namorAh, that's the reason! Yes, I'm using slime. Thanks.
14:34jfieldsis there something in clojure similar to Ruby's array.join?
14:34technomancyjfields: str-join in contrib's str-utils, I think
14:34jfieldstechnomancy: thanks
14:35chouserjfields: or join in clojure.contrib.str-utils2
14:35LauJensen,(apply str (interpose "," ["foo" "bar" "baz"]))
14:35clojurebot"foo,bar,baz"
14:36hiredmanchouser: clojurebot's *out* and such are setup in a binding, so you need to lexically capture and setup a new dynamic binding in the agent action
14:36LauJensenjfields, or roll your own
14:36chouserhiredman: yeah, I figured.
14:37hiredmanI still wading through the evolution of lisp
14:37hiredmanI am
14:38G0SUB_stuartsierra: is there any way to limit the number of agents running in parallel? the webserver supports upto 15 parallel connections.
14:39stuartsierraGOSUB_: not explicitly. The Clojure agent thread pool will limit it to something like 2 * number_of_cores, though
14:39chouserbut that limit is only for 'send' not 'send-off'
14:39chouserno limit at all on 'send-off'
14:40stuartsierraoh, then never mind
14:40G0SUB_stuartsierra: that formula doesn't seem to be working, as the server bails out quickly.
14:40stuartsierraIf you need to control the number of agents/threads, you're probably better off creating your own fixed-size pool of agents and calling an HTTP client (like Apache's) within the action functions.
14:41G0SUB_stuartsierra: I can understand. but that's too much pain for an one-off thing like this.
14:41stuartsierraI don't know what else to offer.
14:42stuartsierragot to go, for now
14:42G0SUB_stuartsierra: see you.
14:43G0SUB_Is partition lazy?
14:43chouserG0SUB_: yes
14:43G0SUB_cool
14:45kotarakWhen was intern added?
14:46kotarakchouser: neat, alter-var-root trick, btw. :)
14:46chouserI think it's very old
14:46chouseritern, I mean. alter-var-root is newish
14:46kotarakHmm.. I would have expected it the other way around. alter-var-root old and intern new...
14:46chouserintern is in 1.0 -- you need more detail than that?
14:47kotarakNo.
14:47kotarak:)
14:47chouserhm, alter-var-root is in 1.0 as well. :-)
14:49chouser...and you may be right. "added intern" Nov 26 2008
14:52chouseralter-var-root showed up with "isa-based multimethods, a la carte hierarchies" Jul 28 2008
14:53kotarakHehe... I was right for some suitable definition of "new". ;)
14:55G0SUB_I have a vector of agents. how do I run await on them?
14:55G0SUB_(await [vec1 vec2]) gave an error
14:55G0SUB_(await [agent1 agent2]), rather
14:57hoeck1GOSUB: maybe: (doseq [a agents] (await a))
14:58G0SUB_hoeck1: hmm, would have been great if the vector could be spliced somehow and passed to await all at once.
14:58meganeor (apply await vec-of-agents)
14:59G0SUB_megane: better
15:01chouserah, the implementation of await is so beautiful and simple
15:04kotarakWell, it certainly is asynchronous.
15:09drewrdoes clojure.main prefer class files over clj?
15:09hoeck1chouser: somehow, I never really enjoyed reading other peoples code, clojure changed this for me by 180 degrees
15:09kotarakdrewr: it prefers clj if they are newer. If reading from a jar, I think, it always prefers clj.
15:10kotarakdrewr: at least there was some issue, that, when reading from a jar, it prefered always on over the other. But it may also be the other way around...
15:12drewrkotarak: yeah, I was thinking in a jar
15:12drewrconfusing that it's not consistent
15:17rosejn,(doc use)
15:17clojurebot"([& args]); Like 'require, but also refers to each lib's namespace using clojure.core/refer. Use :use in the ns macro in preference to calling this directly. 'use accepts additional options in libspecs: :exclude, :only, :rename. The arguments and semantics for :exclude, :only, and :rename are the same as those documented for clojure.core/refer."
15:43Jetienhi! is there a reason why the PersistentQueue hasn't made it to the standard api yet?
15:47chouserJetien: my understanding is that it could be easily abused with polling and multi-threading.
15:48chouserI think it may also be that there are plans for more general queuing API, and I'm not sure how that might influence how PersistentQueue is exposed.
15:49chouserbut using PersistentQueue/EMPTY and conjing onto it should be pretty stable.
15:49Jetienit's just that sometimes it's mentioned in the api - i.e. in the doc for (peek) - but you can't easily create one
15:49Jetienyeah, found your post http://markmail.org/message/brvozelsgmr5a3ba :)
16:06ambienthoeck1 what have you read? i'm thinking that would be a good way to learn clojure for me also
16:08arbschtambient: clojure core is a good read
16:09hoeck1ambient: clojure code
16:10hoeck1ambient: clojure.* and clojure.lang.*.java, especially the Persistent* data structure implementations
16:11ambientok, will do
16:12woobyfor something like a condp, is there a way to do some kind of pattern matching?
16:13woobya la scala's _
16:13kotarakwooby: there are libraries, but Clojure does not provide pattern matching out of the box. let-like things provide destructuring, though.
16:14kotarakwooby: what do you want to do with condp? Maybe we can give you a tip
16:15woobykotarak: cool thanks, here's what i'm playing with: http://gist.github.com/202421
16:18woobykotarak: by the way, are you the vimclojure guy?
16:18kotarakwooby: And you want more something like #(condp = [(mod % 3) (mod % 5)] [0 0] ... [_ 0] ... %)?
16:18kotarakwooby: yes
16:18woobykotarak: thanks! it's awesome
16:19kotarakwooby: good to hear you find it useful. :)
16:19Guest92834vimclojure <3
16:19clojurebotvimclojure is http://kotka.de/projects/clojure/vimclojure.html
16:20woobykotarak: and yes... that's how i'd go about it in scala more or less
16:20kotarakwooby: No. That's not possible in Clojure. At least not that I am aware of...
16:21Chousukeanything is possible with enough macros :)
16:21woobythat's true
16:21kotarakChousuke: hehe, yes. And I know there are libraries doing that.
16:21woobythe whole macro thing has been mindblowing
16:22woobyi'd never gotten far enough with lisp to get into them... been enjoying the holloway book
16:22Chousukesyntactic abstraction is neat, yeah :)
16:25woobyi ran into something the other day i thought might be related
16:25woobya macro called condt
16:25woobybut i can't find it now
16:25woobyanyone heard of it? i think it's in contrib somewheres
16:25kotarakit's in clojure.contrib
16:26kotarakIt uses stuartsierras template thing, IIRC.
16:26kotarakIt was a possible other version for condp.
16:26kotarakBefore condp was included.
16:27woobyi see
16:39technomancyis there a function that combines these two calls? (var-get (ns-resolve 'my-ns 'foo))
16:39kotarak@(ns-resolve 'my-ns 'foo)?
16:39technomancy(and don't say comp) =)
16:39technomancyyou can deref vars?
16:39kotarakyes, think so.
16:40technomancywho'd of thought.
16:40technomancythanks
16:41kotaraktechnomancy: http://groups.google.com/group/clojure/browse_frm/thread/603c9e832e855b20 scroll down to Stephen's reply.
16:45ChousukeVars are one of the reference types, so I suppose it makes sense that you can dereference them. :P
16:45Chousukemakes me wonder why there is a var-get though.
16:45Chousukesince @ works
16:46technomancyI never thought of them as references, but it makes sense
16:46technomancyI guess I don't work with raw vars hardly at all
16:46kotarakChousuke: maybe it predates the IDeref stuff?
16:46Chousukeprobably
16:46kotaraktechnomancy: Rich called them in his recent infoq talk a "special case". (or something along the lines...)
16:47kotarakI hardly ever use Vars besides definitions.
16:47perdalumI've just tried to run a simple example from clojure-neo4j, but I get a java.lang.NoClassDefFoundError: javax/transaction/TransactionManager (NO_SOURCE_FILE:0) error in the REPl. Any ideas of what I'm doing wrong?
16:47kotarak(There were some cases in the Compiler for the line info of the VC Repl, but that is exceptional case, I guess)
17:01perdalumI thought that javax.transaction.* was available without any special (imports …)?
17:03perdalumand why can't I import it with (import 'javax.transaction.TransactionManager)? Well, it'll have to wait until the Sn rises again...
17:11sfuenteshey chouser
17:11chousersfuentes: hi [I'm barely here]
17:14sfuenteswas just curious if you have completely abandoned any use of scala
17:18ambientcapitalization is just useless metadata, really
17:19sfuentesambient: can be classified as shouting ....
17:20Chousukeit does make a difference in real writing though :P
17:21chouserit helps differentiate chouser from Chousuke
17:22kotarakpfff.. not for Colloquy :/
18:02sfuentesits so quiet in here
18:05raekis there an opposite to (filter)?
18:05chouserremove
18:05raekah, thanks!
18:06hiredman(filter (comp not …
18:07technomancyisn't there already an HOF for (comp not %) ?
18:07technomancycomplement
18:08hiredmancomp not is shorter
18:08technomancytrue
18:09sfuenteschouser: so any comment to the scala question?
18:10chousersfuentes: yes, abandoned scala
18:10hiredmanfor great justice
18:15ambientyou know what you doing.
18:23woobyso i'm working on a bitty http server here, running into some io situation if anyone would care to help
18:23woobyhttp://gist.github.com/202551
18:24woobyi'm not getting anything from the input stream until the client kills the connection... is this a buffer flush situation?
18:24woobythanks in advance for any help
18:34hiredmanwooby: println is waiting to realise the entire lazy-seq
18:35hiredman(doseq [line (line-seq rdr)] (println line))
18:35woobyhiredman: i tried throwing a doall in there to no avail... is there a preferred way to do it?
18:35woobyaha
18:36hiredmanprintln is trying to print the whole seq at once, so it is waiting until the seq is complete
18:36woobyi see
18:36woobyand that works perfectly, thank you sir
18:36hiredmanmy pleasure
18:47technomancyI hate it when a macro-expansion runs, but it doesn't work as a regular macro call. =\
19:01hiredmandid you see the other day where the dude was makeing symbols that started with a colon in his macro? and then expansion of his macro expected keywords, so it failed to run, but of course when he pasted the expansion it worked, because the reader read the symbols starting with a colon as keywords
19:01hiredmanamazing
19:11chouserhiredman: that's a bit freaky. It'll be nice to have such kinks worked out
19:12hiredmanchouser: worked out as in not let people make symbols that start with colons?
19:14woobyhiredman: so, the part of the seq i'm trying to realize is the first element... not sure how to do it
19:15chouserright
19:15woobyi have this: (doseq [path (first (line-seq rdr))] but it's unrolling the first line into a character for each body call
19:15hiredmanright
19:15hiredmanforget the doseq
19:15woobywhich makes sense i suppose, but since doseq itself returns nil... not sure how i get at that first line
19:15hiredman(first (line-seq rdr))
19:16hiredmanthat will return the first line "foo" which is handed off to doseq in your example there
19:16hiredmanand doseq calls seq on it and gets (\f \o \o)
19:16woobyoh wow, duh
19:16hiredman:)
19:17woobyi was getting all caught up in forcing it but i guess if i just ask for the first it hooks me up
19:17woobythanks again man
19:17woobythis is so much fun
19:18lisppaste8technomancy pasted "bizarre binding behaviour" at http://paste.lisp.org/display/88259
19:18technomancythat snippet results in "Var minions/info is unbound."
19:18technomancyor I guess user/info if you run it there
19:18technomancybut clearly binding is getting called
19:19hiredmanlisp paste error
19:19technomancyweak sauce. here it is again: http://p.hagelb.org/bizarre-bindings.html
19:21sfuentesits very uncommon to try to do OOP in clojure, correct?
19:21dysingerno
19:21dysinger:)
19:21hiredmanunfortunately not
19:22dysingerwhat I meant is that java interop is OOP
19:23hiredmantechnomancy: info# or ~'info in the macro
19:23hiredman~'info I guess
19:23clojurebotIt's greek to me.
19:23hiredmanclojurebot: buzz off
19:23clojurebotNo entiendo
19:23technomancyhiredman: yeah, we want symbol capture I guess is the problem
19:24sfuenteswell i mean "pure" clojure ...
19:25dysingersfuentes: yeah I haven't seen any OOP clojure
19:25sfuentesok. thought so, but was curious.
19:25hiredman~google clojure socrates
19:25clojurebotFirst, out of 46 results is:
19:25clojurebot#clojure log - Dec 01 2008
19:25clojurebothttp://clojure-log.n01se.net/date/2008-12-01.html
19:26hiredmanha ha
19:26technomancyhiredman: ~'info just makes it bind info in the caller namespace rather than the ns that contains the macro, right?
19:26technomancyif you're in the same ns, it shouldn't make a difference
19:35woobyis there a way to get the argument list as a vector?
19:36lisppaste8danlei pasted "untitled" at http://paste.lisp.org/display/88261
19:36danleioh ... too late
19:36hiredmantechnomancy: eh?
19:37hiredman(binding [~'info @(ns-resolve the-ns# 'info)] …)
19:38danleiwell ... look at my paste
19:38danleiisn't that what you wanted?
19:38danleiI'm not sure, but just 'info would expand to user/info
19:38danleiand I'm not sure if that's wanted
19:39hiredman,`'info
19:39clojurebot(quote sandbox/info)
19:39hiredmanhmmm
19:39danlei`'~'info
19:39danlei,`'~'info
19:39clojurebot(quote info)
19:39danleiugly as hell, but ... *shrug*
19:40technomancyah; quote-unquote-quote on the _other_ info
19:40technomancygotcha
19:40technomancywow
19:41danlei:)
19:42technomancywhat's the difference there then?
19:42technomancythey look like they macro-expand to the same thing
19:43hiredmanreally?
19:43technomancyaccording to macroexpand-1
19:44danleiwhat exactly expands to the same thing?
19:44technomancy'~'info vs 'info
19:44danlei'foo -> user/foo, ~'foo -> foo, '~' -> 'foo
19:44danleiat least in my macroexpand-1
19:45hiredmantechnomancy: it's syntax quote that qualifies symbols
19:45hiredmanso you need to include syntax quote (like in the macro) to see what is going on
19:45hiredman,`info
19:45clojurebotsandbox/info
19:45hiredman,`~'info
19:45clojurebotinfo
19:46hiredman,`'~'info
19:46clojurebot(quote info)
19:46hiredmanhmmm
19:46danleihmmm?
19:47hiredmanI don't think you need '~' there
19:47hiredmanjust ~' again
19:47danleihm
19:47danleiwell, if it should expand to 'foo, then you'd have to, I guess
19:47hiredman,(cons '2' (seq 4))
19:47clojurebot(2 seq 4)
19:47danleiand ns-resolve takes a symbol
19:47technomancyhiredman: cool; thanks for the explanation
19:47technomancyyeah, I need the double-quote
19:48hiredmandanlei: ooooh
19:48hiredmanmacros :)
19:48danlei:)
19:48technomancyjust when you think you understand 'em...
19:48danlei... you should use macroexpand ;)
19:49technomancydanlei: macroexpand told me it was just info
19:49technomancynot user/info
19:50danleiI just wanted to make your sentence complete :)
19:50technomancyoh... crap
19:50danleiin your case it was ` that caused confusion
19:50technomancyslime's macroexpand does the wrong thing
19:50technomancyit conflates user/info with info
19:50technomancygah!
19:50danleihuh?
19:51sfuentesanyone use a mac in here?
19:51technomancydanlei: slime's macroexpand gives me (do (binding [info @(ns-resolve 'clojure.contrib.logging 'info)] info))
19:51technomancywhere the second-to-last info there is actually 'user/info
19:51technomancyI guess it assumes they're the same thing.
19:51technomancyyuck
19:52danleiI just tested on cygwin, latest slime and it does 'foo for the '~', and user/foo for plain 'foo in the macro
19:52danleiso it works here
19:53technomancydanlei: using C-c RET?
19:53danleiwell, M-x slime-macroexpand-1
19:53technomancylooks like the same thing
19:53technomancyweird
19:53technomancyare you on clojure 1.1?
19:54danleibuilt it yesterday
19:55danleibtw is there a way to get the clojure version from the repl?
19:55technomancy,(clojure-version)
19:55clojurebot"1.1.0-alpha-SNAPSHOT"
19:55danleiah, thanks
19:55technomancydanlei: quite strange; I can't duplicate that behaviour.
19:55danleihm
19:56danleistrange indeed
19:56danleiclojure is alpha-snapshot, cygwin emacs, slime/swank-clojure/clojure-mode built yesterday or the day before
19:57technomancydanlei: jochu's swank-clojure or mine?
19:57danleijochu's
19:57technomancyhmm... I haven't been paying attention to his
19:59danleiI'll double-check, just to be sure
20:00danleidefinitely works over here
20:00technomancyI need to take a look at his branch anyway.
20:01danleihe recently merged with stuart(?)
20:01technomancyyeah, he pulled in a big wad of maven dependencies
20:01danleiyes
20:01technomancythat's why I've been putting it off. =)
20:01danlei:)
20:01technomancy(I like maven better than the alternative, but you can use maven and keep it simple.)
20:01danleiI had some trouble yesterday
20:02danleibecause I don't like that clojure-install stuff, and don't know much about maven
20:02danleithen I got it to build, but my completion was gone
20:02danleidon't ask me how I got it working ...
20:02danleibut now it works again
20:03technomancyyou just like handling the checkouts yourself, or is it something else about M-x clojure-install?
20:04danleiwell, it said my clojure was already installed and broke of. besides, I want to know what's going on, and I connect via swank.swank/server-start anyway
20:05danleiso I just want to build my swank.clojure.jar and that's it
20:06danleiswank.swank/server-start & slime-connect, to be correct
20:06danlei*start-server
20:08danleibut I'm still not sure why my completion wouldn't work
20:09danleiI think it was that ;(remove-ns 'swank.commands.completion) line in swank.commands.completion, but I'm not sure
20:09danleirebuilt it after messing around and it worked
20:22danleitechnomancy: btw. are you aware of the (read)/(read-line) problem under win? If I do a (read) or (read-line) in the slime-repl, It will hang
20:23technomancydanlei: it's not just a windows thing; swank just plain doesn't connect *in* right
20:23danleihm, is there a way to get around that?
20:23technomancyprobably... I kind of inherited swank-clojure without really understanding large portions of it
20:23clojurebotclojure is a language to use if you want to up your game
20:23technomancyit could be trivial to fix; I just haven't written any programs that use *in* yet. =)
20:23danleiI see
20:24danleiok, I don't understand large portions of swank-clojure either atm
20:24danleibut if I get the time to investigate and find a solution, I'll let you know
20:24technomancyI think only jochu does, and he doesn't write clojure any more. =\
20:24technomancycool
20:25danleiit used to work, some time ago
20:25danleianyway, I think I should call it a day
20:39slashus2What happened to jochu?
21:56somniumis anyone aware of any projects or wrappers for BerkeleyDB? I found one mailing list post but the repository seems to have vanished.
21:56somniumjust wondering before I start rolling my own
23:36hiredmanclojurebot: tupac is <reply> when I write functions I go blind and let the lambda do its thing
23:36clojurebotOk.