#clojure log - Dec 12 2010

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

3:07 kumarshantanu: hi, is there a shorter way to write this: #(and (number? %) (pos? %))

3:38 pppaul: write your own function and call it (positive-number?)

3:39 kumarshantanu: pppaul: that's what I just did :)

3:39 pppaul: you may be able to get away with just (pos?) no?

3:39 kumarshantanu: ,(pos? :hello)

3:39 clojurebot: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.Number

3:39 pppaul: ewww

3:39 oh well

3:42 kumarshantanu: is there a function to find out the index in a vector? (foo [:a :b :c]) --> [0 1 2]

3:43 not exactly like the foo above, but some variations

3:43 G0SUB: kumarshantanu: you mean given [1 2 3] and 2, the result should be 1?

3:44 kumarshantanu: G0SUB: I want to find out the indexes of positive numbers in a vector

3:45 G0SUB: kumarshantanu: there is no built-in fn for that, but can be written trivially.

3:58 kumarshantanu: did you write the function?

3:59 kumarshantanu: G0SUB: almost..I zipmap'ed (take elem-count (iterate 0)) and the vector

4:00 and then filter'ed to find out which keys were affected

4:01 not sure if this is the most efficient way though

4:03 s/iterate 0/iterate inc 0/

4:04 G0SUB: kumarshantanu: you can use for. let me give you a quick example.

4:05 kumarshantanu: G0SUB: sure

4:08 G0SUB: kumarshantanu: http://paste.lisp.org/display/117598

4:09 * kumarshantanu looks at G0SUB's paste

4:12 kumarshantanu: G0SUB: version 1 is cool (short) but it returns the indices in reverse order

4:12 version 2 maintains the order

4:12 both are cool though

4:12 G0SUB: kumarshantanu: yes. you can do a reverse on it if you care about the order.

4:13 raek: there's map-indexed in core too...

4:13 ,(doc map-indexed)

4:13 clojurebot: "([f coll]); Returns a lazy sequence consisting of the result of applying f to 0 and the first item of coll, followed by applying f to 1 and the second item in coll, etc, until coll is exhausted. Thu...

4:14 G0SUB: raek: yes. that got added in 1.2. completely forgot :)

4:15 raek: too bad stuarthalloway's 'indexed' from Programming Clojure isn't there

4:15 kumarshantanu: learned today -- map-indexed and remove (I should be reading the core/docs often)

4:16 raek: (defn indexed [coll] (map vector (iterate inc 0) coll))

4:16 kumarshantanu: G0SUB: thanks!

4:16 G0SUB: raek: yes, that's useful when the fn takes k & v

4:16 kumarshantanu: you are welcome.

4:17 raek: to just get the indices, consider ##(range (range 0 (count [:a :b :c])))

4:18 sexpbot: java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to java.lang.Number

4:18 raek: &(range 0 (count [:a :b :c]))

4:18 sexpbot: ⟹ (0 1 2)

