#clojure log - Oct 11 2010

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:06 TaigerRobocot: hmm

0:07 i am trying

0:12 freakazoid: anyone use flymake + magit and have issues with emacs CPU usage just gradually increasing over time?

0:12 or otherwise have such a problem and have hints for debugging it

0:19 automata: I'm trying to use rosado's clj-processing on a lein project but getting some error messages

0:20 any help?

0:25 TaigerRobocot: amalloy: else in clojure is " (if (= x y) x , :else y) " ?

0:26 automata: i'm getting this message: (ns live-processing.core

0:26 (:use [rosado.processing]))

0:26 java.lang.NoSuchMethodError: clojure.lang.RestFn.<init>(I)V (NO_SOURCE_FILE:1)

0:26 maravillas: there's no :else

0:26 just (if (= x y) x y)

0:26 amalloy: TaigerRobocot: no, :else is pard of cond. (if CONDITION if-true if-false)

0:26 ,(if false 10 20)

0:26 clojurebot: 20

0:26 TaigerRobocot: tk

0:53 is normal a function with recur return two value? example: instead returns 5 it returns 56 and I want ignore number 6 (next step of method recursive)

0:54 amalloy: TaigerRobocot: i don't understand what you're asking. can you pastebin or gist an example?

0:55 TaigerRobocot: http://pastebin.com/jyrLH4Lk

0:55 I call -> (fact 0 1 9)

0:56 amalloy: TaigerRobocot: you're using (def) when you really want (let). def creates a global variable, not a local

0:56 TaigerRobocot: let requires a vector for its binding

0:56 amalloy: ,(let [x 10] x)

0:56 clojurebot: 10

0:57 amalloy: ,(let [auxN (+ 1 4)] auxN)

0:57 clojurebot: 5

1:01 TaigerRobocot: cool, and that problem returning to values?

1:05 amalloy: oh i see. it's not returning two values; one of them you're printing and the other it's returning

1:06 to make it clearer what's going on, you could turn the print into a println, but i think you probably just want to return the number instead of printing it: (if (= auxN numero) auxN)

1:09 TaigerRobocot: oh, alright.... can I break after print ? The printed number is more important

1:10 anyway, is almost solved :)

1:11 amalloy: try something more like this: (cond (= auxN numero) auxN, (> auxN numero num), :else (+ num...))

1:11 er, except i misparenthesized the > expression. you see what i mean, i hope

1:16 freakazoid: what's the reason for using vectors for that stuff, anyway? Syntax?

1:20 TaigerRobocot: freakazoid: where?

1:21 freakazoid: let, fn, etc

1:23 TaigerRobocot: amalloy: thank u for support, do u have a palpay account for donation?

1:23 amalloy: freakazoid: i'm hardly a language authority, but they seem to be the most convenient way to group a bunch of items

1:24 TaigerRobocot: lol no, support on #clojure is free and comes with no warranty :)

1:31 freakazoid: can you imagine writing (fn) with no [] for arg-specs? you need some way to separate the list of arguments from the function body

1:32 freakazoid: somehow lisp and scheme seem to manage it.

1:32 but it sounds like you're saying it's just syntactic.

1:34 amalloy: lisp uses () instead though, right? you need *some* separator, and in clojure [] is available as a convenient grouping mechanism that doesn't "look" like it will treat its first member as a function

1:35 freakazoid: Right, so syntactic. I was just wondering if it served a further purpose.

1:36 It certainly makes Clojure code easier to read than CL or Scheme code.

1:37 there are some lisp dialects that have [] as just an alternate syntax for lists and use them in particular places by convention

1:37 amalloy: freakazoid: it also simplifies rich's bootstrapping. check out (source defn) - he checks the arguments to see what order they're in; there's a check for vector? in there somewhere

1:37 freakazoid: oh groovy

1:37 so they do serve a further purpose, then

1:37 ,(source defn)

1:37 clojurebot: java.lang.Exception: Unable to resolve symbol: source in this context

1:38 freakazoid: blah

1:38 amalloy: freakazoid: clojurebot doesn't have the source code, either

1:39 clojurebot: source?

1:39 clojurebot: source is http://github.com/hiredman/clojurebot/tree/master

1:39 amalloy: clojurebot: clojure source?

1:39 clojurebot: clojure is far closer to perfection then python

1:40 freakazoid: That's true, though clojurebot's spelling isn't.

1:40 amalloy: freakazoid: http://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L263

1:42 clojurebot: clojure?

1:42 clojurebot: clojure > scheme

1:42 amalloy: you are so unhelpful

1:42 freakazoid: hmm, how do I get the jarfiles lein downloads into swank's classpath in emacs?

1:42 amalloy: clojurebot: github?

1:42 clojurebot: http://github.com/richhickey/clojure/tree/master

1:42 freakazoid: clojurebot: cookies?

1:42 clojurebot: Gabh mo leithscéal?

1:43 amalloy: clojurebot: github is http://github.com/clojure/clojure

1:43 clojurebot: Ik begrijp

1:43 amalloy: clojurebot: github?

1:43 clojurebot: github is http://github.com/clojure/clojure

1:43 amalloy: clojurebot: botsnack

1:43 clojurebot: thanks; that was delicious. (nom nom nom)

1:43 amalloy: freakazoid: you gotta treat him nice :)

1:44 carkh: ~src defn

1:44 clojurebot: Gabh mo leithscéal?

1:44 carkh: mhh

1:44 clojurebot: source defn ?

1:44 clojurebot: No entiendo

1:46 carkh: ~source defn

1:46 ahaaa !

1:47 ~botsnack

1:47 clojurebot: thanks; that was delicious. (nom nom nom)

1:48 amalloy: carkh: clojurebot needs to be updated: he still thinks richhickey has the source, not clojure

1:48 i'll put together a patch for hiredman

1:49 carkh: rich isn't updating this repository at all ?

1:49 raek: the clojure fork is the official one

1:49 amalloy: he might be, but it's not the definitive source. and the last commit to this repo was in june

1:50 carkh: ok

1:55 amalloy: carkh: okay, it's out of my hands now - should be fixed whenever hiredman pulls my repo and builds clojurebot again

1:55 carkh: nice thanks =)

2:05 ossareh: with ring and wrap-cookies I should be able to (assoc (request :cookies) "cookiename" "cookievalue"), right?

2:10 amalloy: ossareh: i haven't used ring, but looking at the source it looks like that's the wrong api

2:13 ossareh: that might be because my example was incomplete? - my route is returning {:status 302 :headers {<redirect header>} :cookies (assoc (request :cookies) "x" "y")}. As I read http://github.com/mmcgrana/ring/blob/master/ring-core/src/ring/middleware/cookies.clj it looks for :cookies in the response and writes the values?

2:13 amalloy: or hrm, ossareh, i take it back. that looks fine api-wise, but because maps are immutable you're adding a value and then throwing it away

2:13 oh. well that looks reasonable

2:14 ossareh: yeah, I'm trying to ensure I keep any cookies passed in, hence assoc'ing on the request cookies

2:14 wondering if you can't set cookies on 302's.

2:15 ahhh

2:16 I see

2:16 the cookie is having it's path set to my handler that is causing the redirect - so I don't see it in other requests.

2:21 LauJensen: Good morning all

2:23 amalloy: this seems like a silly question, but what is defn-? i see it defined as "a non-public defn", but what is that?

2:23 carkh: the function defined with defn- cannot be accessed from another namespace

2:26 LauJensen: carkh: Well. You can still access non public fns using #'someotherns/private-function

2:27 carkh: but that's cheating =)

2:27 LauJensen: Not if you're writing unit tests

2:28 amalloy: mmmm, i love functional languages. if a function is too big, just cut/paste a subtree into a new function, and pass in whatever variables it needs; no need to worry about pass-by-value semantics

2:30 LauJensen: mmmm, order of execution is irelevant, mmmmm

2:31 amalloy: LauJensen: truly a delicious side-effect of not having side-effects

2:31 LauJensen: functional poetry

2:32 notsonerdysunny: can I make cake automatically load a file when it is starting the swank server?

2:39 amalloy: notsonerdysunny: i don't know how, but you could modify src/cake/tasks/swank.clj to add it without too much trouble

2:40 LauJensen: here's what I said in #cake.clj: swank opens your projects cp, which is also what bake gives you access to, try this (deftask swank-load #{swank} (bake (:use yourns) [] (load-file "somefile.clj"))) ?

2:44 amalloy: actually i take it back, notsonerdysunny. try $ cake swank && find src -name '*.clj' | xargs cake run

2:45 (assuming you want to run everything. if you want to be more specific, pass whatever files you want to cake run

2:58 LauJensen: amalloy: I think notsonerdysunny is a new breed of troll, who pops up in technical channels, asks technical questions that make people think about how to answer, and then just ignores the result. Quite intelligent trolling

2:58 amalloy: LauJensen: no, he asked the same question yesterday, or ten hours ago or something

2:59 LauJensen: amalloy: So it works several days in a row with the same question? ingenious

2:59 amalloy: and if you were right, i'm not sure it would count as trolling. more like a socratic public service

2:59 LauJensen: haha, good call

2:59 amalloy: LauJensen: har har. i don't think anyone answered last time

3:02 notsonerdysunny: sorry guys .. I am not trolling .. I was just trying what you guys suggested

3:03 amalloy: notsonerdysunny: don't worry about it, LauJensen's just a grumpy old man. stay off his lawn

3:04 LauJensen: notsonerdysunny: dont worry about it, the above was actually just a joke intended to have your name highlighted a few times, of course I know that you're not trolling :)

3:05 amalloy: LauJensen: -1 for knowing your audience :)

