#clojure log - Jan 29 2011

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

0:00 semperos: their dev's don't always get them updated in the maven repo's particularly quickly

0:01 mefesto: thanks, makes absolute sense

0:01 mefesto: semperos: np

0:58 semperos: really cool that clojureql prints the query as the "string representation" of the table, without having to bind *debug* like Lau's earlier video shows

1:25 joshua__: &findfn 1 2 3

1:25 sexpbot: java.lang.Exception: Unable to resolve symbol: findfn in this context

1:25 joshua__: findfn 1 2 3

1:25 %findfn 1 2 3

1:25 $findfn 1 2 3

1:25 sexpbot: [clojure.core/bit-or clojure.core/bit-xor clojure.core/+ clojure.core/unchecked-add]

1:26 joshua__: $findfn 4 5 9

1:26 sexpbot: [clojure.core/+ clojure.core/unchecked-add]

1:26 joshua__: $findfn 2 3 8

1:26 sexpbot: []

1:32 brehaut: $findfn #(cons %2 %1) '() [1 2 3] '(3 2 1)

1:32 sexpbot: java.lang.Exception: Unreadable form

1:32 brehaut: lame

1:33 that'll teach me to read the doc first

7:06 dedeibel: is clojuredocs.org down for you too? :-/

7:08 raek: no. the search gives a 500 though.

7:09 dedeibel: Precise.

7:57 fliebel: how does the mail feature of sexpbot work? just $mail name message, right?

7:58 stephanmg: hello.

7:58 fliebel: hi

8:05 m1ll3`: /msg stephanmg yo

8:05 lol irssi

8:07 anybody knows where i can get this SimAnt clojure demo from rich hickey?

8:07 fliebel: $mail clgv I Think the answer is either x=2, y=6 or x=3, y=4. https://gist.github.com/801804

8:07 sexpbot: Message saved.

8:08 fliebel: m1ll3`: No… sounds interesting.

8:09 stephanmg: maybe we should ask kotarak.

8:10 m1ll3`: not on

8:11 incandenza: http://clojure.googlegroups.com/web/ants.clj

8:12 __name__: incandenza: this did not execute with 1.2 last i tried

8:13 m1ll3`: thx. i'll try it

8:13 incandenza: well, that is the original example... it may need some updates by now

8:15 __name__: I am confused that rather many constants are program global. is this recommended?

8:16 jkrueger: assuming that you have two java classes, where one extends the other. if you now extend both of these classes with a protocol, is it possible to call the parent classes implementation of the extended protocol from the derived classes implementation ?

8:16 fliebel: hm, it opens a window with a greeen square for me.

8:16 uhm, blue rather

8:20 m1ll3`: you need to start it from repl

8:21 fliebel: hah! howrks!

8:22 quite a lot of cpu and threads :)

8:22 incandenza: yup, still works for me, too.

8:22 __name__: m1ll3`: why do you need to start it from repl?

8:22 fliebel: __name__: You need to call some things to start it

8:22 see the comment at the bottom.

8:22 incandenza: __name__: to start the program, you need to run the stuff in the 'comment' section at the end

8:23 __name__: oh

8:23 * __name__ facepalms

8:24 fliebel: I'm not exactly sure hwat these ants are trying to do, and why hey do it so randomly ;)