4:19 G0SUB: kumarshantanu: (defn take-idx-when [coll pred] (remove nil? (map-indexed #(when (pred %2) %1) coll)))

4:19 kumarshantanu: that should solve your problem.

4:21 kumarshantanu: raek: G0SUB: yup, this is cool

4:22 G0SUB: is it idiomatic to place pred after coll?

4:24 G0SUB: kumarshantanu: no. put the coll after pred. In this case, IMHO pred should come first.

4:24 kumarshantanu: G0SUB: okay

4:42 G0SUB: found a shorter version -- (keep-indexed #(if (pos? %2) %1) [-9 0 2 -7 45 3 -8])

4:42 ,(keep-indexed #(if (pos? %2) %1) [-9 0 2 -7 45 3 -8])

4:42 clojurebot: (2 4 5)

6:20 kumarshantanu: does println work asynchronously is 1.2?

6:20 s/is/in/

6:20 sexpbot: <kumarshantanu> does println work asynchronously in 1.2?

6:45 auser: hola

6:45 what does the '*' (star) mean after a function

6:48 kumarshantanu: auser: generally used for helper implementation fns

6:49 auser: not sure I understand... what does it mean though?

6:51 kumarshantanu: auser: assuming 'foo' is the function that is for public use, foo* is the functin that actually carries out the job and 'foo' just delegates the work to foo*

6:51 auser: ah

6:51 kumarshantanu: 'foo' calls 'foo*' to the actual work with some pre-configuration

6:51 auser: so it really could be either, but foo* used inside the namespace doesn't have to push off to the delegate

6:51 cool

7:02 thanks kumarshantanu

7:03 I've got one more question... is there a way to "fork" off a process?

7:04 I want to continuously poll for a queue to see if there's an item in it (unless I can "push" from the queue)

7:05 maybe like an agent

7:05 (from: http://faustus.webatu.com/clj-quick-ref.html)

7:06 kumarshantanu: auser: not a process, AFAICT

7:06 auser: (sorry, I come from the erlang world)

7:06 kumarshantanu: auser: but you can use threads, whiich is what jvm supports

7:07 look at ConcurrentLinkedQueue

7:07 auser: k

7:08 So you're suggesting I fork off a thread that does the "take"

7:08 kumarshantanu: tehnically you can, but forking off a thread is not so inexpensive as BEAM

7:09 so you can use a task executor thread-pool during the runtime of the operation

7:09 auser: yeah... that's one thing I'll miss with erlang in this current project

7:09 oh. okay?

7:09 kumarshantanu: a thread-pool maintains a pool of runnning threads, and returns the thread to the pool (but not killing it)

7:10 auser: oh that would work nicely I think

7:11 kumarshantanu: also, though not mentioned in the clojure docs, you may find hava.util.concurrent package very useful

7:11 s/hava/java/

7:11 sexpbot: <kumarshantanu> also, though not mentioned in the clojure docs, you may find java.util.concurrent package very useful

7:12 kumarshantanu: http://download.oracle.com/javase/6/docs/api/java/util/concurrent/package-summary.html

7:12 auser: that's funny, I was just looking at that

7:12 http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html

7:13 kumarshantanu: auser: yes, and you will probably find some clojure wrappers written by people to work with the task-executor framework

8:20 fliebel: Is Clojure a JSR 223 script engine? And what about other JVM languages? I came across the term a few times, and I'm wondering if it'd be possible to create a generic REPL for all these languages. (inside an applet?)

8:28 kumarshantanu: fliebel: Did you notice this? http://code.google.com/p/clojure-jsr223/

8:28 fliebel: kumarshantanu: No, I didn't

8:28 kumarshantanu: seems to be bringing 223 to clojure

8:29 AWizzArd: Does swank-clojure work with fresh builds of clojure.jar ?

8:29 fliebel: kumarshantanu: I did notice this: https://github.com/tinkerpop/mutant/wiki

8:31 kumarshantanu: fliebel: I noticed Mutant few days ago too...maybe useful for glue-work

9:10 * Tal

9:44 Nikelandjelo: How can I disable auto-casting (+ Integer/MAX_VALUE 1) to long? I need it to convert into Integer/MIN_VALUE?

9:45 mcav: ,(unchecked-add Integer/MAX_VALUE 1)

9:45 clojurebot: -2147483648

9:46 Nikelandjelo: Thanks

9:46 mcav: yw

10:14 Tordmor: Question: How would you generate a random sequence of digits of arbitrary size?

10:17 mcav: ,(take 5 (repeatedly #(rand-nth (range 10))))

10:17 clojurebot: (0 8 8 9 5)

10:20 mcav: ,(take 5 (repeatedly #(rand-int 10)))

10:20 clojurebot: (6 3 0 5 8)

10:27 Tordmor: mcav: Thanks, that looks great

10:27 mcav: Tordmor: glad to help

10:37 jk__: if i need to build a function that returns true or false, is it sufficient to have the function return non-nil or nil?

10:39 fliebel: jk__: Most of the time, yes.

10:39 jk__: this is for calling tree-seq

10:40 fliebel: i have functions that return a result or nil. wanted to know if there is any problem using them directly in tree-seq

10:40 fliebel: when you say "most of the time" that makes me nervous :)

10:40 fliebel: mcav: Why use rand-nth rather than rand-int?

10:41 jk__: The only problem is when you chekc explicitly for false?

10:41 mcav: fliebel: I wasn't thinking the first time; that's why I put rand-int right after that

10:42 fliebel: &(false? nil)

10:42 sexpbot: ⟹ false

10:42 jk__: i see. so only false is false

10:42 according to the predicate i mean

10:42 fliebel: but #(when nil true)

10:42 &(when nil true)

10:42 sexpbot: ⟹ nil

10:43 jk__: ,(doc when)

10:43 clojurebot: "([test & body]); Evaluates test. If logical true, evaluates body in an implicit do."

10:43 fliebel: So in the context of tree-seq, you should be fine I guess.

10:43 jk__: fliebel: because if i return a nil, it's not going to be true?

10:44 &(true nil)

10:44 sexpbot: java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.IFn

10:44 jk__: &(true? nil)

10:44 sexpbot: ⟹ false

10:44 fliebel: jk__: Everything except false and nil are true.

10:44 jk__: fliebel: but for (false?) only false is false

10:45 i think a part of my brain just exploded but that works for me

10:45 fliebel: (map boolean [1 [] true false nil 0])

10:45 &(map boolean [1 [] true false nil 0])

10:45 sexpbot: ⟹ (true true true false false true)

10:45 jk__: got it

10:45 thx!

10:46 fliebel: false? really checks of the argument IS false, not if it would be falsy.

10:47 jk__: it's like nil is just an unknown. it's neither true nor false

10:47 well no, that's not right either

10:47 nm

10:47 pdk: ,(boolean nil)

10:47 clojurebot: false

10:47 pdk: nil = false

10:47 jk__: .(boolean [])

10:48 ,(boolean [])

10:48 clojurebot: true

10:48 jk__: ,(false? nil)

10:48 clojurebot: false

10:49 jk__: nil is neither (true?) nor (false?)

10:49 ,(true? nil)

10:49 clojurebot: false

10:49 jk__: ,(= nil false)

10:49 clojurebot: false

10:50 jk__: ok sorry for the spam. i understand how it works. thx fliebel

10:53 raek: 'if' checks whether things are truthy or falsy

10:54 false and nil are falsy, everything else is truthy

10:54 'false?' checks whether something is the value false, rather than falsy

10:55 and vice versa for 'true?'

10:56 use (boolean ...) when you really need the value true of false

10:56 *true or false

11:02 jk__: raek: well that's the thing. tree-seq, for example, wants a function that returns true if a node has children, for example. if i do some sort of existence check and it returns a non-boolean thing, or nil, i wanted to just use it

11:02 raek: now for something that will cause your world to fall apart ;)

11:02 ,(true? (Boolean. true))

11:02 clojurebot: false

11:02 jk__: raek: wanted to know if i really had to transform the result to a real boolean

11:02 fliebel: raek: How mean!

11:03 raek: ("solution": no one should ever use that constructor.)

11:03 fliebel: jk__: You don't. It uses when, so nil will just work fine. ##(source tree-seq)

11:03 sexpbot: java.lang.Exception: Unable to resolve symbol: source in this context

11:04 raek: jk__: in most clojure code, you usually don't have to do that. for java interop though, you might need to do it.

11:04 jk__: ,(true? Boolean/FALSE)

11:04 clojurebot: false

11:05 jk__: ,(Boolean. true)

11:05 clojurebot: true

11:05 raek: ,(identical? true Boolean/TRUE)

11:05 clojurebot: true

11:05 jk__: ,(identical? false Boolean/FALSE)

11:05 clojurebot: true

11:07 jk__: ,(true? (Boolean. "true"))

11:07 clojurebot: false

11:07 jk__: ok gonna do real work now

11:07 thx guys

11:07 raek: :-)

11:07 fliebel: :)

11:15 gfrlog: ,(into {} [[1 2] [3 4 ][5 6]])

11:15 clojurebot: {1 2, 3 4, 5 6}

11:41 gfrlog: anybody got any ideas for the easiest way to plot a simple X-Y graph from clojure?

11:52 raek: gfrlog: incanter.

11:52 gfrlog: I had just gotten into that

11:52 has good features

11:52 no telling how much documentation browsing it will take before I can take a bunch of (x,y) pairs and save a basic line graph

11:54 fliebel: gfrlog: I found plot-fn to be useful for these things.

11:54 gfrlog: fliebel: thanks for the tip

11:55 xy-plot also looks promising

11:57 fliebel: gfrlog: Then you'd have to change the direction of your seq I think

11:59 gfrlog: what do you mean?

11:59 it takes an x seq and a y seq

11:59 fliebel: xy-plot takes [x x x x x x] [y y y y y y y] rather than x y pairs

12:01 What you could do is a plot-fn over the result of (into {} pairs) using (range (max-key pairs))

12:01 uhm, function-plot

12:02 gfrlog: it takes an arbitrary function?

12:03 fliebel: gfrlog: Yea, it takes a function, and invokes it for all xs and uses the result as y.

12:04 But xy-plot is probably better. Only you need to convert the input.

12:05 gfrlog: thanks for the help; I think xy-plot will work

12:07 fliebel: hmmm http://liebke.github.com/incanter/charts-api.html#incanter.charts/add-lines

12:28 jk__: $see cemerick

12:28 $seen cemerick

12:28 sexpbot: cemerick was last seen joining on :#clojure-casual 3 hours and 38 minutes ago.

12:28 cemerick: jk__: what's up?

12:28 Raynes: there's a bug for you ^^

12:28 jk__: cemerick: hey, you're one of the main committers on CCW right?

12:29 cemerick: I'm a commiter, yes. Not sure what constitutes "main", but whatever.

12:30 jk__: heh... i just had a question about whether "reformat" in the editor is in the plans. like if your indentation is broken in java, i hit ctl-shift-f to reformat the whole file. that doesn't work in ccw. note that i'm not whining here, i love ccw

12:31 that's really the only thing i miss

12:31 cemerick: jk__: I think Laurent has that in his working copy right now. Line-by-line reindentation is there -- just hit tab at the beginning of a line.

12:32 jk__: cemerick: aha! i didn't know that about tab

12:32 ordnungswidrig: hi

12:33 jk__: cemerick: that helps. i find that i frequently add a let or something and that skews the whole rest of a function. i was doing <end><enter><select to next line><del>

12:33 cemerick: <tab> is certainly much quicker :D

12:33 ordnungswidrig: what's the advantage of using letfn over let?

12:33 cemerick: jk__: yeah -- it's sort of a hack at the moment, IIRC.

12:34 I'm afraid the editor stuff itself is not my area of specialty in the codebase.

12:34 jk__: cemerick: btw, this plugin allowed me to avoid adding another monstrous learning curve (emacs) to the already big one with clojure. good work! i always used vi in the past

12:34 cemerick: All that stuff needs to get bound to the usual commands (e.g. Cmd-I, Cmd-Shift-F, etc)

12:35 jk__: are you using the 0.0.59 release, or the RC?

12:35 I'm really a bit-player -- thank lpetit when you see him. :-)

12:36 jk__: 0.0.64-STABLE01

12:36 cemerick: er, right, that :-)

12:36 jk__: :) i just looked

12:36 cemerick: jk__: there's an 0.2.0-RC1 available now, that has a much-improved REPL

12:37 jk__: cemerick: thanks for the tip. i'll upgrade my plugin then. this one is working well for me

12:37 cemerick: jk__: FYI: http://groups.google.com/group/clojuredev-users/browse_frm/thread/339b0347f6d15b17

12:37 jk__: ahh, nice. i didn't know about that group

12:37 cemerick: it's an RC, so eclipse won't present it as an upgrade. You'd have to uninstall and reinstall. Perhaps only for the brave :-)

12:38 jk__: cemerick: no problem. i've done that procedure hundreds of times on other plugins

12:38 cemerick: we'll probably have 1 or 2 more RCs, then release it (which will then offer it up as an upgrade)

12:38 jk__: well... maybe dozens :)

12:38 cemerick: That's definitely the place to post questions, issues, etc.

12:39 Laurent and I monitor it pretty regularly.

12:39 jk__: cemerick: when i hear people talking about emacs/swank or vi/nailgun stuff, i never really hear anything that seems to be lacking from CCW. it's really a nice plugin

12:40 cemerick: It's getting there :-)

12:40 fliebel: ordnungswidrig: letfn saves you some typing, but afaik the only real advantage is that you get to have mutually recursive functions.

12:41 cemerick: It has a ways to go in some areas, but what's there is very solid. And, eclipse is a great foundation.

12:41 jk__: cemerick: i use the maven plugin too and wrote an archetype for generating a clojure app with compojure and a couple other goodies added. your site gave me the added incentive to go full-bore with the maven and clojure plugins in eclipse

12:42 cemerick: :-)

12:42 jk__: I suspect that Mark (@talios, maintainer of clojure-maven-plugin) might be interested in archetypes.

12:43 One for "plain" projects and one for compojure webapps would make a lot of sense.

12:44 jk__: cemerick: i agree. my simple archetype just includes the dependencies, config to do src-only jar and a sample clojure file. i need to do another one to create an AOT compile war file

12:46 cemerick: i can give it to talios. i'll have to take out the repository entry for our internal artifactory :) everything goes through that internally

12:46 cemerick: right

12:46 I keep throwing example projects out there, but never get around to an archetype

12:47 jk__: yes, i started by cloning my sample project and renaming it, including in the .project file all the time, but it was getting too tedious. i finally broke down and whipped out the archetype so i could quickly start new small test projects

12:48 raek: ordnungswidrig: with letfn, the function can refer to itself. this can be done with let too. (letfn [(foo [...] ...)] ...) ~ (let [foo (fn foo [...] ...)] ...)

12:48 cemerick: I usually just copy a simple pom around a tweak :-)

12:49 jk__: cemerick: yes i should have done that. but that would work well enough that i'd be too lazy to do the archetype :D

12:49 raek: (however, mutually recursive functions using let can only be done with the letfn variant)

12:50 ordnungswidrig: raek: so it's just saving some typing

12:50 raek: pretty much

12:50 ordnungswidrig: ok

12:50 raek: except for the self-referring stuff

12:51 ,(let [foo (fn [] foo)] (foo))

12:51 clojurebot: java.lang.Exception: Unable to resolve symbol: foo in this context

12:51 raek: ,(letfn [(foo [] foo)] (foo))

12:51 clojurebot: #<sandbox$eval159$foo__160 sandbox$eval159$foo__160@32a325>

12:51 raek: stupid example, but you get the idea... :-)