3:07 LauJensen: ?

3:07 amalloy: LauJensen: he didn't know it was a joke. hence you aren't very good at telling jokes

3:08 LauJensen: amalloy: theoretically, couldn't it just be that you two are morons? No wait! Im kidding again! :) Okay I'll take a break from stand-up now

3:08 amalloy: haha

3:09 notsonerdysunny: :)

3:14 amalloy: ew, really? i can't write (comment TODO: whatever) because TODO: is an illegal token? i can understand needing comments to have balanced parens, but...

3:15 carkh: the inside of your comment is going through the reader

3:15 you might want to use ; comments

3:16 LauJensen: amalloy: or #_(comment TODO: whatever lol)

3:16 amalloy: LauJensen: that doesn't work. #_ is shorthand for comment

3:17 carkh: yeah, i usually do, but for a long TODO list i decided to make it multiline

3:17 LauJensen: ,#_(comment TODO: whatever lol)

3:17 clojurebot: Invalid token: TODO:

3:17 amalloy: clojurebot: thanks

3:17 LauJensen: odd, that works in my repl

3:17 clojurebot: I don't understand.

3:17 amalloy: LauJensen: what version of clojure?

3:18 LauJensen: which version? I was testing in 1.2, but I tested with #_(comment hi there), it was the TODO: which was triggering eval

3:18 amalloy: yeah

3:23 LauJensen: i've noticed that using destructuring in function arglists causes (doc f) and eldoc to look ugly. i can add {arglists} metadata to my functions to present a cleaner look, but is there a way to have it automatically use my :as declarations in the arglist?

3:23 eg (defn myfunc [{name :fname last :lname :as person}]) automatically get the simple arglist of [person]?

3:24 LauJensen: Not that I know of

3:25 But I think for clarity, you wouldn't want that either, 6 months from now its nice to know whats being looked up in person

3:28 amalloy: hm, maybe. i suppose you could turn each destructured vector into a ([simple] [{thing1 :complex1 :as simple}]) pair

4:04 notsonerdysunny: LauJensen: what you had suggested does not seem to work.. when I get a repl... I am able to load the file .. but when I did this in the "swank-load" task .. it is unable to see the file..

4:05 LauJensen: Where is the file on disk ?

4:06 notsonerdysunny: it is in lib/ .. it is one of the dependencies

4:07 LauJensen: a .clj file?

4:10 notsonerdysunny: .clj is in a jar file ..

4:10 to be precise .. I am trying to use Clojuratica .. I want it to automatically establish the mathematica connection when it starts

4:11 Clojuratica contains a bunch of .clj files "jar"red together

4:11 LauJensen: notsonerdysunny: Ok. I dont have a lot of time right now. But when you use the bake macro as I showed above, that lets you exec code at compiletime which has all the dependencies of your project loaded, so simply load it as you normally would. The #{swank} syntax means that this runs before swank launches.

4:12 notsonerdysunny: oh thanks .. I did understand what you had given me .. but wasn't able to get it working

4:13 thanks for you help though

4:13 LauJensen: np, you can ping me tonight if its still not working, but the guys in #cake.clj are very helpful so you should be able to get this going :)

4:17 notsonerdysunny: LauJensen: actually I am sorry .. I had quoted the NameSpace

4:17 that is why it was not working

4:17 now it seems fine

4:17 LauJensen: great :)

4:17 opqdonut: what's the status of definterface?

4:20 notsonerdysunny: LauJensen: one more thing .. how is load-file searching for the files.. should the path be relative to some directory ..

4:20 -> (doc load-file)

4:20 LauJensen: notsonerdysunny: I think its just relative to (System/getProperty "user.dir")

5:11 quizme: is there a way to shorten this? http://pastie.org/1212551

5:14 carkh: (:use [ring.middleware params file-info reload file stacktrace])

5:14 mrBliss: quizme: http://gist.github.com/620252

5:14 carkh: i don't know much about ring, but there might be a namespace which imports them all

5:26 raek: for prefix lists, lists should be used, iirc

5:27 that vectors works happens to be an effect of how it's implemented

5:27 (:use (ring.middleware params file-info reload file stacktrace))

5:27 mrBliss: raek: You're right, but I think it looks better ;-)

5:28 carkh: i prefer vectors too =)

5:29 i even put vectors around single imports to make it regular

5:30 LauJensen: And it really makes no difference does it?

5:32 raek: I put my sense of aesthetics to the side and write it the documented way :-)

5:32 mrBliss: a stu said you should use lists because that's what the documentation prescribes

5:33 raek: just beware of the empty-prefix-list syndrome...

5:34 that is, (:use (foo)) which doesn't do anything

5:34 carkh: it uses foo

5:34 i do that all the time =P

5:34 raek: vectors or lists?

5:35 carkh: vectors

5:37 raek: it works with vectors (meaning use without options), but not for lists (meaning empty prefix list)

5:41 LauJensen: yea, so vectors are safer

5:42 raek: a fair point

6:28 philip``: Hi, i'm trying to get cake running on my gentoo box, but it just raises an exception and hangs when i do "cake". The exception is "NoClassDefFoundError: Could not initialize class java.util.Currency". I've tried to find java.util.currency in emerge, but i can't seem to find it. Am i overlooking something?

6:29 /join #cake

6:29 erh...

6:29 Chousuke: are you sure your java is properly installed?

6:30 Currency is a standard component of the JRE

6:31 (And I doubt cake depends on it, so your problem might not be with cake)

6:31 philip``: Chousuke: I think i've installed icedtea, but i must admit, i was quite confused as to what packages to install.

6:31 Maybe i should try with sun/oracle jre?

6:31 Chousuke: icedtea should work I think

6:31 philip``: okay

6:31 Chousuke: but I don't know anything about Gentoo

6:32 philip``: Do you know of any simple way to test my java?

6:33 Chousuke: try writing a Hello World

6:36 LauJensen: philip``: its #cake.clj

6:37 philip``: java -version ?

6:38 philip``: or java -cp clojure.jar clojure.main -e '(println "Hello, world!")'

6:38 jarpiain: also, eselect java-vm list

6:40 philip``: LauJensen: version: http://gist.github.com/620331

6:40 And yeah, somethings definitly wrong. Hello world doesnt work, i get a nosuchmethod exception.

6:41 as in, it cant find System.out.println

6:41 LauJensen: philip``: Clean your system, install Oracle/Sun JRE/JDK

6:41 At least thats my recommendation, Ive spent enough hours debugging OpenJDK already :)

6:42 philip``: I'll try that. Thank you.

6:43 don333: given 2 files - main.clj and rtta/run.clj - where main :uses rtta.run, I can't slime-eval-buffer the main.clj in Emacs

6:43 it gives me "Could not locate rtta/run__init.class or rtta/run.clj on classpath"

6:43 tobiasraeder: hey :)

6:43 LauJensen: hey tobiasraeder, hows the project coming along?

6:44 tobiasraeder: @LauJensen good good, nearly done with the interop side so soon i should be mainly doing clojure that looks like clojure ;)

6:44 don333: what is the proper way to work in slime with namespaced files using other namespaced files?

6:48 tobiasraeder: what interface do i need to implement to be able to use deftyped classes like a map?

7:01 or to formulate it different, anyone worked with ILookup and ILookupThunk?

7:56 philip``: Okay, java is working now, and so is cake :). Now i'm having problems with emacs/swank-clojure... I'm running swank with 'cake swank', and i can connect from emacs just fine. Evaluating functions in the REPL is working too, but if i open up a file in another buffer and compile a function with C-c C-c, emacs hangs for a bit and gives me this error: "error in process filter: Wrong type argument: sequencep, 0.007100712"

7:56 . The compilation works fine, but it's really annoying with the little delay...

7:57 Also, exceptions make emacs hang, but the debugger window doesnt appear. I have to switch the that buffer manually :-/

8:00 LauJensen: C-h k C-c C-c ?

8:00 And did you connect using slime-connect ?

8:00 philip``: ^

8:02 notsonerdysunny: Hello ..

8:03 philip``: LauJensen: C-c C-c runs slime-compile-defun. I am connected in the repl window, and the other buffer has majormode clojure-mode and slime minor mode. When i compile a defun from the clojure-mode buffer, it gets compiled and i can run it in my repl buffer, but not without giving me an error

8:03 LauJensen: philip``: try slime-eval-defun instead

8:04 notsonerdysunny: hey

8:04 notsonerdysunny: the slime interaction is kinda slow when compared to sbcl .. it becomes significant when an exception is thrown and you just press q to return to repl.. is this expected

8:04 Hey LauJensen