8:26 m1ll3`: great. works

8:26 my system's screwed now lol

8:26 incandenza: here's the talk where he explains it: http://blip.tv/file/812787

8:26 __name__: wouldn't it be a bit better to use $CPU threads for that?

8:26 $ANTS threads sounds like a lot of overhead

8:26 stephanmg: ants seek for food driven by pheromones.

8:34 __name__: this is fun to watch

8:34 fliebel: incandenza: This is clojure 1.0?

8:39 incandenza: fliebel: not sure if it's been updated, but it still works on 1.2. the talk was from april 2008

8:39 fliebel: right

8:46 heh, at least he decided to keep his glasses on his nose now...

10:00 bartj: is there a "between" function to check if a number is between two numbers

10:00 I want to use that instead of:

10:01 (or (>= n lower) (<= n upper))

10:02 tonyl: not that I know of

10:03 __name__: bartj: why or?

10:05 raek: ,(<= 1 5 10)

10:05 clojurebot: true

10:05 raek: ,(<= 1 20 10)

10:05 clojurebot: false

10:06 bartj: ,(doc <=)

10:06 clojurebot: "([x] [x y] [x y & more]); Returns non-nil if nums are in monotonically non-decreasing order, otherwise false."

10:07 bartj: __name__: oops; yeah, and should be used

10:07 raek: all the <=, <, =, et.c., operations can take more than 2 args

10:07 (< a b c d) is the same as (and (< a b) (< b c) (< c d))

10:08 bartj: so you mean to say:

10:08 __name__: bartj: (defn between [min max n] (and (>= n min) (<= n max)))

10:09 raek: (if (<= lower n upper) (... between ...) (... not between ...))

10:14 bartj: cool! thanks!

10:17 raek: you always show me a better way :)

10:29 robonobo: whenever i move a function to another namespace and try to use it at the repl, i get the error that the function is already defined, how do i fox that?

10:29 s/fox/fix

10:29 sexpbot: <robonobo> whenever i move a function to another namespace and try to use it at the repl, i get the error that the function is already defined, how do i fix that?

10:31 raek: robonobo: you (ns-unmap 'dependent.namespace 'the-var) and then you can use the new one

10:31 tonyl: maybe ns-unmap

10:32 raek: you can also call (remove-ns 'dependent.namespace) to start over completely

10:32 but in that case, make sure the repl is in another namespace and that you remove all namespaces that have used that one too

10:34 dedeibel: I am a bit confused - there is "every?" and "not-every?" and "not-any?" but no "any?", I was also missing something like "not-zero?". Any explanation for that, isn't it inconsistent?

10:34 raek: e.g. scenario: (ns a (:use b)). if you ns-remove b, be sure to ns-remove a too

10:34 dedeibel: an "any?" function can be more general. instead of just returning true, it could return the item itself

10:35 dedeibel: this function is 'some'

10:36 ,(some odd? [0 2 4 5 6 8])

10:36 ,(some #(when (odd? %) %) [0 2 4 5 6 8])

10:36 clojurebot: true

10:36 5

10:36 raek: so, 'some' is just like "any?", but even more powerful

10:37 but yeah, for the sake of symmetry, one could say that not having 'any?' is a bit inconsistent

10:38 re. complements of predicates: in these cases, it's common to use 'not' or the compound 'if-not' and 'when-not'

10:39 tonyl: or complement

11:24 robonobo: is there a to-the-power-of symbol in clojure?

11:24 like ** in python

11:24 2**3 = 8

11:30 dedeibel: raek: okay, thanks for the insight

11:32 :D

11:44 tonyl: ronobo: I am not sure, but there is Math/pow

11:46 robonobo: tonyl: i know, but i don't like using long function names when doing math. Anyway, i just made a ** function that calls math/pow

11:47 tonyl: there is also clojure.contrib.generic.math-functions/pow

11:47 that is longer

11:47 but

11:47 y

11:47 you can require or use it

11:48 or clojure.contrib.math/expt

12:47 neilcj: is there a function that takes a library and returns a list of its public variables?

12:49 Raynes: &(keys (ns-interns 'clojure.core))

12:49 sexpbot: java.lang.SecurityException: You tripped the alarm! ns-interns is bad!

12:49 Raynes: Of course it is.

12:49 neilcj: ^

12:50 ns-interns returns a map of symbols to vars from whatever namespace you pass it. Calling keys on it just gets you a list of symbols in that namespace.

12:50 As for publics...

12:51 raek: ns-publics?

12:51 Raynes: &(doc ns-publics)

12:51 sexpbot: java.lang.SecurityException: You tripped the alarm! ns-publics is bad!

12:51 Raynes: 'course.

12:51 raek: "Returns a map of the public intern mappings for the namespace."

12:51 Raynes: Yeah, that's what I was looking for. :D

12:52 neilcj: that works, thanks guys

12:52 raek: the lib has to be loaded first

12:58 jaley: Hi guys! I want clojure.contrib.logging calls to write to a file in /var/log - where should I be looking? I think it's picked up commons-logging from my classpath for a dependent library i'm using. is this configurable in commons-logging.properties or something? I've been googling away about apache commons logging and I just get overwhelmed with complex stuff that I don't need :/

13:07 SergeyD: What do you think of adding ":binding" into the "for" construct? Is it a bad idea because "for" is lazy and it can lead to problems when crossing thread boundaries?

13:07 BTW, what is the right place to propose language changes?

13:08 Like the above )

13:11 chouser: SergeyD: The google group is the place to say such things

13:12 I don't think I've ever wanted to do a binding inside a 'for'

13:13 SergeyD: you have a use case for :binding between two iteration expressions in the same 'for'?

13:17 SergeyD: chouser, may be I'm overusing bindings now and not using "for" the right way.

13:17 chouser, I have this: (dorun (for [i (range 4) j (range 3)] (binding [*offset-x* (* i *width) *offset-y (* j *height*)] (make-stuff!))))

13:19 chouser, I will look for the best practices of using bindings.

13:20 _pyr_: hi

13:43 chouser: SergeyD: I'd recommend using binding less frequently. Is there a reason you couldn't pass offset-x and offset-y as args to make-stuff!

13:43 ?

13:43 pyr: hi

13:47 SergeyD: chouser, I'm exploring using bindings for cross-a-lot-of-functions parameters to make my code more concise.

13:52 LauJensen: Morning

13:52 SergeyD: Evening :)

13:54 Scriptor: Afternoon!

14:06 bartj: doesn't re-gsub replaces globally ?

14:06 for eg: to replace industries and ltd from company names, I use the following:

14:06 , (re-gsub #"^(industries|ltd)[\s]+|[\s]+(industries|ltd)[\s]+|[\s]+(industries|ltd)$" " " "apar industries ltd")

14:06 clojurebot: java.lang.Exception: Unable to resolve symbol: re-gsub in this context

14:07 LauJensen: SergeyD: Scriptor Look up UGT

14:07 bartj: but, I get "apar ltd"

14:08 what am I doing wrong ?

14:10 ie. why isn't the last ltd removed ?

14:10 SergeyD: LauJensen, I see :)

14:16 bartj: it seems to me that re-gsub is not doing a "global" substitute

14:17 LauJensen: bartj: Go check in #perl :)

15:23 robonobo: is there some kind of combination of some and map that returns the first element for which the given function returned true and false when none of them did?

15:25 wait, i can use filter and first

15:27 pauldoo: where am I going wrong with this: (let [r (ref 10)] (set! r (inc @r)) @r)

15:27 trying to simply modify a ref..

15:28 mefesto: missing dosync?

15:29 pauldoo: mefesto: adding dosync doesn't help..

15:29 mefesto: pauldoo: and for refs i think you need ref-set

15:30 http://clojure.org/refs

15:30 pauldoo: mefesto: brilliant - ref-set + dosync fixed it

15:30 hm.. this is interesting, because I'm only using this var/ref on a single thread

15:31 mefesto: ,(let [r (ref 10)] (dosync (alter r inc)))

15:31 clojurebot: 11

16:14 mjg123: Hi - I'm having trouble with compojure routes: deploying as a .war to tomcat with context-root of "tb", I know how to create a route which would match (eg) http://localhost:8080/tb/myresource

16:14 (GET "myresource ...) or (GET "tb/myresource ...) - neither works.

16:15 ahh - s/I know/I don't know/

16:15 LauJensen: mjg123: try moustache, everything nests, ie (app ["tb"] (app ["x"] ... ["y" .. etc))) so that all of your routes are moved up behind /tb/*

16:17 * mjg123 reading up on moustache

16:18 mjg123: nice. The answer to my original question seems to be (GET "/tb/myresource" ...)

16:21 LauJensen: wow you got that from reading up on moustache? Man christophes makes solid docs

16:21 mjg123: was multitasking

16:43 jaley: hi everyone. since updating leiningen 1.3.1 to 1.4.2, i get the help printed followed by a FileNotFoundException no matter what command i'm trying to run. anyone else seen this?

16:45 technomancy: jaley: how did you upgrade? just "lein upgrade"?

16:46 jaley: technomancy: no.. actually i didn't know that existed so i copied the latest version of the script

16:46 technomancy: can you paste the stack trace? I've never heard of that happening

16:47 jaley: technomancy: ok, i just ran lein upgrade and it's fixed

16:47 Exception in thread "main" java.io.FileNotFoundException: (No such file or directory)

16:47 at java.io.FileInputStream.open(Native Method)

16:47 at java.io.FileInputStream.<init>(FileInputStream.java:106)

16:47 at java.io.FileInputStream.<init>(FileInputStream.java:66)

16:47 at clojure.lang.Compiler.loadFile(Compiler.java:5817)

16:47 at clojure.main$load_script.invoke(main.clj:221)

16:48 at clojure.main$script_opt.invoke(main.clj:273)

16:48 at clojure.main$main.doInvoke(main.clj:354)

16:48 clojurebot: clojure bot is not immune to ,(iterate inc 0)

16:48 jaley: at clojure.lang.RestFn.invoke(RestFn.java:437)

16:48 at clojure.lang.Var.invoke(Var.java:373)

16:48 technomancy: I didn't mean literally paste =(

16:48 jaley: at clojure.lang.AFn.applyToHelper(AFn.java:169)

16:48 at clojure.lang.Var.applyTo(Var.java:482)

16:48 at clojure.main.main(main.java:37)


16:48 that was the trace, before it fixed

16:48 technomancy: oh. sorry. clojurebot is upset

16:49 technomancy: is this cygwin or something?

16:49 jaley: linux. ubuntu server 10.04 (i think)

16:51 technomancy: it's working fine now. will remember there's an upgrade feature next time :)

16:52 technomancy: oh, what was the fix?

16:52 jaley: technomancy: i just ran the upgrade as su, that seemed to work

16:54 LauJensen: hehe

16:54 technomancy: couple weeks and we'll have .deb packages

16:55 jaley: technomancy: for leiningen?

16:56 technomancy: yeah

16:57 jaley: nice. are you sticking it in a launchpad repo thing?

16:57 technomancy: probably

19:24 cc_: hello, quite new to clojure here. I was wondering if someone can clear up a with-open problem for me

19:24 (with-open [rdr (reader "project.clj")] (count (line-seq rdr)))

19:24 that one works fine, however for some reason if i try to take 2 instead the stream closes

19:25 (with-open [rdr (reader "project.clj")] (take 2 (line-seq rdr)))

19:25 this gives: java.io.IOException: Stream closed

19:25 any idea why?

19:26 tomoj: &(do (take 2 (repeatedly #(println "foo"))) nil)

19:26 sexpbot: ⟹ nil

19:26 tomoj: &(take 2 (repeatedly #(println "foo")))

19:26 sexpbot: ⟹ (foofoonil nil)

19:27 tomoj: line-seq and take are lazy

19:28 count forces the file i/o to happen inside the with-open by iterating through the whole line seq

19:28 with (take 2 (line-seq rdr)), no file i/o happens until the seq is forced, when the repl tries to print the return value

19:28 but by then with-open has returned and the reader is closed

19:28 cc_: ah, so i need to force evaluation with doseq?

19:29 tomoj: doseq would be good if you are iterating through the lines and doing something for each

19:29 in your example above, (doall (take 2 (line-seq rdr))) should work, I think

19:31 cc_: that worked. Thanks alot for clearing that up :)

21:08 yayitswei: does anyone have experience using clojure and selenium together?

23:24 andyfingerhut: I'd like to do (int x) where x is a primitive long, and truncate the value to the least significant 32 bits if the value is outside the range of an int. And I want it to be as fast as Java could do it, or within 2x the speed Java could. Any thoughts?

Logging service provided by n01se.net