12:53 the only time I have used letfn is when I needed a helper function to implement a lazy sequence

13:00 Lajla: raek,

13:00 I am the second best programmer in the world.

13:00 Ever told you that.

13:00 cemerick, how about my named recur

13:00 I want it.

13:00 If you can give this to me.

13:01 Then I will reward you handsomely.

13:01 bmh: What's a reasonable way to compare two doubles with a desired precision?

13:07 ordnungswidrig: raek: ok, thanks for explaining

13:17 npoektop: Adamant: hi! is there a way to make slime-autodoc work with clojure?

13:17 Adamant: don't know offhand

13:45 kumarshantanu: Question: how can I convert a string to a regex?

13:45 "hello" --> #"hello"

13:46 raek: ,(re-pattern "[0-9]+")

13:46 clojurebot: #"[0-9]+"

13:46 kumarshantanu: raek: thanks!

14:18 * raek gets inspired by this and starts to play with graphs: http://jkkramer.wordpress.com/2010/08/27/fun-with-clojure%C2%A0turning-cats-into-dogs-in-hanoi/

14:20 bobo_: raek: yeh that one is awesome

14:22 jkkramer: hey thanks :) i guess i should probably write the promised follow-up

14:26 raek: jkkramer: I'm looking throught the docstrings of loom and I came across the word "read-only". what does it mean in this case?