8:05 philip``: LauJensen: Okay, thats snappy like i'd expect (for a simple function that sums two numbers...) Just need to bind that to C-c C-c instead i guess?

8:05 LauJensen: Yes sir

8:05 philip``: Also, you might want to try Arch Linux :)

8:07 philip``: LauJensen: Haha, yeah, some of my friends tell me that too. But i think i'm going to stay with Gentoo for a while. terminal-porn is nice :)

8:08 kryft: Arch Linux. ♥

8:08 * fro0g likes gentoo

8:08 LauJensen: <3 Arch Linux E>

8:09 philip``: (updating chromium compiles for 3 hours straight. It's almost like an orgy!)

8:09 LauJensen: Arch is Ubuntu without the bloat, Gentoo without the suck, Debian without the Flintstones, OSX without the femininity and totally unlike Windows

8:09 fro0g: philip``: distcc :)

8:10 LauJensen: Also, Arch can do about 90 critical program updates in around 90 seconds. Gentoo can do it in 90 years :(

8:10 philip``: Is it also ubuntu without the fucked up non-textfile-configurations?

8:11 LauJensen: philip``: Yea, its not even Debian based, so its pretty far from Ubuntu

8:11 Except for my monitor layout I dont think I have anything thats not in some way text based configuration

8:11 philip``: I spend almost a week getting xmonad running acceptably in ubuntu 9.10 because configuring x is fucked up...

8:12 LauJensen: really? Should be super easy though http://media.slated.org/albums/userpics/10002/ubuntu.png

8:14 fhd: Hi there. Has anyone tried TDD with Clojure? Is it possible to use mock objects? I couldn't find a reasonable way.

8:14 AWizzArd: Hallo fhd.

8:14 philip``: LauJensen: Not my experience. Setting up xmonad for gdm was just weird... (okay, thats not x, but i had problems with that too!). I totally gave up trying to get stumpwm to work, but it's been smooth as a babys butt on gentoo (havent tried xmonad though, but stumpwm was piece of cake)

8:15 LauJensen: fhd: I've seen a few post on TDD, but if Im not mistaken Rich Hickey has pretty strong views on TDD, ie. not liking it. I could be wrong though

8:15 philip``: Im using Awesome on Arch, though thats no cake-walk since they changed Cairo dramatically Im locked on version 1.8 and they're on 1.10 now IIRC

8:15 fhd: LauJensen: I've seen some posts too, but none go into detail.

8:16 AWizzArd: fhd: You say you can't find a reasonable way. What ways did you try so far?

8:16 fhd: More general, even without TDD, how can I e.g. create a "provider" interface and create several implementations of it in Clojure?

8:16 philip``: LauJensen: That sucks. You

8:16 fhd: I never thought about doing something like that in Lisp because I only used it for scripting. But now I need an architecture that supports exchanging of backends.

8:17 philip``: LauJensen: You're the one from bestinclass right? It's very nice, part of what convinced me to try out clojure. Thank you for that :)

8:17 fhd: AWizzArd: Well, I tried a function that would accept an fn object as an argument, which was either the mock function or the real one. I hated that approach...

8:17 kryft: philip``: Everything has been easy on Arch Linux. =)

8:17 LauJensen: philip``: sweet, glad to hear it :) np

8:18 kryft: Which WM are you using?

8:18 Chousuke: fhd: you can use protocols, multimethods or higher order fns

8:18 (higher order protocol fns work too I guess :P)

8:18 kryft: LauJensen: xmonad

8:19 LauJensen: I also opted for OSSv4 instead of ALSA, but other than that, I guess my setup is fairly standard (and minimalist :)

8:19 fhd: Chousuke: I'll look into that stuff. Nothing rings a bell, but as I said, I've only used Lisp for simple scripting so far

8:19 Being forced AFK now...

8:19 Chousuke: fhd: protocols are kind of like interfaces, only more dynamic

8:20 philip``: kryft: How's OSSv4 working out for you?

8:22 kryft: philip``: No complaints. :) Well, something occasionally blocks the soundcard although I have vmix enabled, so I should probably take a look at that at some point.

8:23 philip``: I don't think I had that problem when I first installed my system, so probably something changed with a kernel update at some point or something.

8:23 AWizzArd: fhd: bist du aus Köln? :)

8:23 Chousuke: I should try installing a Linux distribution at some point but I can't be bothered :P OS X has fewer annoyances.

8:24 (big ones, but fewer)

8:26 kryft: In addition to xmonad, I use a vertical keyboard from safetype ( http://www.safetype.com ) and vimperator for firefox, so guests who just want to check their webmail tend to be quite confused. :)

8:26 Chousuke: heh

8:26 LauJensen: kryft: You use Vimperator because you cant afford Conkeror?

8:26 Chousuke: I use vimperator too

8:27 I find vimperator to be better than conkeror :P

8:27 LauJensen: Chousuke: how so ?

8:27 kryft: LauJensen: Conkeror?

8:27 LauJensen: kryft: conkeror.org

8:27 Chousuke: vi keys work better for browsing than emacs keys

8:27 LauJensen: Chousuke: how so ?

8:27 Chousuke: emacs keys require too much movement away from home row

8:28 LauJensen: Chousuke: Got a link to an overview of the bindings?

8:28 afk

8:28 fro0g: as a conkeror alternative, have you tried keysnail?

8:28 Chousuke: LauJensen: j/k and link hints with mostly homerow characters. pretty much all you need.

8:28 kryft: LauJensen: Huh, hadn't heard about that. I'm quite happy with vimperator, though, and it's easier to install the extension all over the place than to actually install a new browser. :)

8:29 fro0g: http://github.com/mooz/keysnail/wiki

8:29 shoover: Chousuke: define_key(default_global_keymap, "j", "cmd_scrollLineDown");

8:29 define_key(default_global_keymap, "k", "cmd_scrollLineUp");

8:29

8:29 Chousuke: but I suppose if you're used to emacs Conkeror is better for you.

8:29 kryft: Also, if Conkeror doesn't have vimish keybindings, it's not an alternative. =)

8:30 That reminds me; I'm considering migrating from vim to emacs+vimpulse (or whatever they have these days)

8:30 Chousuke: I find the vi input model superior to emacs'. As an editor, however, emacs is better.

8:30 kryft: Has anyone tried that?

8:30 Chousuke: Heh, that's precisely why I'm considering emacs+vimpulse. :) Best of both worlds, it would seem.

8:30 In principle at least, which is why I'm curious about people's experiences.

8:30 Chousuke: The problem with viper/vimpulse is that most emacs extensions don't work well with it.

8:31 they expect the emacs input model

8:31 and break vi stuff in weird ways.

8:31 philip``: I tried conkeror out one time, but i couldn't get RndPhrase working, so it was pretty much a no-go since i couldnt log in anywhere...

8:31 Chousuke: so basically you'll be able to edit text with vi keybindings just fine but any more advanced stuff is going to have to be done with emacs keybindings.

8:32 philip``: Liked the idea though.

8:32 kryft: Chousuke: Can you give an example of more advanced stuff?

8:32 Chousuke: kryft: using paredit, for example

8:32 kryft: Chousuke: What's that? :P

8:33 Chousuke: structural editing for lisp code (and some non-lispy languages too)

8:33 kryft: Ah, that's a minor mode, I guess viper/vimpulse is a minor mode too?

8:33 Chousuke: yeah

8:34 kryft: Chousuke: So what do you use?

8:34 philip``: Going home.

8:34 Chousuke: I use vi for quick editing and emacs for serious stuff :P

8:35 kryft: Hmm, I feel quite lost without vi editing commands. :/

8:35 Chousuke: Well I haven't invested that much into either editor.

9:08 fhd: AWizzArd: Ja :)

9:08 kryft: Is that 'yes' or 'and'?

9:09 fhd: "Yes" :)

9:09 kryft: (I'm guessing 'yes', but I'm a stupid parser ;)

9:36 LauJensen: Chousuke: Okay cool, I'll try Vimperator. though I fear I will never be happy until I've integrated Conkerors keybindings into Uzbl

9:36 fhd: But I'm wondering. If Hickey doesn't like TDD, why is the testing support of Clojure so neat?

9:37 Sure, it could be used for plain old unit testing, but come on, that's boring...

9:38 LauJensen: fhd: I haven't heard his views directly from him so dont put too much weight on it. What I know is that Rich and I are both inspired by the talk Out of the Tar pit (http://web.mac.com/ben_moseley/frp/paper-v1_01.pdf) which IIRC talks about reducing complexity to enhance your ability to reason up front as a way of quality assurance, as an opposite to letting your test suite dictate your code

9:40 fhd: Hm, sounds similar to TDD. TDD is not really about testing, it's more about design in fact.

9:41 Leads to real nice designs in Java IMO, but I'm not yet sure if it makes sense in Clojure. I found that I have difficulties applying it, so I stopped and decided to try it once I'm more confident with the language.

9:42 bobo_: i agree

9:42 the tests that come out of TDD is not the most important thing, but it is a realy nice addition :-)

9:44 noidi_: what's the difference between clojure.contrib.seq-utils and clojure.contrib.seq? is one deprecated in the favor of the other?

