#clojure logs

2010-01-16

00:38Apage43mm.
00:39Apage43Niftily, calling .invoke on clojure function from within Velocity Template Engine just plain works.
01:47ndimidukI'm working on some java interop. How do I specify as metadata that a function parameter should be of type Class[] ?
01:48ndimiduk(defn -init [#^Class[] types] ...) is roughly what i'd like to express
01:48ndimidukor do constructor argument type lists go somewhere else?
01:50qbgDoes an array of objects not work for you?
01:50ndimiduki suppose it could
01:51ndimidukthat would make the class less clear for java consumers
01:54ndimidukoh, i should clarify: this is extending a base class which has multiple constructors of single argument with differing types
01:55ndimidukso i'd like the appropriate version of -init to be called based on which constructor is invoked
01:56Apage43ndimiduk: perhaps you'd do well to write some 'briding' classes in Java, since it sounds like you aren't exposing a terribly 'lispy' API anyhow.
01:57ndimidukhmm
01:57Apage43*bridging
01:58ndimidukright
02:00ndimidukah, gen-class says i should specify :constructors {}
02:00ndimidukso would I say :constructors {[] [String] [Class<>]} ?
02:56rikthevikhey, i'm having trouble getting lein to run my tests
02:56rikthevikCaused by: java.lang.Exception: No such var: clojure.test/successful?
02:57rikthevikthoughts?
03:02JomyootHow can I get stack trace to compojure
04:18bagucodeHello all
04:47lypanovdamn, elpa isn't the most reliable thing ever...
05:06lypanovhow do i get a pretty print out of the available methods for a given namespace?
05:07lypanov(doc *) is neat but i'd expect (doc ns) to work actaully. and for it to pretty print the first line of each doc for the ns-publics result
05:07clojurebot"([] [x] [x y] [x y & more]); Returns the product of nums. (*) returns 1."
05:07lypanovheh
06:01dabdare there any guidelines for writing clojure doc strings?
06:01dabdfor when someone writes clojuredoc...
11:48michael___I went to a great presentation by Michael Fogus on Clojure 1.1 and 1.2 features.
11:50michael___I'd like to dive into some of them, especially the new concurrency constructs like futures and promises. I'd also like to explore reify deftype and defprotocol.
11:50michael___I'm blanking on good applications for small projects, though.
11:51michael___Any suggestions? I'd like to do something a little involved and practical, to apply these new features
11:51michael___We would have loved to have you there, chouser
11:52chouserhm, practical and small is a hard combination.
11:52michael___I've looked at your Project Euler solutions in the past
11:53michael___I don't know if Euler is a good source for this, tho
11:53chousermichael___: A nice thought. Half a continent away though. :-/
11:54michael___chouser: at least we know how to pronounce your name, now, thanks to fogus
11:54chouserfor deftype all you need is to think of some new structure that you want to play nicely with clojure's builtin fns like seq
11:54michael___good point
11:55michael___Is anyone using these features in their work or own projects right now?
11:57chouserperhaps nobody who is here on saturdays :-)
11:58michael___LOL
11:58michael___I'll think about it some more and ask Google some more. Thanks!
12:08dabdwhen u need to bind a variable 'foo' which is based on another similar variable, do you consider good style to give it the same name or is it better something like foo2
12:09dabdexample (defn f [foo] (let [foo2 (some-fn foo)] (println foo2)))
12:09chouserdabd: It's a bit of a judgement call of course, but it's not always bad to reuse the same name.
12:10chouserI guess I'd say there's no much point in sticking a 2 on there if that's the best new name you can com up with. :-)
12:10dabdi tend to append an asterisk to the original name but it can be confusing and error prone
12:10qbgIf the shadowing doesn't affect me, I reuse the name
12:10qbg(assuming the original name still makes sense)
12:17lypanovwhats the best way to connect to a mysql db with clojure?
12:17lypanovits for data extraction, no writing.
12:17lypanovneed a batch access method therefore.
12:19tolstoylypanov: Can you just shell out to the mysql client?
12:20tolstoy(Assuming you don't want to use the contrib.sql / jdbc stuff.)
12:20lypanovcontrib.sql is an option, i just can't find others with a quick google :)
12:21tolstoyI think there's a ClojureQL.
12:21lypanovah, thats the one. thx! reading up on it
12:23dabdsometimes I think it would be nicer to have only parenthesis as the delimiters and read macros for vectors #V, maps #M, sets #S, and so on. Does anyone agree?
12:24dabdOTOH for readability Clojure syntax is great. The single delimiter syntax would make code editing slightly easier IMHO
12:25dabdI used Common Lisp for some time so I'm a suspect...
12:25tolstoyI think of [ and { as '( and find it's easy to get away with thinking like that most of the time.
12:25chouserdabd: you'd really want (let #V(a 10 b 20) (+ a b)) ?
12:26chousertolstoy: beware that '
12:26chouser[ and { are semantically a bit closer to (list I think
12:27tolstoyI guess that's sorta what I was thinking, but yeah, you're right. Obviously, I use clojure pretty simply.
12:28dabdchouser: like I said I used Common Lisp for some time. For instance when ending a function definition in CL I just closed all parenthesis in row on the same line. However with clojure because we have different delimiters I feel the need to close them 'a la' Java.
12:29rikthevikhas anyone here got experience with "lein test"?
12:29dabdeach one on a different line so they don't appear all mixed up on the same line
12:29rikthevikNo such var: clojure.test/successful?
12:29chouserdabd: it's a point that's been mae before, though that's the first I've seen your #V suggestion.
12:29chouserbeen made
12:30chouserbut please don't put your closing parens on different lines! :-)
12:32dabdchouser: if I have several ) in a row I don't put them on the same line but if a } or ] I think it looks ugly to close them all on the same line )))]})))) like this
12:33dabdchouser: the #V is clearly stolen from Lisp and I'm sure Rich Hickey thought about this when creating clojure and it's syntax
12:34dabdchouser: I will follow the conventions and close them on the same line though!
12:38tolstoydabd: Wasn't part of the goal with clojure to appeal a little to users of other dynamic languages?
12:39tolstoySo you get brackets for arrays, braces for maps, commas....
12:43stuartsierraIn Clojure 1.0, conj on a vector does not preserve metadata. Is that a bug?
12:43stuartsierraIn Clojure 1.1, conj on vectors does preserve metadata.
12:44dabdtolstoy: sure it was
12:45alechow can I check if an item is in a list?
12:46stuartsierra,(some #{:a} (list :b :a :c))
12:46clojurebot:a
12:47stuartsierra,((set (list :b :a :c)) :a)
12:47clojurebot:a
12:48alecstuartsierra: hm, ok. I also just stumbled upon (.contains (list :a :b) :a), which seems to work
12:49stuartsierraalec: In general, if you're testing whether or not a list includes something, consider using a set instead of a list.
12:50aldebrnCan I experiment with clojurebot in a test channel? I want to see if I can ask the humans a question with a case example
12:50aldebrnAh, I can message it directly
12:53lypanovouch. search doesn't show all matches on clojars.org.
12:56lypanovis there any way to get emacs to make its current state a bit more obvious?
12:56lypanovfrequently i end up getting lost in weird modes
12:56the-kennylypanov: The modes are shown in the info bar
12:56the-kennylypanov: And you can cancel almost everything with Esc Esc Esc
12:56the-kenny(Or C-g)
12:57lypanovah, finally. thank you!
12:57lypanovno... it did it again. vi-mode just randomly ending. !@#@$%
12:58the-kennyI don't have any experience with vi-mode, sorry
13:00aldebrn,(for [val '(1 2 3 4 5)] (let [big-enough? #(> %1 val)] (big-enough? 3)))
13:00clojurebot(true true false false false)
13:00aldebrnWhy does that no work if instead of (big-enough? 3) there I called another function that used big-enough? ?
13:01Chousukehm?
13:02aldebrnSo if I had (foo 3) instead of (big-enough? 3) there, and I had previously defined (defn foo [x] (big-enough? x)) and (defn big-enough? [x] (> x 0)), calling that "for" comprehension would use this latter definition of big-enough?
13:03aldebrnInstead of the new big-enough?'s I was defining in the let
13:03alecstuartsierra: thanks, that actually made the problem a lot easier. I did't even need to do that check.
13:04lypanovthe-kenny: i found out why... thought vip-mode == vi-mode
13:04ben_mCould anyone who uses Clojure with Emacs/Slime give me a sample .emacs? I just can't get it to work :(
13:05Chousukealdebrn: let bindings are lexical, not dynamic
13:07lisppaste8qbg pasted "My .emacs" at http://paste.lisp.org/display/93500
13:07the-kennyben_m: I suggest using elpa.
13:07qbgHas stuff you probably don't need
13:07the-kennyIt's a no-brainer then
13:08qbgelpa helps
13:08ben_mhmm
13:08aldebrnChousuke, thanks. So the functions I call from a let's expression will not be aware of let rebinding sub-functions that they will use
13:08ben_mqbg: thanks
13:08qbgI used to use ELPA, but now I manage my own copies
13:09tolstoyDoes elpa have a mechanism for detecting and then applying updates to packages?
13:09the-kennytolstoy: I modified slime.el and it detected my changes and asked me to recompile it
13:11Chousukealdebrn: yeah. for that, you need the binding macro
13:11tolstoythe-kenny: So that solves the case of detecting that there's been an update to clojure-mode, or paredit, etc?
13:11tolstoythe-kenny: Not local update, but a new package up at the elpa site?
13:11the-kennytolstoy: No, I don't know if it does that.. sorry
13:12qbgI think package-list-packages will fetch the new list from the server
13:12qbg(or there is another command)
13:12tolstoyelpa faq isn't helping....
13:12Chousukealdebrn: note, though, that binding only affects code that actually executes within the binding block. thus, laziness is a caveat
13:12qbgThen you can select to install the new packages
13:13tolstoyqbg: If you've already installed a package, once you refresh, does it let you know there's a new version?
13:13qbgThe old version is listed as obsolete and the new version is in the list
13:14tolstoyqbg: Ah, cool. I note that their front page says "upgrade". ;)
13:15ben_mbaaah
13:15ben_mIt won't work!
13:15tolstoyAh, I see two versions of erc (for instance). Interesting.
13:16qbgben_m: What are you getting?
13:16ben_mPolling "/tmp/slime...." (abort with ...)
13:16ben_mforever though
13:16ben_mI don't get the CL-USER> prompt like I do with sbcl :(
13:17qbgWhat do you see in *inferior-lisp*?
13:18ben_mThe clojure repl
13:18ben_mah
13:18ben_muser=> java.io.FileNotFoundException: Could not locate swank/swank__init.class or swank/swank.clj on classpath: (NO_SOURCE_FILE:0)
13:18robwolfeben_m: do you have "require 'slime" after elpa package.el is loaded?
13:18ben_mI don't use elpa
13:18ben_mBut I do require slime
13:19qbgWhere is your swank-clojure?
13:19ben_mThe dir?
13:19qbgThe jar
13:19qbgIt needs to be on the classpath
13:19ben_mI don't have that jar I think
13:19qbgDid get swank-clojure from git?
13:20ben_myeah
13:20qbgDo you have leiningen installed?
13:20ben_mleiningen?
13:20clojurebotleiningen is a build tool designed not to set your hair on fire (http://github.com/technomancy/leiningen)
13:20ben_mI do not
13:20qbgOnce you have it, do `lein jar` in the directory
13:20qbgThat will build the jar for you
13:20ben_mOh
13:21qbgLuckily leiningen is easy to install
13:21rikthevikI'm getting this error with "lein test". No such var: clojure.test/successful?
13:21rikthevikthoughts?
13:21LauJensenGents I'm doing an experiment for which I need some help. Has anyone here got access to a public MS Sql databases which I can try to log into, run a select now(); and drop out again ?
13:22ben_mSo leiningen is ant without the XML?
13:22qbgOr something
13:22rikthevikben_m: and maven without the brain damage
13:22qbg(makes me think of ASDF)
13:22ben_mnice
13:23ben_mI'm no fan of Java tbh, classpath makes me weep :D
13:24ben_mqbg: Do I need swank.jar?
13:24qbgSomething like that
13:24the-kennyswank-clojure.jar
13:25ben_mhmm
13:25qbgActually, once you have it built, you can test it before altering your .emacs
13:25lypanovben_m: classpath itself is a brillian idea. but tooling it is hard.
13:25ben_mNo idea where to run lein jar
13:25the-kennyleiningen manages all classpath stuff for me :)
13:25ben_mThere's no project.clj anywhere
13:25lypanovlein help new
13:26qbgFrom whose repo did you clone swank-clojure?
13:26ben_mUh, can't remember :|
13:26ben_mWhose should I clone it from?
13:26lypanovhope it wasn't the first google hit...
13:26ben_mIt might have been.
13:26lypanov(the mistake i made last night)
13:26lypanovben_m: technomancy.
13:26ben_mOh
13:26lypanovi used the first google hit, it breaks completely.
13:26ben_mI cloned it from joshua or something like that, I think.
13:27lypanovjochu.
13:27qbgYeah, that is old
13:27lypanovyeah... made the same mistake.
13:27ben_m:/
13:27lypanovben_m: you would have heard me say the same thing last night :P
13:27qbgben_m: Some pain now, fun later ;)
13:27lypanovtook me a bit longer to realize though.
13:28lypanovben_m: technomancy for clojure-mode etc also.
13:28lypanovtechnomancy kept telling me last night to read the "clojure-mode readme. it explains everything"
13:28lypanovafter 2 hours i realized i was reading the wrong readme...
13:28qbglol
13:28ben_mhah
13:30dabdwhy the naming inconsistency empty? vs. not-empty (one ends with ? and the other not)?
13:30LauJensenFunctions ending with ? are predicates returning true/false, not-empty is not one such
13:31the-kennynot-empty returns nil or a coll
13:31the-kennyNot a boolean
13:31dabdok. thanks
13:34ben_mMaybe I should check out ELPA
13:34LauJensenwhy the sigh ?
15:26qbgIs this view of clojure correct? http://vintage-digital.com/hefner/misc/lisp-programmers.jpg
15:27defni dont think so
15:28defnPHP is dead on though
15:28qbgIf Clojure is the Borg, who wouldn't want to be part of the Borg?
15:28defnme, because of the assimilation mostly
15:29hiredmanhttp://www.loper-os.org/?p=42
15:29qbgScotty is elisp?
15:29qbgI guess I can see that
15:30hiredmanI think you a missing the fact that it is supposed to be from the perspective of a common lisp programmer
15:30lypanovi think i want to learn asp.net.
15:30lypanovand make friends.
15:31defnyes! making friends!
15:31defni remember that!
15:31qbgWE SHALL ASSIMILATE YOUR FRIENDS
15:33defnqbg: :(
15:33qbgRESISTANCE IS FUTILE
15:39somniumalexyk: ping
15:40bpsmain't nobody here but us chickens
15:40ben_mLauJensen: Mind linking your screencast again? I got distracted before.
15:41LauJensenSure - but I'm moving the server from the US to London as we speak
15:41LauJensenI'll let you know when I'm done
15:41ben_malright :)
15:48LauJensenben_m: Looks like it'll be about 50 minutes
15:49lpetitHello
15:49ben_mLauJensen: Alright, I'll try it on my own in the meantime :)
15:49lpetitWho wants to take the task of hosting clojure with Go ? ! :-) http://www.infoq.com/articles/google-go-primer
15:52bagucodelpetit: Making the data structures and reader should be straight forward enough. But then there is the issue of compilation. The ASM library and the classloaders provides that for the jvm. What would you use with Go? LLVM would be my choice I guess.
15:53chouserwhy not just generate golang source?
15:53lpetitWhat is LLVM ?
15:53chouserit worked well enough for javascript, seems likely it would work for golang
15:54lpetitchouser: how do you get, then the dynamicity of a REPL ?
15:54chouseroh. well. they claim their compiler is fast, right? :-)
15:55lpetit:)
15:55bagucodeLLVM is a bunch of stuff. It's a portable assembly language with associated tools for optimization and compilation. It's pretty cool stuff actually. Since the compilation infrastructure is all libraries you can use it as a JIT compiler as well.
15:55chousergenerate sources, compile to a .so, ldload, run
15:55chouser:-)
15:56bagucodeLLVM is much cooler, no offline or source generation needed.
15:56lpetitchouser: in which state is "clojure hosted on javascript" (don't know the exact name), btw ?
15:56bagucodeIt's like ASM + classloader, but for native code
15:56lpetitbagucode: looks very interesting !
15:56bagucodeBut ... what would be the point of implementing clojure on top of Go? Hotspot is already very fast actually. Memory consumption maybe?
15:57chouserlpetit: clojurescript. a significant subset of clojure was working, but because lots of parts had to be hand-translated, clojure has moved on and clojurescript has been left behind
15:57lpetitchouser: do you consider reactivating the project once cinc has become a reality ?
15:57chouserabsolutely
15:58lpetitwonderful! Oh, I would need it by monday, if possible.
15:58lpetitI once had the idea of calling the eclipse plugin for clojure : "Ectoplasm".
15:59lpetitI guess when cinc has become a reality, this name could pretty well describe the phenomenon : clojure the ectoplasm attacking each and every platform which already has a story for gc and threading ! :)
16:00chouserhm, I'd rather it not be so restrictive.
16:00chouserthough maybe it's obvious to people who know gc better than I that simple reference counting won't cut it.
16:01bagucodeWell, it's certainly much less work to not have to do the GC :)
16:02lpetityeah, even if doable in practice, I guess no gc would be a blocker for most people
16:02lpetits/in practice/in theory/
16:03bagucodeI think Apple actually open sourced their multithreaded Objective-C GC. I think it's written in C or C++ so it's usable by pretty much any language implementation.
16:03bagucodeI looked at it briefly but couldn't find much documentation
16:03bagucode:(
16:04chouserhow would llvm interact with golang?
16:04bagucodellvm has a C interface so just call that from Go
16:05bagucodeIt has functions for instruction generation sort of like ASM does
16:05bagucodeThen you say something like ExecutionEngine.getFunction(blah blah) and you get a pointer to you new native-compiled function
16:06ben_mWoo
16:06bagucodeI have actually used LLVM from Clojure ;) I'm crazy that way.
16:06ben_mLauJensen: nevermind!
16:07ben_mI used ELPA and let it install clojure, works now :)
16:07LauJensenk
16:07jevgenihi guys. I tried (+ 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1) with resulted in 0.9999999999999999. I know this is a very old Java problem, but what was the reason it was not fixed in Clojure (compared to Groovy/Scala)?
16:10bagucodechouser: I don't know if you remember but I said that one of my motivations for clj-native was that I wanted to use a C library with a large amount of small functions. That was LLVM, I was playing around with it at the time. Both the C and C++ interfaces for it are horrible and I thought that if I could use it from Clojure I could make some sort of assembler dsl that would make it more pleasant :)
16:12greghjevgeni: there's nothing to "fix", that's how computers do arithmetic
16:12greghthe reason is that 0.1, although it looks nice and round in decimal, can't be represented exactly in a binary fraction
16:13ben_mThe "fix" is to use a library
16:13Chousuke,(+ 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M)
16:13clojurebot1.0M
16:13ChousukeBigdecimals :P
16:13greghan excellent article on the topic is: http://docs.sun.com/source/806-3568/ncg_goldberg.html (What Every Computer Scientist Should Know About Floating-Point Arithmetic)
16:13ben_m:D
16:13qbgYou could also use rationals
16:14qbg,(+ 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10)
16:14clojurebot1
16:14Chousukehmm
16:14Chousuke,(+ 1 1/10
16:14clojurebotEOF while reading
16:14jevgenigregh: yes, I know this. however, you don't save 0.1M or 1/10 in databases. I am worried about the integration with the exising datasources and performing operations on these values.
16:14Chousuke,(+ 1 1/10)
16:14clojurebot11/10
16:15Chousukejevgeni: There's nothing Clojure can do about Java's Doubles :/
16:15gregha common way to avoid the problem in situations such as financial calculations, is to store all values in integer numbers of *cents* instead of dollars (for example) and do all integer calculations
16:16jevgenitheoretically, can I redefine the + to represent 0.1 as bigdecimals?
16:16Chousukejust use 0.1M
16:16greghor integer numbers of tents of cents if you want to handle rounding yourself
16:16ChousukeThis only applies to literals anyway.
16:16Chousukeif you get a double from some API, then you have to deal with the imprecision
16:16Chousukethere's no way around it
16:17ChousukeYou need to complain to the API creators to make one that gives you BigDecimals :P
16:17hiredmanjevgeni: why don't you have 0.1M or 1/10 in databases?
16:18jevgenihiredman: it's already saved as float number. a big legacy system to integrate)
16:18hiredmanwell
16:19hiredmanyou are screwed if you are already using floats
16:19hiredmanand have been since the beginning
16:19bagucodejevgeni: so convert the numbers to rationals or bigdecimals when getting them from the DB then and at least the errors won't compound more?
16:20bagucode,(rationalize 0.1)
16:20clojurebot1/10
16:20hiredmanit's the kind of error there isn't any recovering from
16:20jevgenibagucode: thanks for hint
16:21Chousukehmm
16:21hiredmanyou can't tunnel to the past and make things precise
16:21Chousuke,(rationalize 0.18923893)
16:21clojurebot18923893/100000000
16:21gregh,(rationalize (+ 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1))
16:21clojurebot9999999999999999/10000000000000000
16:21bagucode:D
16:22bagucode,(reduce + (map rationalize [0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1]))
16:22clojurebot1
16:23jevgeni(class (+ 1.5M 1.5))
16:23jevgeni,(class (+ 1.5M 1.5))
16:23clojurebotjava.lang.Double
16:24jevgeni(class (+ 15/10 1.5))
16:24jevgeni,(class (+ 15/10 1.5))
16:24clojurebotjava.lang.Double
16:24aleccan a java array returned by something like String.split be converted into a clojure list?
16:24lpetit,(apply + (map rationalize [0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1]))
16:24clojurebot1
16:25lpetitalec: sure
16:26lpetit,(into () (.split "hello you" " "))
16:26clojurebot("you" "hello")
16:26lpetit,(type (into () (.split "hello you" " ")))
16:26clojurebotclojure.lang.PersistentList
16:26aleclpetit: ah, cool. thx
16:26lpetityou would rather prefer putting it in a vector, though, to preserve the array order :
16:26lpetit> ,(type (into [] (.split "hello you" " ")))
16:26lpetit,(type (into [] (.split "hello you" " ")))
16:26clojurebotclojure.lang.PersistentVector
16:27lpetit,(into [] (.split "hello you" " "))
16:27clojurebot["hello" "you"]
16:27lpetitalec: vectors preserve the constant time access to their contents by index. accessing lists by index is done in linear time.
16:28lpetit,(doc list)
16:28clojurebot"([& items]); Creates a new list containing the items."
16:28lpetit,(doc nth)
16:28clojurebot"([coll index] [coll index not-found]); Returns the value at the index. get returns nil if index out of bounds, nth throws an exception unless not-found is supplied. nth also works for strings, Java arrays, regex Matchers and Lists, and, in O(n) time, for sequences."
16:28qbg,(vec (.split "hello you" " "))
16:28clojurebot["hello" "you"]
16:28Chousukeof course, if you don't need a vector:
16:28Chousuke,(seq (.split "hello you" " "))
16:28clojurebot("hello" "you")
16:29lpetitChousuke: :is it "cheaper" in terms of memory or cpu to use seq instead of vec (assuming you want to consume the whole thing) ?
16:32bagucodeGood question. Without looking at the source I think that's hard to answer. The seq from the array is a wrapper object right? So that introduces some overhead. The vector is a little heavier object than the array, but on the other hand it is it's own sequence, so it shouldn't add any overhead to call seq on it? I'm just speculating I haven't looked at the implementation so don't listen to me :)
16:35Chousukelpetit: Hm.
16:35Chousukelpetit: vec needs to copy the array, so I think it's slower
16:36Chousukethough it might be that vec just assumes ownership of it and "lazily" wraps it in a PersistentVector-like interface
16:36Chousukebut I guess seq would be faster
16:37lpetitWell, one also has to consider that alec wants to wrap an array. So depending on his use case, snapshotting the array content into a vector may be safer than relying on the array never changing and just having a seq over it
16:37lpetitI also guess that seq over an array only has to store a ref to the array and an index, so yes, certainly much cheaper
16:38lpetitBut anyway, wouldn't the array work "as is" with most core functions working on seq, since they call (seq) on their arg, don't they N
16:38lpetit?
16:38Chousukeyeah
16:38LauJensenbestinclass.dk is back up again, now serving from London
16:38ChousukeI had some adventures with my brand new QNAP NAS today
16:39ChousukeI managed to brick my Debian installation on it. had to set up a dhcp/tftp server and restore from a backup firmware image ;/
16:40ChousukeGood thing I didn't have to resort to using a serial console, though.
16:41Chousukerebooting things accessible only via the network is rather... stressful
16:47LauJensenYes sir
16:47bagucodeLauJensen: I just scrolled through your blog archive and saw this "An official from Reddit has asked that sleeps be inserted into the code..." did they get hammered after that article?
16:47LauJensenI think so
16:48LauJensenI saw a comment on HN saying that they got a traffic boom
16:48bagucodeGuess you have a lot of readers :)
16:48LauJensenYes - I'm glad I started with a low entry bar, because it means that people not actually read the code, but they feel comfortable enough with it to download and play with it - thats pretty great considering this is Clojure and not some mainstream language
16:50LauJenseneh, rephrase "not actually read" = "not just read"
16:51jevgeni,(* 100M 1.1)
16:51clojurebot110.00000000000001
16:51jevgenishouldn't 1.1 be converted to bigDecimal instead on BigDecimal converted to Double?
16:51jevgeniinstead of*
16:52alechow can I combine two sets, ie, #(1 2 3} and #(4 5 6} go to #{1 2 3 4 5 6}
16:53Chousuke,(into #{2 3 4} #{5 6 7})
16:53clojurebot#{2 3 4 5 6 7}
16:53alecChousuke: ha, same function that answered my last question... thx
16:53Chousukethere's also clojure.set/union I guess
16:54Chousuke~def clojure.set/union
17:23dabdis there a function that iterates each successive tail of a seq?
17:24patrickdloganwho's got the most current, accurate instructions for setting up slime / swank?
17:24patrickdlogantried clojure-install in emacs - it said deprecated in favor of swank-clojure
17:24esbenapatrickdlogan: use swank-clojure instead
17:25dabdI defined this trivial function to do it http://pastebin.com/m105bb8a8
17:26patrickdloganesbena: yeah, went to swank-clojure and the README is still from May and says "step 2. invoke m-x clojure-install..."
17:26patrickdloganesbena: so I should ignore the README?
17:27esbenapatrickdlogan: I'm pretty sure I just used the installer in Emacs. Then it worked out of the box
17:39chouser,(take-while seq (iterate rest [1 2 3 4]))
17:39clojurebot([1 2 3 4] (2 3 4) (3 4) (4))
17:39chouserwhen did not-empty show up??
17:40chouserhuh. it's old. :-/
17:42dabdchouser: take-while returns the sequence of tails. I just want to iterate them. perhaps I should wrap it in a dorun?
17:45chouserdorun also just returns them. what do you mean by "iterate them"
17:46dabddo something with each tail but not collect them
17:46kotarakdabd: doseq
17:46dabdwhat about this (defn do-tails [s f] (doseq [item (take-while seq (iterate rest s))] (f item)))
17:47kotarakdabd: that's just (doseq [item s] (f item))
17:48kotarakdabd: ah no. it is not. Forget what I said
17:48dabdkotarak: yes I didn't name item properly it should be named tail
17:48lpetit,(doc recursions)
17:48clojurebotPardon?
17:48lpetitclojurebot: nevermind
17:51Rayneschouser: What are you guys using to write your book?
17:59chouserRaynes: knowledge we've gained through decades of research and hard work
17:59chouser:-)
17:59Rayneschouser: Heh heh.
17:59RaynesI meant that rather literally.
17:59Raynes:p
17:59chouserI'm mostly using vim. I believe fogus mostly uses emacs.
18:00RaynesI tried to use muse mode, but it doesn't seem to work right for me. :\
18:00RaynesIt looked awesome too.
18:00RaynesShame.
18:01chousersome of the first stuff was written in etherpad
18:02RaynesUsing LaTeX or something?
18:03chouserManning has a docbook-like xml format they like, and tools to generate pdfs as well as whatever they need to actually go to print.
18:03RaynesI see.
18:03RaynesI'm clueless about book writing. :\
18:04chouserso we've developed a tool that converts a somewhat extended version of Markdown to Manning's XML format.
18:05chouserI was too! Apparently a lot of their books are written and prepared in MS Word.
18:05RaynesI've read up on some OOo stuff about book writing. Styling makes my eyes water. It all seems too complicated.
18:07RaynesMuse-mode's documentation is thorough, but awful vague.
18:08lpetitdabd: your initial attempt was good too by not creating unnecessary sequences. I've just updated it to take into account that you want to eagerly consume it (so using next instead of rest), and getting rid of the loop to leverage the direct use of recur on the function: http://pastebin.com/m2725cd2d
18:10lpetitdabd: though now that I think about it, keeping your initial version, replacing the initialization of s in the loop (loop [s s]) by (seq s) : (loop [s (seq s)]), and then replacing rest with next should do it. (will save the superfluous call to seq, which is unnecessary but for the initialization of s arg)
18:15dabdlpetit: I don't understand the difference between your 1st 2nd suggestions http://pastebin.com/m28155e0c
18:15mkhchouser: i bought your book yesterday, any chance of it being published in ePub format
18:16maaclI would like to create a function that returns a unique pseudo random length vector of pseudo random ints. A max length of the vector and max value of the ints should be definable. Any hints?
18:16lpetitdabd: in the second, (seq s) will be called just once, at loop initialization. in the first, it is called every time
18:18dabdlpetit: of course. thx
18:19Chousuke,(vec (take (rand-int 10) (repeatedly #(rand-int 20))))
18:19clojurebot[14 12 0 2 2 14 8 13 13]
18:20Chousukemaacl: see above
18:20dabdlpetit: in practice this elegant functional version is very inefficient: both iterate and seq create sequences unnecessarily http://pastebin.com/m64eeb50b
18:21maaclChousuke: thanks, but my challenge is the unique part, I am guessing a closure is the solution, but I cannot get my head around it
18:22Chousukemaacl: hmhm
18:22Chousukemaacl: you need to store the vectors in a ref I guess.
18:22lpetitdabd: yes, you only want side effects, and you know you want to go through the whole list eagerly, so you don't care about lazy seqs, you just want to iterate as quickly as possible. That's why I was considering that your initial attemp was more suited for defining such a general tool
18:23qbgmaacl: A random length subseq of a permutation of 0 to n-1?
18:25maaclqbg: yes I believe so
18:25qbgIf you define shuffle, the definition should be trivial
18:26qbgSomething like (take (rand-int <num>) (shuffle (range <num>)))
18:28maaclqhg: so e.g. I have 5 vectors with 20 unique values in each and I want 10 unique vectors with a value from 1 to 5 of the vectors
18:28dabdlpetit: why is it necessary to call (seq s)?
18:29qbgThe 10 vectors are of random length?
18:30lpetitdabd: (seq s) will ensure s is transformed into a seq, *and also* if s is an empty coll or an empty lazy seq, the result of calling seq is guaranteed to be nil. (remember that '() is not considered as logical false in clojure)
18:31maaclqbg: yes
18:32qbgAre the sets of values in the 5 vectors disjoint from each other?
18:32maaclit is like a cartesian product except not one item from each set but a random number of items with a max = the number of sets
18:32dabdlpetit: can u show me an example where this would not work correctly? http://pastebin.com/m5c4aa68f
18:33chousermkh: I'll ask
18:33mkhchouser: thanks
18:34qbgWould taking items randomly from the concatenation of all 5 vectors work?
18:34lpetitdabd: hey, it will work correctly, not-empty is based on calling seq, look:
18:34lpetit~source not-empty
18:36maaclqbg: nope, if there is just one element in the vector it has to be from the first
18:36maaclqbg: the first set that is
18:36dabdlpetit: ok. thx
18:36lpetitdabd: but you're calling it every time, even so calling next in recur guarantees that you will either have a logical true, either nil (which is logical false), so there is just the initialization of the loop where u need to call (seq s) to ensure you have a correct logical false (nil) if s is empty
18:36qbgAnd if there are two elements in the vector?
18:37maaclqbg: they have to be from the first and second set
18:38maaclqbg: ah, i could just do the different relevant products and join them
18:39qbgIf that works, why not
18:40dabdlpetit: this is getting slightly confusing. why should I worry about logical values if not-empty returns nil for an empty collection or the collection otherwise?
18:41alexykcan you nest a defn, you have to do an fn?
18:41alexykor have to do an fn instead
18:42qbgWhy would you want nest a defn?
18:42patrickdlogantrying to connect the dots between ELPA and github for swank-clojure...
18:42lpetitdabd: my point was not about using seq directly or using not-empty (this is basically the same thing), but about the fact that calling them is only needed once, since calling next will *ensure* that you either have an non empty lazy seq, or nil
18:42lpetitalexyk: ??
18:42patrickdloganELPA installed 1.1.0 of swank-clojure...
18:43alexykhm, lots of FP is done with auxiliary functions, e.g. carrying an accumulator
18:43patrickdlogangithub shows just one branch, 1.0
18:43alexykthe aux is only needed in the parent
18:43alexykand hence good to nest and hide
18:43qbgYou could use let/letfn
18:44qbgnested functions are good, but defn makes a global binding
18:45hiredmanalexyk: def operates in the global scope
18:45alexykhiredman: ok
18:45hiredmanand local bindings of names are immutable
18:45hiredmanso having def operate locally would be just weird
18:46hiredmanso use let or letfn
18:47qbgJust be careful that you don't do unbounded recursion.
18:51dabdlpetit: got it. I had to look at the implementations of not-empty and next and finally figured what u meant. So u need to pay attention to which functions use seq under the hood when looping
18:52dabdso this is the final version: http://pastebin.com/m4926bb67
18:52lpetitdabd: it's in the public API/contract of 'next and 'seq to return nil on empty colls/lazy sequences.
18:53lpetitdabd: sure. going to bed now, cu
18:54dabdlpetit: thx
19:01tolstoyAnyone here using netbeans/enclojure?
19:03tolstoyDoesn't seem to want to install the plugin in netbeans 6.8. Surely, 6.8 is compatible....
19:07tolstoyAh, has something to do with github downloading.
20:00ajuchello, anybody compiled lately penumbra with leiningen
21:31mebaran151is there an easy way to turn a clojure hashmap into xml?
21:32chouserhm... recursively?
21:34mebaran151yeah
21:34mebaran151like the way we have write json
21:34hiredmanmebaran151: like a clojure.xml hashmap?
21:34mebaran151I have a hash-map: I'd like to just output it to a flash client
21:34mebaran151thought xml would be the easiest way to do it
21:35mebaran151it seems like clojure.xml would have something like what I need but I haven't found it yet
21:35hiredmanjson is most likely the easiest way to do it
21:35hiredmanclojure.xml has emit
21:35chouserI don't know of a generic map-to-xml, though it wouldn't be too hard to make.
21:35hiredmanbut you can;t use it on an arbitrary hashmap
21:36mebaran151hiredman: what kind of hashmaps can I use it on?
21:36hiredmanthe kind of hashmaps clojure.xml/parse produces
21:37hiredmanflash is more or less javascript, why not use json?
21:37mebaran151I haven't been using contrib, and I thought maybe the xml ns had what I needed
21:38mebaran151also e4x makes these documents a little easier to work with
21:38hiredmanyou can just use clojure-json if you don't want to use contrib
21:38mebaran151extra lib though?
21:39hiredmanyes
21:39mebaran151I should just probably use json-str in contrib
21:58ben_m,pastebin
21:58clojurebotjava.lang.Exception: Unable to resolve symbol: pastebin in this context
21:58ben_m?pastebin
21:59ben_mHmm
21:59ben_mWill just use a generic one ..
21:59chouserlisppaste8: url?
21:59lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
21:59ben_mhttp://sprunge.us/jRCW
22:00ben_mI'm trying to follow a tutorial ...
22:00ben_mCompiling this gives no errors, but when I run it, I only get an empty window :/
22:02hiredmanwhat window manager?
22:03hiredmanI have heard ion and java don't play nice together
22:03ben_mMusca
22:04ben_mtiling too
22:04ltyphaircompiz turned on has given me trouble before. the java window would end up under the panel
22:04ben_mBut I doubt that's the problem
22:04ben_mNah, no compiz.
22:04hiredmanben_m: why do you doubt it?
22:04ben_mI had other Java programs running
22:05ben_mNot in Musca specifically, but other tilers.
22:07the-kennyben_m: uhm.. you're calling the function "counter-app", right?
22:07hiredmanworks for me
22:07ltyphairfor what it worth the code works on gnome.
22:11ben_mthe-kenny: yes?
22:11ben_mHmm alright then
22:11ben_mEverything about my PC acts in mysterious ways, so this does not surprise me.
22:30ben_mIs there a shortcut in the REPL to get the last result? Like */**/*** in CL
22:35hiredman*1 *2 *3
22:36ben_mah, thanks :)
22:38hiredman(doc e*)
22:38clojurebotExcuse me?
22:38hiredman(doc *e)
22:38clojurebot"; bound in a repl thread to the most recent exception caught by the repl"
22:40konr`it seems that my JVM is computing data on an infinite sequence - is there a way to recover without killing slime (therefore losing the session data)?
22:41ben_mC-c C-c 0
22:41ben_m?
22:45konr`wow
22:45konr`thanks, ben_m
22:45wiligtechnomancy: Yay! swank-clojure is now (read-line) enabled.
22:45konr`I used to ignore that debug menu
22:45ben_mHeh, it can do so much more if you use Common Lisp.
22:51mattreplis there a known issue with leiningen's test command?
22:52aldebrnliebke, I'll post this to the group, but maybe I'm doing something stupid: when I start clj (from the latest Incanter snapshot build) and (use 'incanter.core), Clojure can't find the "shuffle" function (from contrib.seq-utils).
22:53aldebrnIf I try to (use 'clojure.contrib.seq-utils), I get an IllegalStateException, but after which I can see shuffle, e.g., (doc shuffle)
22:54aldebrnSo, I can work around this by using the REPL, but it prevents me from running scripts that use shuffle
22:54liebkealdebrn: okay thanks, I'll take a look. Were you using the pre-built distribution or building it from source?
22:54aldebrnPre-built
22:54liebkeokay, I'll test it out
22:55aldebrnThanks for your selfless hard work
22:55liebke:)
22:58liebkealdebrn: I'm getting the error. What platform are you running on?
22:58aldebrnFedora 11 64-bit
22:59liebkedo you have a CLASSPATH set?
22:59aldebrnjava version "1.6.0_0" OpenJDK Runtime Environment (IcedTea6 1.6)
22:59aldebrnNo CLASSPATH appears to be set
23:00liebkeI don't have fedora, but I'll test it on redhat 64-bit
23:01aldebrnYou said you were getting the "IllegalStateException: group-by already refers to: #'incanter.core/group-by in namespace: user" error?
23:02liebkeI said?
23:03aldebrn"liebke> aldebrn: I'm getting the error." <-- did you mean you're not getting an error?
23:03liebkeoops yeah, I meant I'm not getting the error :)
23:03liebkeis that the error you're getting?
23:04aldebrnYes, when I try (use 'clojure.contrib.seq-utils)
23:04liebkeah yes, I've seen that one. That's because it also has group-by defined
23:05liebkeyou need to use require instead of 'use' for either incanter.core or seq-utils
23:05aldebrnAhh, so does incanter.core, got it
23:05aldebrnOk
23:05liebkeyeah, name collision
23:13aldebrnliebke, sorry to bother you again, how would I use (require) with seq-utils?
23:15mattreplaldebrn: (require [clojure.contrib.seq-utils :as seq-utils])
23:15mattreplthen seq-utils/group-by
23:15mattreplyou can also do (use [clojure.contrib.seq-utils :only [<stuff> <you> <need>]])
23:16mattrepland that should be :require and :use if used in a namespace definition
23:18aldebrnmattrepl, thanks, something somewhat strange is happening: (use 'clojure.contrib.seq-utils) works fine (by itself), but (use [clojure.contrib.seq-utils :only [shuffle]]) gives this horrific ClassNotFoundException: clojure.contrib.seq-utils (NO_SOURCE_FILE:1) ?
23:19aldebrnSimilarly with your example using (require), am I typing something wrong?
23:19mattreplright, I gave you a bad example since it's incorrect for an ns definition as well as from the repl
23:19mattreplyou need to quote clojure.contrib.seq-utils and shuffle
23:19liebkealdebrn: try (require '(clojure.contrib [seq-utils :as s]))
23:20aldebrnAhh, damned quotes
23:20aldebrnThank you thank you
23:20liebkeand then you can refer to functions using the s prefix, like s/group-by