14:26 all the graphs are immutable, right?

14:27 does it mean that you cannot create modified copies of them?

14:27 jkkramer: raek: meaning the add/remove fns won't work. it's for when graphs are created on the fly (e.g. from some function)

14:28 raek: i.e., there's no stored data to "modify" -- just functions which generate neighbors and such on-demand

14:28 i should mention that loom's implementation may still change a lot. in particular, i plan on having it use deftype instead of defrecord

14:29 haven't had time to work on it recently

14:29 raek: if I just use the public function, that wouldn't affect me, right?

14:30 jkkramer: right, ideally the API wouldn't change much

14:31 i might rethink fly graphs...maybe just creating something like graph-seq, analogous to tree-seq

14:31 raek: I have only used the lib for about 10 minutes, but I really like what I have seen so far :)

14:31 jkkramer: cool, thanks. let me know if you have any comments/suggestions

14:32 raek: only one small one so far:

14:32 you might want to consider to put the ubigraph integration in a separate artifact/jar

14:33 jkkramer: yeah, that might make sense

14:33 raek: I assume that the core of loom only uses a few deps

14:34 jkkramer: just clojure.core, yup

14:34 raek: and the most of the deps seemed to be used only by the ubigraph parts

14:34 neat

14:34 is there any autodoc up for loom?