9:44 their documentation is identical... http://richhickey.github.com/clojure-contrib/#seq

9:46 chouser: noidi_: hm. probably clojure.contrib.seq-utils is deprecated in favor of the other, though a docstring to that effect sure would be nice.

9:46 then -utils naming scheme is "older"

9:49 quizme: mrbliss: thanks

9:51 noidi_: chouser, thanks

9:58 defn: chouser: good idea -- it would be nice to have doc-strings which say if we're using functions from a deprecated namespace

10:01 chouser: defn: I think there are some plans in the works to manage contrib differently. Should help with this kind of version management task.

10:02 LauJensen: chouser: which plans?

10:03 chouser: LauJensen: I haven't heard any decisions announced

11:25 Munksgaard: When i try to evaluate something which throws an exception in my repl (in emacs, via cake swank) the exception-window (the one where i can chose to quit, continue etc) doesnt show up. The buffer is there, and i can switch to it, but (unlike normal slime with clisp or sbcl) emacs doesnt automatically switch to the error handling window. This causes some annoyances (in particular it makes error handling slow), is there

11:25 any way to fix it?

11:25 (It's me, philip´´´ from earlier :-) )

11:26 kryft: Munksgaard: Philip.. Munksgaard.. I think I see a connection!

11:26 Munksgaard: kryft: Indeed, Philip Munksgaard is my name! xD

11:26 kryft: Munksgaard: Amazing!

11:27 Munksgaard: I know right?

11:29 Still doesn't help my problem though :/

11:29 kryft: Sorry. :(

11:30 I suck at being helpful or useful.

11:30 Munksgaard: Me too, i just want help all the time :-(

11:31 esj: Munksgaard: I usually have two buffers up in emacs.

11:31 so when an exception/stacktrace is thrown it turns up in one of them and its easy to tab over and deal with

11:33 Munksgaard: esj: Well yeah, thats kind of what happens when i'm working with clisp. I have to buffers (a file and a repl) and when i evaluate something which causes an exception, the other buffer automatically switches to the exception and focus is switched to that buffer.

11:35 esj: but in clojure it doesn't ? Afraid I can't help you then, my emacs-fu is lame. I just installed form elpa to according Technomancy's instructions and went from there. Seems to work

11:40 Munksgaard: esj: Exactly, it's not the same in clojure :-(

11:40 esj: that's a bummer dude.

11:42 Munksgaard: hm, yeah. Guess i'm going to have to write perfect code without exceptions :-)

11:49 esj: that's the spirit

13:30 defn: chouser: good to hear -- i found the renames to be sort of a PITB

13:41 DeusExPikachu: i just read http://www.learningclojure.com/2010/10/latest-collection-of-filthy-hacks-for.html and the author asks if he is allowed to require everything in an agent in order to not block the repl startup, is there any forseable problems with this method?

14:09 scottj: Is there a way to write (defmacro by [x fname forms] `(do ~@(map (partial cons fname) (partition x forms)))) so (by 2 def [a 1 b 2]) and (let [c [a 1 b 2]] (by 2 def c)) and (by 2 def '(a 1 b 2)) all work?

14:09 chouser: Yes!

14:09 * chouser now reads the question.

14:10 chouser: oh. no.

14:11 scottj: there's some limitation to macros that I'm not grasping because I seem to run into this a lot

14:11 chouser: the problem is youre middle example. At compile time (when the 'by' macro is expanded) the fact that there is a local named c is known, but it's runtime value has not yet been computed

14:12 the runtime value of c could be anything, computed in any number of ways (user input, etc) so 'by' cannot at compile time change it's behavior or output different code based on the *value* of c

14:14 scottj: does that make sense?

14:18 if you were willing to go a little nuts with the use of lexical context introspection and eval, you could make something that would (usually) work, but would have surprising (in the bad sense) performance characteristics

14:18 ...and in a larger sense is rarely the right approach.

14:20 scottj: yeah, the application is where I get tripped up. so macros can only output code based on their literal inputs, not what they resolve to?

14:20 chouser: They can only output code based on what's known at the time that form is compiled.

14:21 Imagine if your example were (defn f [& c] (by 2 def c)) (f a 1 b (slurp "foo.txt"))

14:26 scottj: not following that, hung up on a being evaled bc f is a fn

14:27 chouser: ok

14:27 np

14:27 (defn f [& c] (by 2 def c)) (f 'a 1 'b (slurp "foo.txt"))

14:27 scottj: with macros re the inputs to the macro is the only thing known at compile time their literal value?

14:28 chouser: right, the arguments are the forms themselves, not what they would evaluate to at runtime.

14:28 Chousuke: everything evaluated prior to the macro executing is available though

14:29 so def'd globals, java libraries (including reflection) etc.

14:29 chouser: with the forms come metadata (you can get their line number, type hints, etc). You also get access to the lexical context via &env and &form, so you can (with some effort) discover the names and perhaps types of locals that will be available to the code your macro returns.

14:30 so once you're in this deep, more important than the fact you're getting literals is *when* you're getting them.

14:30 when (defn f ...) is compiled above, no macro in its body can possibly know what the value of c is going to be at runtime.

14:31 it just hasn't happened yet

14:31 scottj: but for you specific example, you've got a few options

14:32 (map (partial apply intern *ns*) '{a 1 b 2}) ; works fine -- no macros!

14:33 you could write a function intern* so that it's just (map intern* '{a 1 b 2})

14:33 ...but that's because there's a function 'intern' that does much of what 'def' does.

14:34 most other macros or builtins would be much harder to work with

14:34 scottj: nice, I actually want a generic by more than specifically a def with multiple args

14:34 chouser: yeah, I figured.

14:35 LauJensen: chouser: Isnt his middle-example doable by peeking in &env?

14:36 chouser: (let [c [true (prn :ok) (prn :oops)]] (by 3 if)) ; never gonna work right

14:36 LauJensen: no

14:38 peeking at &env could tell you c is a local. If it's not a fn argument, you could (in a unsupported, fragile way) look at the form used to initialize it ...but that could itself of course be a function call or any other runtime thing.

14:39 gary_poster: Hi. I'm using spare moments to play with clojure and liking it. While playing, I just encountered a behavior I can't figure out quickly. I don't understand something simple, I suspect. Given...

14:39 (require '[clojure.contrib.str-utils2 :as s])

14:39 This works

14:39 (#(s/join " " %) `("hello" "world"))

14:39 but this gives me "java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector"

14:39 (-> `("hello" "world") #(s/join " " %))

14:39 chouser: in hact, (let [c [a 1 c 2]] ...) is simply a syntax error unless a and b are already defined.

14:39 in fact

14:39 gary_poster: Is someone willing to enlghten?

14:39 chouser: and if they are defined, c will have their values, not their names.

14:40 hiredman: gary_poster: macroexpand the form

14:42 raek: gary_poster: -> and anonymous functions can be a bit surprising

14:42 scottj: chouser: thanks for the help

14:43 raek: (-> foo #(bar %)) --> (-> foo (fn [%] (bar %))) --> (fn foo [%] (bar %))

14:43 gary_poster: hiredman, raek, wow, yeah, that's not what I expected at all. thank you

14:47 So I guess the intended work-around is either "don't do that" or

14:47 (-> `("hello" "world") (#(s/join " " %)))

14:47 which works

14:47 TeXnomancy: gary_poster: you probably want ' instead of `

14:47 the latter is mostly meant for macro use

14:48 gary_poster: ah, k, thank you TeXnomancy

14:48 I think I might have known that at one point ;-)

14:52 chouser: gary_poster: right. or maybe you want the thrush combinator instead of ->

14:53 gary_poster: http://blog.fogus.me/2010/09/28/thrush-in-clojure-redux/

14:54 gary_poster: (thrush '("hello" "world") #(s/join " " %)) might do what you expect

14:55 raek: gary_poster: had never thought about putting it in parens...

14:55 hiredman: chouser: I doubt it

14:55 gary_poster: chouser: was reading, looks very nice. Experientially, it does work.

14:55 raek: but that seems to solve the problem

14:55 chouser: hiredman: oh? why's that?

14:55 hiredman: oh, thinking of K

14:55 chouser: oh

14:55 gary_poster: chouser: BTW, purchased your book & like it :-)

14:56 congrats

14:56 chouser: gary_poster: thanks! glad you like it.

14:56 hiredman: I'm lousy with the combinators. 'map' is as much as I can handle.

15:08 iwillig: is there a way i can search for reference types from within slime ?

15:08 like i want to find the location of a type on my class path

15:14 arkh: I'd like to use a lazy and infinite sequence in a for - (take 100 (for [x (range 10) y (range 10) z (lazy-sequence-thing 1000)] ... ) ;;; Is there a better way than to use take ? Downside with take is a person has to multiply x and y to take the right number.

15:16 chouser: are you intentionally only using the first thing from (lazy-sequence-thing 1000)

15:16 ?

15:16 arkh: well ... multiply the number of elements in x and y

15:16 chouser: but you want z to only ever be the first value from (lazy-sequence-thing 1000)?

15:16 arkh: I'd like to use as many things of the lazy sequence as there are elements in x and y combined/multipled

15:17 chouser: er, wait.

15:18 ,(take 9 (for [x (range 3) y (range 3) z (range 100)] [x y z]))

15:18 clojurebot: ([0 0 0] [0 0 1] [0 0 2] [0 0 3] [0 0 4] [0 0 5] [0 0 6] [0 0 7] [0 0 8])

15:18 arkh: actually, here's what I have: (take 20 (for [subday (range 10) day (range 2) value (next (lazy-change 1000))] (str day " " subday " " value))))

15:19 chouser: lazy-change is infinite?

15:19 arkh: yes

15:19 chouser: then subday and day will always be 0

15:20 no matter how many you take

15:20 arkh: oh yeah! because it happens from the 'right-side' first ...

15:20 : ( lol

15:20 chouser: yeah

15:20 arkh: sorry

15:20 we can reverse the order of subday, day, and value

15:20 chouser: do you want to be cycling through subday and day in step with lazy-change?

15:21 arkh: yes

15:21 chouser: ,(map vector (for [x (range 3) y (range 2)] [x y]) (range 100))

15:21 clojurebot: ([[0 0] 0] [[0 1] 1] [[1 0] 2] [[1 1] 3] [[2 0] 4] [[2 1] 5])

15:22 chouser: map is the way to walk more than one seq in step, and stops as soon as any of them end, so ... just what you want, I think.

15:22 arkh: yes - thank you very much

15:23 gary_poster: ...ooh, clojurebot, cool...

15:24 jacortinas: ,(println "yup")

15:24 clojurebot: yup

15:24 gary_poster: lol

15:29 lpetit: Hello ther e!

15:29 chouser: lpetit: hi!

15:30 LauJensen: lpetit: bonjour mon ami! c'est la vie? qui qui!

15:30 lpetit: LauJensen: I wish I could talk Danish as you speak French, my friend !

15:31 LauJensen: haha

15:33 iisjmii: Can anybody tell me how to gice clojure a typehint for an array of integers (as created by int-array) is it #^Integers?

15:33 hiredman: #^ints

15:34 I believe

15:34 iisjmii: thx

15:34 hiredman: well, ^ints if you are using 1.2

15:34 iisjmii: and do you know if I have to give type hints to all nested bindings?

15:35 shanmu: hi all, any feedback on clj-record in the community? (I did google, but could not get any conclusive answers)

15:37 Is it quite polished or does it need TLC to get it to work?

15:38 ossareh: what is clj-record?

15:38 shanmu: http://github.com/duelinmarkers/clj-record "clj-record is a Clojure persistence library inspired by Ruby on Rails’ ActiveRecord but aimed at using LISPey functional idioms."

15:38 it does not seems to be based on clojureQL

15:42 chouser: I'm suspicious of all ORB

15:42 lpetit: chouser: you mean ORM ?

15:42 chouser: and my experience with ActiveRecord informs that opinion. But I haven't looked at clj-record at all.

15:43 lpetit: er, yeah, that. :-)

15:43 shanmu: I am tempted to roll my own with ClojureQL as an abstraction layer

15:43 not a full blown ORM, but whatever my project demands.. (more of a FRM functional relational mapper)

15:46 romain_p: hi, who wants to help a beginner improve his code?

15:46 http://pastebin.com/UnmC4g9J

15:46 (trying to create a map that index a list of words by count)

15:47 shanmu: romain_p: if you want a ready made solution, look at frequencies

15:47 ,(doc frequencies)

15:47 clojurebot: "([coll]); Returns a map from distinct items in coll to the number of times they appear."

15:47 shanmu: (source frequencies) would help refine your code

15:47 romain_p: shanmu: tx

15:48 LauJensen: ,(reduce #(assoc %1 %2 (inc (get %1 %2 0))) {} ["hi" "there" "oh" "hi"])

15:48 clojurebot: {"oh" 1, "there" 1, "hi" 2}

15:48 LauJensen: romain_p: Coming from imperative languages you naturally look for loop, but often reduce is more idiomatic

15:48 raek: what is the best way of representing the null character in code? \u0000 ?

15:49 it gets printed as \^@ for me

15:49 maybe that's slime...

15:49 romain_p: LauJensen: tx

15:51 raek: ,\u0000

15:51 clojurebot: \

15:52 shanmu: what is (or is there) a group/artifact id for using clojureql with leiningen?

15:52 bobo_: shanmu: http://clojars.org/org.clojars.snuxoll/clojureql that one?

15:53 shanmu: bobo_: not sure - clojureql seems to be from bestinclass.dk

15:53 raek: http://gitorious.org/clojureql/clojureql/blobs/master/build.gradle seems to indicate [clojureql "0.9.7"]

15:53 shanmu: raek: thanks!, checking

15:54 raek: http://new.clojars.org/repo/clojureql/clojureql/0.9.7/

15:54 LauJensen: bobo_: that snuxoll guy is weird. He worked ClojureQL, broke it, then put the jar on Clojars.

15:54 raek: the only version on clojars, anyway

15:54 bobo_: LauJensen: :-/ thats the problem and benefit of clojars

15:54 its ffa

15:54 LauJensen: sure is.

15:55 shanmu: LauJensen: are you the LauJensen behind clojureql?

15:55 LauJensen: shanmu: yea

15:55 bobo_: im suprised to see a build.gradle from LauJensen ? wheres the cakelove?

15:55 LauJensen: http://clojars.org/clojureql

15:55 shanmu: LauJensen: cool.. thanks for the work!

15:55 LauJensen: bobo_: Meikel, my co-pilot on ClojureQL, wrote Clojuresque. Though for version 1.0 I'll likely switch to Cake :)

15:56 shanmu: np, its a team effort though

15:56 bobo_: :-)

15:59 dont think ive been at gitorious before, i dont think i like i

15:59 t

16:05 LauJensen: bobo_: We moved because Github at one time was unuseably slow. We emailed them for action and waited a couple of months, then moved

16:06 Its actually been quite pleasant. They have a great system for handling merge requests etc

16:10 bobo_: yeh github can be insaenly slow sometimes :-/

16:14 LauJensen: I haven't experienced it in the last 6 months or so

16:16 kevins_: I have a n00b question (just getting my feet wet w/ Clojure)

16:16 trying this : user=> (map first ["hello" "world"])

16:16 (\h \w)

16:17 first is the first letter of each string, how do I get all of the chars of the string (i.e. results would be (\h \e \l \l \o...etc..)

16:17 so not first, not rest....the entire string in chars..

16:17 Chousuke: (seq string)

16:17 kevins_: seq..

16:17 Chousuke: ,(seq "foo")

16:17 clojurebot: (\f \o \o)

16:17 Chousuke: seq makes sequences of sequenceable things :)

16:18 kevins_: I tried .toCharArray...but I got back a list of references....I'll read up more on seq.

16:19 raek: the functions that take a sequence in clojure will call seq on their argument

16:19 Chousuke: kevins_: the sequence is a basic abstraction in clojure

16:19 raek: which is most often called 'coll' in the docs

16:20 (seq (.getBytes "hello" "US-ASCII"))

16:20 hiredman: I am sure you meant utf8 there

16:20 raek: can turn almost anything sequential into a seq

16:21 hiredman: I didn't want to scare the mundanes... :-)

16:21 but yes. UTF-8 is the one and only.

16:22 karmazilla: Can protocols extend other interfaces? 'cause I'd like to define a protocol that is also clojure.lang.Indexed

16:22 kevins_: so seq is saying turn this string into.....an array or vector? (or I shouldn't really care)

16:23 Chousuke: kevins_: neither; it becomes a sequence.

16:23 kevins_: and the sequence is actually just a list-like view into the underlying string

16:24 so the string doesn't change (it can't anyway, it's immutable). You instead get a new thing, which is the sequence.

16:25 and you can do lots of things to sequences. first and rest are the basic operations, but lots of clojure functions work with sequences.

16:25 usually you don't need to call seq on anything directly though. (unless you're checking for emptiness).

16:26 -> (map str "foo")

16:26 ah blah, sexpbot not here

16:26 ,(map str "foo")

16:26 clojurebot: ("f" "o" "o")

16:26 Chousuke: so, like that.

16:26 ivey: where is sexpbot?

16:27 kevins_: the larger example I was playing with was (frequencies (map first words)))

16:27 Chousuke: ,(apply str (reverse "foo")); or like that.

16:27 clojurebot: "oof"

16:27 kevins_: and I wanted to get all letters out of the words list...not just first.

16:29 Chousuke: hmm

16:29 ,(apply concat ["some" "words"])

16:29 clojurebot: (\s \o \m \e \w \o \r \d \s)

16:30 Chousuke: concat concatenates sequences (what the strings automatically become) and apply is needed to concat a sequence of sequences.

16:31 fhd: Hi. I'm using defprotocol to use the mock object pattern in test-driven development, because someone in this channel pointed me to that function earlier.

16:31 kevins_: this works, but it's not idiomatic? (frequencies (map seq words))

16:31 fhd: It works fine, but I feel like I'm trying to do Java in Clojure here. It doesn't help that the examples usually use camel case for defprotocol and deftype.

16:32 What do you think? Should I avoid these functions?

16:32 Chousuke: kevins_: are you sure you want that?

16:32 kevins_: wouldn't that count the frequencies of the words?

16:33 kevins_: and that should be pretty much the same as (frequencies words) anyway

16:36 kuriouskat: Hi! I'm new to clojure and fp in general. I saw the look-and-say golf puzzle in stack overflow (ref: http://en.wikipedia.org/wiki/Look-and-say_sequence)

16:36 I thought I shall try it out in Clojure.

16:36 Here is my attempt thus far.

16:36 (defn lazy-look-and-generate[] (iterate (fn[x] (mapcat (fn[n] (loop[x1 (first n) y (rest n) count 1] (if (= x1 (first y)) (recur x1 (rest y) (inc count)) (conj nil count x1)))) x)) [1])) (print (lazy-look-and-generate))

16:37 kencausey: kuriouskat: please use a paste site like paste.lisp.org

16:37 kuriouskat: sure sorry

16:39 http://paste.lisp.org/+2H22.

16:39 I'm seeing a runtime exception. Any pointers on where I might be going wrong would be appreciated

16:55 amalloy: ,(conj nil count [1 2 3])

16:55 clojurebot: ([1 2 3] #<core$count clojure.core$count@bc5a71>)

16:55 raek: kuriouskat: a runtime exception often means that the delayed code of the lazy seq raised an exception

16:55 amalloy: kuriouskat: ^^

16:55 raek: kuriouskat: try looking at the 'cause' of it

16:56 amalloy: you probably want (count x1), not count x1

16:56 raek: count is a loop variable in his code

16:56 amalloy: oh. blurgh, so it is

16:57 raek: ,(conj [] 1 2)

16:57 clojurebot: [1 2]

16:57 amalloy: ,(conj nil 1 2)

16:57 clojurebot: (2 1)

16:58 raek: (conj nil count x1) could also be written as (list x1 count)

16:59 jkkramer: kuriouskat: you might also consider researching clojure's core seq functions. loop is usually not the best first choice

16:59 ,(take 6 (iterate #(mapcat (juxt count first) (partition-by identity %)) [1]))

16:59 clojurebot: ([1] (1 1) (2 1) (1 2 1 1) (1 1 1 2 2 1) (3 1 2 2 1 1))

17:00 jkkramer: not quite right...

17:00 amalloy: jkkramer: it looks right to me

17:01 jkkramer: oh, right, it is. misread the wikipedia page when double-checking

17:01 kuriouskat: I converted (conj nil 1 2) to (list count x1)

17:01 still the same exception

17:01 @jkkramer: it looks right to me

17:04 raek: kuriouskat: in your call (rest n), n have the value 1

17:05 the function given to mapcat gets applied for all values in [1], i.e. 1

17:06 I would split up that function into two: one for the "step" and one for the repeated invokation

17:06 that way, it is much easer to test the step logic in the repl

17:10 kuriouskat: <raek> is there something like list-of-lists then?

17:11 By the way, all these are useful pointers. Thx @raek and @jkkramer

17:12 raek: [[1]] ?

17:12 kuriouskat: yeah

17:12 that should be it right. I'm testing it out

17:13 no respise

17:28 scottj: ant in clojure dir builds .jar in clojure dir but mvn install tries to install the jar in clojure/targets . am I missing something for installing custom clojure build in maven?

17:36 jjido: given a function f, can you tell its maximal arity?

17:36 amalloy: TeXnomancy, ninjudd: i'm spending like hours fighting to get ant/maven to cooperate with eclipse in an open-source java project i'm trying to extend. i've never appreciated lein/cake more

17:37 ,(:arglists (meta (#clojure.core/seq)))

17:37 clojurebot: No dispatch macro for: c

17:38 amalloy: ,(:arglists (meta #'clojure.core/seq))

17:38 clojurebot: ([coll])

17:38 amalloy: jjido: you can use this if you have the var associated with the function. not sure if you can do it when you've been passed it

17:39 jjido: amalloy: I will try

17:46 TeXnomancy: jjido: there's an example of inspecting the arglists in leiningen.core; leiningen uses the arglists to determine if a task is standalone or needs to run in the context of a project

17:47 jjido: I realised that I can't tell the arity of functions with &

17:48 TeXnomancy: ,Double/POSITIVE_INFINITY

17:48 clojurebot: Infinity

17:49 TeXnomancy: that doesn't roundtrip; somewhat lame.

17:51 jjido: lol

17:51 what is the equivalent of (contains?) for a list?

17:53 I can use not-any? since I want to negate it

17:55 jkkramer: ,(doc some)

17:56 clojurebot: "([pred coll]); Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence, otherwise nil: (some #{:fred} coll)"

18:04 raek: jjido: you could use 'some', but in many cases it makes more sense to do contains? on a set

18:05 ohpauleez: jjido: 'some' is the standard idiom for lists or vectors

18:05 ,(some #{3} [1 2 3 4 5])

18:05 clojurebot: 3

18:05 ohpauleez: ,(some #{7} [1 2 3 4 5])

18:05 clojurebot: nil

18:05 jjido: ,(contains? '("a" "b" "c") "c")

18:05 clojurebot: false

18:06 jjido: ,(not-any? #(= % "c") '("a" "b" "c"))

18:06 clojurebot: false

18:06 jjido: ,(not-any? #(= % "d") '("a" "b" "c"))

18:06 clojurebot: true

18:07 raek: ,(contains? #{1 2 3} 1)

18:07 clojurebot: true

18:07 jjido: ,(contains? (set '("a" "b" "c")) "c")

18:07 clojurebot: true

18:08 raek: checking if something is in a set is a very fast operation

18:08 jjido: ,(nil? (some #{7} [1 2 3 4 5]))

18:08 clojurebot: true

18:10 jjido: ,(source not-any)

18:10 clojurebot: java.lang.Exception: Unable to resolve symbol: source in this context

18:40 jjido: ,(-> (fn [a] (+ a a)) (fn [f] (f 1)))

18:40 clojurebot: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol

18:40 jjido: mmh :(

18:41 MayDaniel: ,(macroexpand-1 '(-> (fn [a] (+ a a)) (fn [f] (f 1))))

18:41 clojurebot: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol

18:42 MayDaniel: Well it's putting the first function into (fn *here* [f]

18:46 Derander: ,(macroexpand #'foo)

18:46 clojurebot: java.lang.Exception: Unable to resolve var: foo in this context

18:46 MayDaniel: ,(macroexpand '#'foo)

18:46 clojurebot: (var foo)

18:46 Derander: you show off you

18:46 MayDaniel: Hehe.

18:48 amalloy: ~source not-any?

18:48 jjido: ^^

18:50 jjido: amalloy: nice (def not-any? (comp not some))

18:51 MayDaniel: I see, thanks

18:52 amalloy: also, you could fix your -> woes with an extra layer of parentheses

18:52 (macroexpand '(-> (fn [] foo) ((fn [f] (f)))))

18:52 ,(macroexpand '(-> (fn [] foo) ((fn [f] (f)))))

18:52 clojurebot: ((fn [f] (f)) (fn [] foo))

18:52 jjido: amalloy: I just defined a function that does (-> f rest)

18:53 ,(-> (fn [a] (+ a a)) ((fn [f] (f 1))))

18:53 clojurebot: 2

18:54 amalloy: the extra parens are to cause -> to splice after the whole fdecl, not just the first element (fn)

18:56 jjido: can I tell Clojure to take the standard input as a file (ie. not opening an interactive session)?

18:57 source file

18:58 amalloy: try cake run?

18:59 jjido: amalloy: what is cake? ;)

18:59 ohpauleez: jjido: there is a lein run too :)

18:59 amalloy: jjido: how do you get your repl?

18:59 ohpauleez: you can also setup a ./scripts

18:59 jjido: amalloy: clj

18:59 amalloy: jjido: clj < myfil.clj, then?

19:00 ohpauleez: maybe i haven't upgraded, but lein help doesn't list run as a task for me

19:00 ohpauleez: external plugin

19:00 jjido: ok I can pass - as argument to take the standard input as source, but (use) does not work

19:02 Derander: does anyone have an example of -> or ->> in use?

19:03 I read the description in the API doc but I can't visualize it

19:04 hiredman: http://gist.github.com/184831

19:04 from before ->> existed

19:04 jjido: Derander: not the best example, but I use -> for eg:

19:04 (-> [1, 2, 3] count)

19:04 ,(-> [1, 2, 3] count)

19:04 clojurebot: 3

19:05 jjido: on my own objects of course.

19:05 Derander: right

19:07 ohpauleez: Derander: typically you choose to use the threading macro if it simplifies readability only

19:07 often times you see it used when doing interop stuff

19:07 amalloy: ,(->> (range) (filter even?) (drop 100) (map dec) (take 10))

19:07 clojurebot: (199 201 203 205 207 209 211 213 215 217)

19:07 amalloy: Derander: does the above make any sense?

19:07 Derander: amalloy: reading

19:08 amalloy: ,(clojure.walk/macroexpand-all '(->> (range) (filter even?) (drop 100) (map dec) (take 10)))

19:08 clojurebot: java.lang.ClassNotFoundException: clojure.walk

19:09 hiredman: ,(-> (+ x x) (->> (fn [x]) (update-in {:a 0} [:a])))

19:09 clojurebot: {:a 0}

19:09 hiredman: ,(-> (+ x x) (->> (fn [x]) (update-in {:a 2} [:a])))

19:09 clojurebot: {:a 4}

19:09 Derander: amalloy: I believe I understand

19:09 checking the documentation for "dec" though. never seen that one

19:09 jjido: decrement

19:09 Derander: ah

19:10 amalloy: Derander: and if you want the source for anything you can always ask clojurebot

19:10 Derander: right

19:10 jjido: I solved my (use) issue, I needed to add . to the classpath

19:10 Derander: I don't have emacs on this machine setup for clojure dev like I do on my desktop

19:10 otherwise I'd just etags over to it :-/

19:24 bmh: What are the best practices for using Java libraries from clojure? Run everything through the interop or write a nice, tasty functional wrapper?

19:26 freakazoid: bmh: if you are making extensive use of the library you should wrap it

19:26 you don't want your clojure code to start looking like java :)

19:27 there are a number of wrappers for java libraries out there you could look at

19:27 bmh: That is a very good point. OK. Next question: I'm trying to pull a java library into my project. I've got the source yanked in and I've compiled it with lein-javac

19:28 When I try to :use it, the universe explodes with a "could not locate kylm__init.class" error

19:28 freakazoid: A really simple one being http://richhickey.github.com/clojure-contrib/server-socket-api.html which wraps java sockets, though it only exposes a small part of the interface

19:28 bmh: that's quite nice

19:28 freakazoid: is the jar file or class file in your classpath?

19:28 dnolen: bmh: you don't :use Java libraries, you :import the classes from that library

19:28 freakazoid: oh, java, right.

19:30 bmh: dnolen: Thanks

19:30 jjido: ~ delay

19:30 clojurebot: Excuse me?

19:30 jjido: ~delay

19:30 clojurebot: Pardon?

19:31 jjido: tsk tsk

19:31 ~get-me-a-beer

19:31 clojurebot: excusez-moi

19:33 bmh: thanks freakazoid and dnolen. I'll wrap this lib up tomorrow.

19:34 freakazoid: no problemo

19:37 nex_: why does:

19:37 (def ops '(+ /))

19:37 (map #(% 5 5) ops)

19:38 return (5 5) while i would expect (10 0)

19:39 (or: is it possible to map on a list of functions?)

19:42 amalloy: ,(map #(% 5 5) [+ /])

19:42 clojurebot: (10 1)

19:43 amalloy: nex_: it's the '(blah) that's tripping you up: it quotes + and / so that they're just symbols, instead of refs to the function you want to call

19:43 freakazoid: OH

19:43 amalloy: to make a literal list of things, usually vectors [a b c etc] are the way to go

19:44 freakazoid: geez, I'd been wondering what the difference was between '(…) and (list ...)

19:44 it's obvious in retrospect, but then again so are most things

19:44 amalloy: ,(let [a 10] [[a 1] '(a 1) (list a 1) `(a 1)])

19:44 clojurebot: [[10 1] (a 1) (10 1) (sandbox/a 1)]

19:45 nex_: amalloy: thanks, im repling it

19:47 freakazoid: syntax quotes rock

19:47 nex_: :) whoa fantastic

19:47 freakazoid: the more I learn about clojure the more I realize how well thought out it is

19:48 Dawgmatix: it builds upon lisp :)

19:48 freakazoid: I don't know that i would say that

19:48 CL, at least, needed a bunch of stuff ripped out.

19:48 Dawgmatix: i meant conceptually

19:48 freakazoid: So it builds upon lisp in the same way that people "add on" to their house in California

19:49 they tear down all but one wall and then completely rebuild everything else.

19:49 To keep the same property tax base.

19:49 Dawgmatix: i wasnt aware of this hack

19:50 freakazoid: Few people outside CA are, because it's ridiculous, because property tax law in CA is ridiculous.

19:50 It's a blatant subsidy for the rich.

19:50 Dawgmatix: :)

19:51 in cali every section feels another section is getting blatant subsidies

19:51 :D

19:51 freakazoid: I suppose you could say that.

19:51 But government is pretty much always coopted by the powerful.

19:52 Dawgmatix: i think were headed interesting offtopic territory

19:52 freakazoid: Indeed.

19:53 The offtopic conversation always seems so much better in the channels of the better languages

19:53 replaca_: chouser: you around?

19:53 freakazoid: #erlang and #clojure, vs say #ruby and #python

19:53 Dawgmatix: #python is in fact a great channel, though yes it stays strongly ontopic

19:54 #clojure is great too, chouser is always ready with answers

19:54 freakazoid: actually I was only guessing. I don't hang out on #python or #ruby.

19:55 being more mainstream, I would just guess they have a larger fraction of dumb people

19:55 though at least it's IRC, which many Ruby users probably can't figure out how to get into.

19:55 Dawgmatix: come on!

19:55 freakazoid: heh, maybe I'm mixing it up with #php

19:56 Ruby has a lot of smart people using it, but a lot of people who can't do any more than cut and paste.

20:03 amalloy: freakazoid: what the clojure community needs is more CL-like elitism...

20:04 freakazoid: Fine, fine

20:04 Though actually I'm perfectly happy to use Ruby or Python where they make sense

20:04 pretty much language agnostic except for languages that make it hard to write good code

20:06 kmc: i feel really dumb, but i can't find (by google etc.) a simple way to compute exponentials, i.e. a^b in Clojure

20:06 is there no built-in operator for this?

20:06 freakazoid: Math/pow

20:07 amalloy: kmc: i was doing this just the other night. clojure.math/expt

20:07 (math.pow uses doubles, so won't work for bigints)

20:07 freakazoid: Ohh

20:07 amalloy: ,clojure.math/expt

20:07 clojurebot: java.lang.ClassNotFoundException: clojure.math

20:07 freakazoid: clojure.contrib.math?

20:07 clojurebot: clojure > scheme

20:08 amalloy: no, he just doesn't have the other packages loaded

20:08 it works in a real repl

20:08 freakazoid: oh, ok

20:08 kmc: i'm an absolute noob, just started... do i need to import a package somehow?

20:08 ah cool (Math/pow 2 3) works

20:08 amalloy: kmc: (use 'clojure.math)

20:08 if you need precision; math/pow converts to floating-point

20:08 kmc: ok looks like i've got to set up my classpath etc

20:08 amalloy: ,(Math/pow 2 100)

20:08 clojurebot: 1.2676506002282294E30

20:09 amalloy: kmc: let me strongly recommend using either lein or cake. they manageall this classpath nonsense for you

20:11 freakazoid: cake is written in ruby? interesting choice

20:11 plathrop: kmc: +1 to what amalloy just said. With lein, clojure doesn't feel like java.

20:11 amalloy: clojurebot: lein?

20:11 clojurebot: the leiningen screencast is on full disclojure: http://vimeo.com/8934942

20:11 amalloy: clojurebot: cake?

20:11 clojurebot: cheesecake is delicious.

20:11 lancepantz: freakazoid: just the client script

20:11 freakazoid: oh, ok.

20:11 lancepantz: the same part of lein that is written in bash

20:12 freakazoid: I guess these days ruby is almost as likely to be installed as bash

20:12 amalloy: clojurebot: cake is http://github.com/ninjudd/cake

20:12 clojurebot: c'est bon!

20:12 lancepantz: it's nice, it was a good decision, gives us windows compatibility without cygwin

20:13 freakazoid: oh right windows

20:13 I keep forgetting that exists

20:14 not really but most of the time to me there are two platforms: mac and linux

20:14 it's from being molested by Windows as a child.

20:16 amalloy: anyway kmc i hope that wasn't all too overwhelming. let us know if you need help setting up a build tool

20:17 kmc: thanks a lot

20:17 "doesn't feel like java" is an attractive proposition

20:17 i'm managing with the REPL right now

20:18 btw does Clojure have a recursive "let" construct?

20:18 amalloy: kmc: recursive how? the answer is surely yes, i just don't understand the question

20:18 freakazoid: let* I'm guessing?

20:18 kmc: i tried let*

20:18 though it's possible i was doing something dumb

20:19 amalloy: kmc: let in clojure acts like let* in CL

20:19 ,(let [x 1 a (inc x)] a)

20:19 clojurebot: 2

20:19 freakazoid: oh hmm maybe I was thinking of racket

20:19 amalloy: freakazoid: clojure has a let*, it's just not public. rich uses it to bootstrap

20:20 ,(macroexpand '(let [x 1] x))

20:20 clojurebot: (let* [x 1] x)

20:20 freakazoid: I thought I'd seen it somewhere.

20:20 amalloy: ,(macroexpand '(let [x 1 y 2] x))

20:20 clojurebot: (let* [x 1 y 2] x)

20:20 kmc: ,(let [f #(cond (= % 0) 1 :else (* % (f (- % 1))))] (f 5))

20:20 hiredman: it is public

20:20 clojurebot: java.lang.Exception: Unable to resolve symbol: f in this context

20:20 hiredman: let* is a special form in fact

20:21 kmc: you want letfn

20:21 amalloy: hiredman: or recur

20:21 hiredman: for creating local recursive functions

20:21 amalloy: recur won't work there

20:21 kmc: ,(letfn [f [n] (cond (= n 0) 1 :else (* n (f (- n 1))))] (f 5))

20:21 clojurebot: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol

20:21 amalloy: but then you'd have to make it tail-recursive i guess

20:21 hiredman: kmc: you'll need to read the docs for letfn

20:21 kmc: ok

20:22 letfn doesn't do TCO?

20:22 amalloy: TCO isn't automatic in clojure, and your function isn't tail-recursive

20:22 kmc: yeah this one isn't

20:22 my real situation is

20:22 amalloy: ,(letfn [(f [n] (cond (= n 0) 1 :else (* n (f (- n 1)))))] (f 5))

20:22 clojurebot: 120

20:23 kmc: thanks!

20:23 hiredman: if it is self recursive you can use recur if it is not you can use trampoline

20:27 * kmc looks up recur

20:27 kmc: so i use it with 'loop'?

20:27 amalloy: kmc: or with functions. it recurs to either

20:28 hiredman: since i've got you here, i haven't totally grokked the Github Way. i tried to submit a pull request for clojurebot; did i succeed?

20:29 hiredman: yes

20:29 amalloy: ,(loop [n 10 res []] (if (zero? n) res (recur (dec n (conj res n))))

20:29 clojurebot: EOF while reading

20:29 amalloy: ,(loop [n 10 res []] (if (zero? n) res (recur (dec n (conj res n)))))

20:29 clojurebot: java.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$dec

20:29 amalloy: bah

20:29 ,(loop [n 10 res []] (if (zero? n) res (recur (dec n) (conj res n))))

20:29 clojurebot: [10 9 8 7 6 5 4 3 2 1]

20:33 amalloy: say i have some code that requires a Foo object, but i keep forgetting and passing it Bar objects, and i waste a lot of time tracing the call stack to see where i messed up. is this the sort of thing that function preconditions are supposed to solve?

20:35 kmc: wow i ran just 'cake' and it went nuts on my hard drive

20:35 feels like it tried to tar up my entire filesystem or somethingkillall java

20:35 amalloy: i think it downloads dependencies the first time you run it?

20:35 lancepantz: yep

20:35 maven has an ass-ton

20:36 there is a branch that uses ivy that's much more palatable, but it's still in progress

20:36 kmc: heh

20:36 ok, so cake makes my system unusable. guess it's lein then

20:36 amalloy: kmc: lein uses maven too

20:37 lancepantz: yeah, well you're installing something on your hard drive, ofcourse its going to spin up :)

20:37 amalloy: but this frenzied download should be a one-time thing, and i don't think it takes *that* much space, does it?

20:37 lancepantz: like 10 megs i think

20:37 amalloy: hm. my ~/.m2 has 116MB in it

20:38 lancepantz: kmc: how did it make your system unusable?

20:38 amalloy: but cake only has 12MB, as you say, lance

20:41 kmc: i don't know what it was doing but it pretty much killed my ability to use the system interactively

20:41 in way that bulk file transfers don't

20:42 amalloy: maybe build cake with --no-destroy-host-system :)

21:06 freakazoid: woo, penumbra looks pretty neat

21:15 kmc: lein takes about three seconds to start up and do anything

21:15 and 'lein repl' takes longer

21:15 is there a way i can reload my code inside the repl?

21:15 coldhead: cherish these moments

21:16 hiredman: lein repl is not the recommended why to use lein

21:16 lein swank or whatever the equiv is for vimclojure

21:17 you can reload your code using the provided features from your editor

21:19 kmc: ok, there's not a good standalone repl?

21:21 hiredman: kmc: clojure.main

21:21 kmc: suppose i'm representing coordinates within an image and i want to iterate from [0,0] to [w,h] in left-to-right, top-to-bottom order

21:21 what's the idiomatic clojure way to do this?

21:21 hiredman: for

21:21 ,(doc for)

21:21 clojurebot: "([seq-exprs body-expr]); List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], :while test, :when test. (

21:22 hiredman: ,(for [h (range 5) w (range 5)] [w h])

21:22 clojurebot: ([0 0] [1 0] [2 0] [3 0] [4 0] [0 1] [1 1] [2 1] [3 1] [4 1] [0 2] [1 2] [2 2] [3 2] [4 2] [0 3] [1 3] [2 3] [3 3] [4 3] [0 4] [1 4] [2 4] [3 4] [4 4])

21:24 dnolen: kmc: cake is pretty good, IMO, but it sounds like it didn't work out for you.

21:24 lein is pretty good too, now that you can hook into a running REPL via telnet

21:25 kmc: thanks hiredman

21:51 scottj: if I have [f1 f2] and [v1 v2] how do I get [(f1 v1) (f2 v2)] w/o writing that out?

21:59 bhenry: ,(vector (map list [:f1 :f2] [:v1 :v2]))

21:59 clojurebot: [((:f1 :v1) (:f2 :v2))]

21:59 bhenry: nope.

22:00 ,(doc vec)

22:00 clojurebot: "([coll]); Creates a new vector containing the contents of coll."

22:00 bhenry: ,(vec (map list [:f1 :f2] [:v1 :v2]))

22:00 clojurebot: [(:f1 :v1) (:f2 :v2)]

22:01 bhenry: scottj: something like that maybe? this is usually where someone else provides a better solution

22:01 scottj: bhenry: :) actually f's are functions

22:01 ,(map list [inc dec] [1 1])

22:01 clojurebot: ((#<core$inc clojure.core$inc@b9c46a> 1) (#<core$dec clojure.core$dec@58e72c> 1))

22:01 bhenry: ooh

22:02 jk_: bobo_: the tests that come out of TDD are very useful just for testing when it comes to regression testing though

22:02 bobo_: not just a design thing

22:03 chouser: ,(map #(%1 %2) [inc dec] [5 10])

22:03 clojurebot: (6 9)

22:04 bhenry: damn chouser i just got that same thing, (map #(%1 %2) [inc dec] [1 1])

22:05 scottj: chouser: so there's no name for that?

22:05 hiredman: it's almost apply

22:05 (map apply [inc dec] [[1] [1]])

22:06 ,(map apply [inc dec] [[1] [1]])

22:06 clojurebot: (2 0)

22:39 scottj: I read news.arc (hacker news source)last night, pretty interesting. the entire website is in one file. Arc has this shorter member lookup syntax so instead of (host :ip) you just do host:ip. I implemented it in LispReader.java in a few lines. normally destructuring is better but if you have three objects with the same key name then I think (foo host:ip proxy:ip client:ip) would be nice. unfortunately it doesn't if the hash isn't already bound to a local, at

22:45 dpritchett: the clojureCLR update on the mailing list is pretty exciting

22:46 i fired it up and tried a load-file and couldn't make it work though :(

23:05 kmc: i have a sequence named 'points' defined with 'for'

23:05 and a function 'out-pt' which has some side effect

23:05 (doseq [pt points] (out-pt pt) ; will perform all the effects

23:05 (map out-pt points) ; will not

23:06 and i'm not sure why

23:06 hiredman: read the docs for map and for doseq

23:06 I highly suggest you read docs

23:07 kmc: i have been, but i'll take another look

23:08 ah so the problem is that map returns a lazy sequence

23:09 TeXnomancy: clojurebot: map?

23:09 clojurebot: map is lazy

23:10 kmc: so is there something i can use with the syntax of map, which will perform effects right away?

23:10 TeXnomancy: a classic

23:10 scottj: see dorun and doall

23:11 kmc: thanks

23:12 amalloy: kmc: also doseq

23:13 oh, i see you already found out about doseq. that's what i get for contributing before reading all the logs

23:51 kmc: i'm mapping over a bunch (60,000) of independent computations

23:51 i replaced map with pmap and it runs slower

23:51 from reading some discussion online, it sounds like this is common, but it's not clear what the solution is

23:51 hiredman: have you read the doc string for pmap?

23:52 kmc: yes

23:52 hiredman: and you saw the last part?

23:52 kmc: yes

23:52 but it's a vague qualitative statement; i don't know what the coordination overhead is

23:53 let me put it this way, my 60,000 computations take 20 seconds sequentially

23:53 jkkramer: kmc: a common strategy is to partition a collection into batches before parallel processing

23:53 kmc: which means each one takes 1/3 millisecond

23:53 which seems pretty big to me

23:53 hiredman: doesn't sound computationally intensive

23:54 kmc: eh like i said, the doc string gives no quantitative guideline

23:54 jkkramer, sounds good, is there a standard way to do this or shall i roll my own?

23:55 jkkramer: kmc: not sure if anyone's abstracted it out into a lib, but there are snippets out there

23:55 kmc: ok

23:56 jkkramer: usually involving a combination of partition-all, pmap/futures, reduce, etc

23:56 kmc: looks not too bad

23:59 jkkramer: kmc: here's a rudimentary example: http://gist.github.com/517696

Logging service provided by n01se.net