14:35 jkkramer: not yet

14:36 raek: btw, it's truly wonderful to be able to just send a graph to GraphViz...

14:37 jkkramer: turned out to be quite easy, compared to integrating a java lib for visualization, or writing my own

14:55 fuchsd: Howdy! What's the best/most idiomatic way to re-bind *command-line-args* in a test with Lazytest?

14:56 I tried this: https://gist.github.com/738277

14:56 and it didn't seem to work.

14:56 However, if I move that bindings form to within the it form,

14:57 the test passes and fails as it should, but the reporting isn't the best (it reports the whole bindings expression instead of just the tests)

14:57 Is there a better way to do this?

14:59 cemerick: Is anyone aware of a way to compile Java apps down to Javascript to be run within the browser?

14:59 chouser, perhaps?

15:00 lpetit: GWT

15:00 ahem

15:01 bobo_: souns alot like GWT yes

15:02 cemerick: yeah

15:02 What I just heard about was something Oracle-sponsored, though.

15:03 I can't find anything about oracle being involved in such a project though…

15:17 bobo_: can someone tell me why i should name a argument for username "s" instead of "user-name"? or "n" instead of "size" if it is the size of something?

15:17 or am i missunderstanding the coding standards?

15:22 ossareh: bobo_: I guess since a username is a string and size is a number. IMHO I prefer the longer variants but have found myself using the shorter ones as I spend more time hacking clojure.

15:24 bobo_: i have tried to like the short once for a long while now. dont get it at all

15:25 ossareh: The regular short ones I use are "n" for number and "x" for some anonymous data, (map (fn [x] (do-something-with-x x)) coll)

15:27 bobo_: and that seems to be the correct way to do it according to the standards, but would be nice to know why it is the standard.

15:34 fuchsd: ('let' or 'given' don't work in this case either)

15:51 cemerick: lpetit, bobo_: http://cemerick.com/2010/12/12/oracle-vp-we-have-a-strategy-to-run-java-inside-a-javascript-environment/

15:59 fliebel: Why the f*ck does the RSS icon on twitter.com give my my favorites?

16:00 oops, that was meant for my twitter feed

16:05 bobo_: cemerick: that sounds realy weird, i dont get why they would develop such a thing

16:05 raek: ok, now I got loom hooked up with ring and moustache. now I can make graphs of clojure data available from the web!

16:07 cemerick: bobo_: Oracle can't keep ceding client-side stuff to everyone else.

16:07 Especially if they're working on something like orto, that would be *huge*

16:08 bobo_: orto?

16:09 cemerick: bobo_: there's a link about it in my post

16:09 bobo_: ah! im blind =)

16:09 ah yes that would be huge

16:12 if people are crazy enough to do a flash runtime in javascript oracle could very well be building a java runtime in it.

17:00 ordnungswidrig: uh, so they want to keep java but not then jvm?

17:00 brehaut: marketting?

17:01 they were talking in terms of desktop applications

17:01 ordnungswidrig: Uh, you mean the desktop machines that will have 12 cores in 4 years by default?

17:02 Sounds like java compiled to javascript would be a perfect fit *g*

17:02 brehaut: my guess is that the JVM is unattractive to users as a platform for desktop apps but web apps are great. java applets are dead. whats next? try to make java run in the one platform everyone has

17:03 i was only imply that it did seem like they were discarding the JVM wholesale

17:03 npoektop: Does lazytest run tests in a separate thread?

17:03 brehaut: only that they implied it wasnt part of desktop plan

17:05 ordnungswidrig: brehaut: you mean, desktop apps in the browser

17:05 ?

17:06 brehaut: ordnungswidrig: im guessing and reading through the lines but yes

17:07 ordnungswidrig: brehaut: how scary, in the browser we already have a nice function language named ecmascript. who, really, will need java, here ?

17:07 brehaut: ordnungswidrig: java developers? GWT developers?

17:09 ordnungswidrig: brehaut: Shouldn't a developer be able to program in multiple languages?

17:10 brehaut: ordnungswidrig: i dont think its any more sane than you do, im just trying to suggest why they might think its a good idea

17:10 ordnungswidrig: brehaut: However, I see that there is no strongly language in the browser

17:10 brehaut: …strongly typed...

17:11 (There is a haskell to js compiler, IIRC)

17:11 brehaut: ordnungswidrig: im very much a polyglot myself, but im also aware of how much of a minority view that is with a lot of developers

17:11 ordnungswidrig: brehaut: then, they should do a vba to js compiler :-)

17:11 brehaut: ordnungswidrig: good god no

17:11 ordnungswidrig: vba needs to be shot

17:12 im still recovering from the trauma of programming vaste quanitities of VBA professionally

17:12 ordnungswidrig: brehaut: by the number of developers then yes!

17:13 * ordnungswidrig had done vba for test automatation once ("%§$%§$%)

17:16 brehaut: ordnungswidrig: my last gig i was working on legacy systems where basicly everything was VBA. most of our servers had several million lines of it in production

17:17 ordnungswidrig: brehaut: fascinating that such systems work

17:17 brehaut: often without a glimpse of qa

17:17 brehaut: ordnungswidrig: aint that the truth :P

17:18 no more of that for me

17:18 ordnungswidrig: brehaut: beside end-to-end testing done by a horde of tester running test scripts by hand an entering results into excel sheets?

17:18 brehaut: word docs rather than excel sheets for us but yeah ;)

17:18 arrummzen: How do I import clojure functions from one namespace to another so I don't have to append the other namespace/ to every function call?

17:19 brehaut: arrummzen: first, aliasing the namespace is a prefered choice

17:19 arrummzen: otherwise 'use'

17:19 arrummzen: What do you mean by aliasing the namespace?

17:19 brehaut: (require '[clojure.xml :as 'xml])

17:19 oh sorry

17:19 (require '[clojure.xml :as xml])

17:20 then you can do (xml/emit nodes)

17:20 frinstance

17:20 arrummzen: this is the recommended approach

17:20 arrummzen: hmm... require seems to only work if I have the functions I need compiled to disk?

17:20 brehaut: arrummzen: it should work for any clj file you have. its the typical way of loading code

17:20 arrummzen: Use has the same problem...

17:21 brehaut: arrummzen: you have a deeper problem i think?

17:22 arrummzen: do you have your project anywhere public?

17:23 arrummzen: or are you dabbling in a repl?

17:23 ordnungswidrig: arrummzen: is the source file with the used function on the classpath?

17:23 arrummzen: Never mind, it seems that it can load a .clj file as well.

17:23 brehaut: yes

17:24 arrummzen: Sorry, I'm new to this REPL stuff. I'm used to the C/Makefile style of working.

17:24 brehaut: arrummzen: no worries

17:26 arrummzen: if you must import a function into your namespace rather than requiring the namespace, it is suggested that you restrict what you import to a specific set of symbols.

17:27 arrummzen: eg (use '[clojure.contrib.zip-filter.xml :only [xml-> xml1-> text])

17:28 arrummzen: are you using a project management / 'build' tool?

17:29 arrummzen: No....

17:30 brehaut: arrummzen: may i suggest you look into github.com/technomancy/leiningen for managing your projects

17:30 arrummzen: I'm using eclipse which manages the Java part of the build. But counterclockwise doesn't seem to support a unified build system.

17:30 brehaut: arrummzen: and its sibling project github.com/liebke/cljr

17:31 arrummzen: sure. I've used lein for the buildy bits of a project with eclipse + ccw

17:33 arrummzen: Sounds good. I've only 2 files at this point but as the project grows I'll have to start thinking about a build system.

17:34 brehaut: arrummzen: importantly lein will maintain the dependancies for you, both fetching them and sticking them on the projects classpath. ahead of time compilation is the exception, not the rule, in clojure, so 'build' ussually just means producing an uberjar with your clj + all dependant jars.

17:37 arrummzen: brehaut: what do you mean by fetch? Does it automatically download updates?

17:37 brehaut: arrummzen: it will download any dependancies you specifiy with the version you specify

17:38 and handle dependancy resolution for those too. It is built on the maven dependancy system

17:38 arrummzen: sounds interesting =)

17:40 gfrlog: isn't there a histogrammy function in clojure that does [1,3,3,4,5,4,6] => {1 1, 3 2, 4 2, 5 1, 6 1} ?

17:41 clojure.core/frequencies

17:44 hiredman: (apply merge-with + (map (fn [x] {x 1}) [1,3,3,4,5,4,6]))

17:44 ,(apply merge-with + (map (fn [x] {x 1}) [1,3,3,4,5,4,6]))

17:44 clojurebot: {6 1, 5 1, 4 2, 3 2, 1 1}

17:45 brehaut: hiredman: cunning :) also he answered his own question with clojure.core/frequencies i think

17:46 gfrlog: yeah

17:46 that's cute though

17:47 hiredman: ~def frequencies

17:47 clojurebot: you suck

17:47 clojurebot: It's greek to me.

18:11 rata_: hi

18:11 brehaut: rata_ [temporally appropriate greeting]

18:12 rata_: :)

18:13 raek_: rata_: good morning (Universal Greeting Time)

18:17 Licenser: night everyone!

18:27 jk__: arrummzen: it's pretty easy to build clojure project with the maven clojure plugin inside eclipse. if you're already using the maven plugin that is

18:59 gfrlog: does incanter have a feature for drawing a basic graph on a log scale?

18:59 (i.e., y-axis is log scale)

19:42 jcromartie: I made a map function that prints progress over large lazy seqs https://gist.github.com/738505

19:43 oops, updated to include the missing dot-points :)

19:59 tomoj: jcromartie: try not to count the seq

19:59 er, coll

19:59 jcromartie: hm, yeah I guess that might spoil things

20:00 then it's kind of hard to do

20:00 oh well

20:00 tomoj: I don't see why you need the progress atom

20:00 can't you just map-indexed?

20:00 jcromartie: well you still need to know where in the collection you are at

20:00 tomoj: oh, of course

20:00 :)

20:01 so it only makes sense anyway for colls you can fit in memory

20:01 jcromartie: it's more for the evaluation of (f x), not the coll of x's

20:01 yeah

20:02 tomoj: doprogress?

20:02 I dunno, I guess using map like that is ok

20:02 as long as people know the thing they get back will behave weirdly

20:03 but if they were going to use map to do it, they'd know that anyway

20:16 jcromartie: yeah

20:16 I have a better idea

20:16 how about with-progress

20:16 which binds *progress* and lets you use fns like (progress "Doing stuff") (progress 0.5) to show meters

20:22 laurus: Does anyone know a way in Clojure to do something similar to http://briancarper.net/blog/527/printing-a-nicely-formatted-plaintext-table-of-data-in-clojure , but with commands that would allow the selection of data based on certain criteria, say, for that example, age < 29 ?

20:23 tomoj: filter the data before passing it to the table function?

20:23 maybe I'm not following you

20:23 laurus: tomoj, how?

20:24 tomoj: (table (filter #(< (:age %) 29) data) [:age :name]) ?

20:24 laurus: Ah, I see.

20:24 tomoj: depends on the data I guess

20:30 Darmani: user> (- 0 -9223372036854775808)

20:30 -9223372036854775808

20:30 *sigh*

20:31 How should I report this?

21:07 hippiehunter: is there a way to un-zip a collection of maps with x elements into x collections?

21:07 gfrlog: example of input and output?

21:08 brehaut: have you tried (apply map col) ?

21:08 sorry

21:09 hippiehunter: [{:item1 "hello" :item2 "again"}] into ["hello"] and ["again"] with some way to name the resulting collections

21:10 brehaut: hippiehunter: you might need to be a bit more explicit

21:11 hippiehunter: do you want say [{:i1 1 :i2 4} {:i1 3 :i2 5}]

21:11 hippiehunter: yes

21:11 brehaut: to become say {:i1 [1 3] :i2 [4 5]}

21:11 hippiehunter: that would certainly do the trick since i could destructure it

21:12 brehaut: i think merge-with would be a good start

21:13 (apply merge-with + col) for example would sum those for you

21:14 so replace + with a fun that conjs acc [i] or returns [item]

21:15 gfrlog: I think he'd still have potential problems with that

21:15 brehaut: id noodle about in a repl to work it out for you, but i just sliced mu finger open

21:15 hippiehunter: im unsure of how to pass the arguments into merge-with with considering they would be in vector form

21:15 gfrlog: for keys present in the first map and none of the ethors

21:15 brehaut: hippiehunter: apply

21:15 gfrlog: hippiehunter: I'll try to scratch something up real quick, one sec

21:15 hippiehunter: the maps are homogeneous

21:16 gfrlog: oh

21:16 they all have the same keys?

21:16 hippiehunter: yes

21:16 gfrlog: much easier

21:16 lessee...

21:18 (into {} (map (comp vector (apply comp coll)) (keys coll)))

21:18 no way that'll work on the first try

21:19 yeah, the (keys coll) at the end should be (keys (first coll))

21:21 I could clean it up even better if I knew of a good way to take a set of keys and a fn and spit out a map

21:21 using (into {} and-some-pairs) is the only way I know how

21:24 hippiehunter: im a little hazy on (apply comp coll)

21:25 coll doesnt contain functions, doest comp try to run things?

21:25 gfrlog: coll contains maps, right?

21:25 hippiehunter: yeah

21:25 gfrlog: maps are functions

21:25 in this case we want to take each key, and run it through each one of those maps/functions and get a vector of the results

21:26 which should be what (apply comp coll) does

21:26 there's a bug in there still that I'm trying to work out

21:27 ah hah

21:27 comp is not what I want :)

21:27 it's...the other thing

21:27 lemme find the cheatsheet...

21:28 juxt I bet

21:29 got it:

21:29 (into {} (map (juxt identity (apply juxt coll)) (keys (first coll))))

21:30 so (apply juxt coll) is a function that takes a key and returns a vector of values

21:30 the (juxt identity ...) part will return a pair, where the first element is the key and the second element is the vector of values

21:30 so map creates a list of pairs, and into shoves them all in a map

21:32 hippiehunter: ,(let [coll [{:i1 1 :i2} {:i1 3 :i2 4}]] (into {} (map (juxt identity (apply juxt coll)) (keys first coll))))

21:32 clojurebot: 3

21:33 gfrlog: your first map looks incomplete

21:33 hippiehunter: ahh thanks

21:33 (let [coll [{:i1 1 :i2 2} {:i1 3 :i2 4}]] (into {} (map (juxt identity (apply juxt coll)) (keys first coll))))

21:33 oops

21:33 gfrlog: I'm surprised that doesn't throw an error

21:33 hippiehunter: ,(let [coll [{:i1 1 :i2 2} {:i1 3 :i2 4}]] (into {} (map (juxt identity (apply juxt coll)) (keys first coll))))

21:33 clojurebot: java.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$keys

21:34 gfrlog: you want (keys (first coll))

21:34 hippiehunter: ,(let [coll [{:i1 1 :i2 2} {:i1 3 :i2 4}]] (into {} (map (juxt identity (apply juxt coll)) (keys (first coll)))))

21:34 clojurebot: {:i1 [1 3], :i2 [2 4]}

21:34 gfrlog: woohoo

21:34 hippiehunter: awsome

22:41 Derander: I wonder if it'd be possible to implement a swank server for ruby

23:03 hippiehunter: when I do a full macro expand, it tends to produce a single line of mega doom that I would like to have nicely formatted. Is there such a feature or must I reflow by hand?

23:04 brehaut: hippiehunter clojure.contrib.pprint might contain what you want?

23:04 hippiehunter: http://richhickey.github.com/clojure-contrib/pprint-api.html

23:12 hippiehunter: thanks that got me in the right direction

23:18 Synt_x: Quiet in here

23:32 technomancy: clojurebot: wake up, sluggard.

23:32 clojurebot: It's greek to me.

23:33 technomancy: clojurebot: well then Ξυπνήστε, οκνηρός

23:33 clojurebot: Huh?

23:33 brehaut: (inc technomancy)

23:33 sexpbot: ⟹ 1

23:33 technomancy: ಠ_ಠ

23:34 Raynes: (inc brehaut)

23:34 sexpbot: ⟹ 2

23:35 brehaut: wow im quickly approaching my HN karma score

23:42 Lajla: ,(+ 1 1)

23:42 clojurebot: Lajla: Excuse me?

23:42 Lajla: I'm still ignored. =(

23:42 ossareh: &(+ 1 1)

23:42 sexpbot: ⟹ 2

23:42 ossareh: speak to bots that listen

23:43 is clojurebot's code in github?

23:44 technomancy: clojurebot: source?

23:44 clojurebot: source is http://github.com/hiredman/clojurebot/tree/master

23:44 ossareh: ^_^

23:45 Lajla: &(set! * +)

23:45 sexpbot: java.lang.IllegalStateException: Can't change/establish root binding of: * with set

23:54 Raynes: ossareh: sexpbot isn't a clojurebot.

23:54 ossareh: Raynes: what is the core difference?

23:55 Raynes: ossareh: They are entirely different bots designed in entirely different ways with totally different goals.

23:55 The core difference is 'everything'. :p

23:55 ossareh: hah.

23:55 Raynes: I've never looked at the clojurebot source code outside of it's sandbox code.

23:56 sexpbot: whatis source

23:56 sexpbot: source does not exist in my database.

23:56 Raynes: sexpbot: whatis sexpbot

23:56 sexpbot: sexpbot = the bestest sexpbot ever

23:56 Raynes: Heh, I nixed my own link.

23:56 $learn sexpbot http://github.com/Raynes/sexpbot

23:56 sexpbot: My memory is more powerful than M-x butterfly. I wont forget it.

23:58 ossareh: Raynes: btw - saw your tweet about your mum burning things. I know how that roles, best thing that ever happened to me because I was forced to cook. Such a great skill to have!

23:59 Raynes: I have a high respect and admiration for proper chefs. If programming wasn't my thing, cooking would be.

23:59 Too bad I suck at cooking.

Logging service provided by n01se.net