#clojure log - Oct 02 2014

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

1:05 zhaow: can any one help to explain why this does not work?

1:05 (reduce #((if (even? %2) (* %1 2) (inc %1))) 1 (range 0 3))

1:06 but this works: (reduce (fn [number, index] (if (even? index) (* number 2) (inc number))) 1 (range 0 3))

1:08 joshuafcole_: parens

1:08 mdeboard: zhaow: You have extra parens

1:08 joshuafcole_: look off there

1:08 dbasch: &(reduce #(if (even? %2) (* %1 2) (inc %1)) 1 (range 0 3))

1:08 lazybot: ⇒ 6

1:09 zhaow: I see

1:09 Thank you all :)

1:09 joshuafcole_: glad to help

1:09 go team

1:09 mdeboard: lol

1:10 To answer your question, yes, someone can help to explain why it doesn't work

1:10 joshuafcole_: (inc mdeboard)

1:10 lazybot: ⇒ 8

1:10 zhaow: (thumbsup) :D

2:22 m00nlight: How can I run an exernal C program within clojure program? It seems the clojure.java.shell will cause an IOException error=2, No such file or directory

2:23 anyone can help?

2:27 dbasch: m00nlight: are you giving it an absolute path?

2:27 m00nlight: Yes

2:28 iamcyberbird: anyone worked all the way through SICP?

2:28 m00nlight: I find the reason, (shell/sh "ls -aux") will cause the errro, and (shell/sh "ls" "-aux") is fine, so I must seperate the program and the argument ?

2:29 luxbock: m00nlight: yes

2:30 m00nlight: dbasch: luxbock: Thanks solved

2:30 luxbock: m00nlight: if you need to lot of shell-calls you could check out https://github.com/Raynes/conch

2:53 wei: possibly a noob question, but what’s the difference between >!! and put!

3:02 dbasch: wei: >!! is blocking put

3:02 wei: so why does >! need to be in a go block but put! doesn't

3:03 if they’re both async

3:08 dbasch: http://stackoverflow.com/questions/19538919/a-possible-solution-to-avoid-limitation-in-go-macro-must-be-called-inside-a-go

4:02 borkdude: so, how do you guys feel about racket as a sysadmin scripting language?

4:08 clgv: borkdude: probably depends on how well it interfaces with the tools available from os

4:37 m1dnight: I have created a class "counter" in my leiningen project. The class has package "demo". The path is /src/projectname/demo

4:37 (the core.clj file of the lein project is thus located at /src/projectname/

4:38 If I want to import the java class in my core.clj I should thus write (:require [demo counter]), right?

4:38 I can't seem to import it, nor in the core.clj or in the repl

4:38 am I doing something wrong? I have compiled the .class file in the .demo folder as well

4:39 I keep getting ClassNotFound error

4:40 (btw, i'm talking about a java clas)

4:41 borkdude: m1dnight I think you need to configure java compilation in the leiningen project

4:42 :java-source-paths

4:42 m1dnight: oh

4:44 daniel___: borkdude: still here?

4:44 u work too hard

4:45 m1dnight: borkdude: Great :) That worked like a charm!

4:45 (inc borkdude)

4:45 lazybot: ⇒ 4

4:45 m1dnight: \o/

4:50 clgv: seesaw question: can I do a (select widget [:.some-class]) such that only direct children are selected?

4:52 since that is based on "enlive" . is that possible in enlive's selection mechanism?

4:54 borkdude: daniel___ what do you mean? :)

4:55 mercwithamouth: did the compojure-app template change as of recent?

4:55 i could have sworn it used to create routes/models/views folders?

5:06 daniel___: borkdude: u helped me with some multimethods before i went to bed

5:06 over 12 hours ago

5:06 borkdude: daniel___ I also went to bed after that I think

5:06 daniel___: ah ok :)

5:07 uk?

5:07 borkdude: Netherlands

5:07 daniel___: u have a job that lets you write clojure?

5:07 joelkuiper: Say I have a function (fn [a b] ...) is it possible to get the arguments bindings as a map within that function? Such that {:a a :b b} ?

5:08 without doing it manually that is?

5:08 borkdude: joelkuiper {:keys [a b]} ?

5:08 joelkuiper ah wait, you want to create a map

5:09 daniel___ yes

5:09 joelkuiper: borkdude: yes, I'm getting some arguments, but I need to pass them along as a key-worded map.

5:09 daniel___: borkdude: interesting, good to hear

5:10 joelkuiper: borkdude: the equivalent of (fn x [a b] (y {:a a :b b})) but then automatically :p

5:10 borkdude: joelkuiper I dont think there is something baked in for that, you could however write a macro for it

5:10 joelkuiper if you have only two keys I wouldn't bother though

5:11 daniel___ not full time though, it depends

5:12 joelkuiper: borkdude: it was the example ;-) I'm using a library which api changed from (x a b c ...) to (x {:a a :b b :c c ...}), and I was hoping to avoid manual labour ;-)

5:13 borkdude: (defmacro to-map [& symbols] .... you'll figure it out)

5:13 joelkuiper: borkdude: yep ... I'll get to it ;-) thanks!

5:33 lvh: I'm writing a fake clock to test core.async/timeout. Someone must've written this before...

5:35 m1dnight: Do i have to add something specific in my core.clj when I import a class that has a lot of imports? I have copy pasted the code of LinkedBlockingQueue in my own file and compiled it by hand and that works but clj can't find it

5:36 however, it can find the class I tried before..

5:37 lvh: m1dnight: uh? you should just be able to import it directly

5:37 m1dnight: (:import (java.java.util.concurrent LinkedBlockingQueue))

5:38 m1dnight: lvh: Yeah, But i want to change it a bit to suit my own needs. So I wanted to start with the vanilla version first to make sure it worked

5:38 First i've tested a simple class counter.java, and I can import and use that one

5:38 lvh: m1dnight: Okay, then I don't understand your question.

5:39 m1dnight: So i added the source of LinkedBlockingQueue to that exact folder, so I could import that one

5:39 but I can import counter, but not LinkedBlockingQueue

5:40 I can compile both manually, which works fine. So in my clojure part I import the counter which works. But importing LinkedBlockingQueue class (my own) does not work

5:40 And I'm guessing it has something to do with the fact that it inherits and implements?

5:40 Not sure..

5:40 lvh: m1dnight: Could you pastebin the error message? "Doesn't work" isn't very specific.

5:40 m1dnight: sure, hold on

5:40 lvh: m1dnight: That shouldn't affect anything.

5:42 m1dnight: oh, I see now. For completeness' sake I wanted to add the tree of my directories and I notice that there is no LinkedBlockingQueue.class in my target folder

5:45 Oh dear

5:45 it seems to work fine when I put some testcode in my core.clj, and "lein run", but in emacs it can't find it

5:46 let me find the error in emacs

5:46 aaaand restarting emacs worked

5:46 Perhaps emacs didn't notice the new compiled files in the target directory or something?

5:50 schmir: m1dnight: lein repl (or clojure-jack-in) will compile the java files when it starts..

5:53 m1dnight: aah, that figures :) then the file was not compiled yet

5:53 Sorry, i'm all new to the entire ecosystem :)

5:53 thanks for the input guys

5:56 lvh: m1dnight: M-x cider-restart

5:57 m1dnight: (assuming you already have a cider)

5:57 m1dnight: you have to do that every time there's some stuff you're not compiling manually and throwing into the repl

5:57 m1dnight: e.g. deps or java code

6:00 m1dnight: aha :)

6:00 * m1dnight puts it on his cheatsheet

6:01 m1dnight: thanks a lot! :)

6:26 ucb: is there any way I can redef (ala with-redefs) Java static methods?

6:26 e.g. Thread/sleep

6:34 lvh: ucb: I'm assuming you've tried the obvious and it doesn't work?

6:34 ucb: yeah

6:35 wait, the obvious being (with-redefs [Thread/sleep identity] (Thread/sleep 10)) right?

6:35 lvh: yeah

6:36 ucb: yeah, that doesn't work because with-redefs is for vars

6:36 lvh: ucb: I guess maybe you could store it in a var? although that's tricky because e.g. Arrays/copyOfRange won't work because there's a ton of different signatures for it

6:36 ucb: the problem is that a third party lib I'm using calls Thread/sleep

6:37 and I want to avoid that in my tests ^_^

6:37 lvh: ucb: ah, right

6:38 mercwithamouth: so i'm using cider and the repl that comes with it. i se in ciders documentation they discuss including the cider-nrepl plugin. is that not already active?

6:38 lvh: ucb: I'd say https://github.com/technomancy/robert-hooke, but I don't know if that does anything for java methods

6:38 mercwithamouth: is there added functionality?

6:40 ucb: lvh: thanks, but that doesn't deal with java static methods

6:41 I'm not sure there's a clear way or even if it's doable unfortunately :(

6:41 lvh: ucb: Yeah :(

6:41 ucb: Sorry :/ maybe try the ml?

6:41 ucb: no worries :)

6:41 yeah will do

7:04 gfredericks: ucb: release a clojure library called thread-slash-sleep and make a pull request

7:05 ucb: heh

7:17 clgv: lvh: ucb: robert-hooke works explicitely on clojure variables

7:18 ucb: yuppe, saw that :)

7:18 clgv: ucb: you'd need something like Java AOP

7:18 ucb: AspectJ I mean

7:20 usb: that stuff is essentially either rewriting bytecode or intercepting the compiler to add/modify bytecode

7:20 ucb: I feared as much

7:21 clgv: ucb: you can not mock out the third party lib?

7:22 ucb: not really. It's not really a lib either, it's more of an app which I'm using as a lib (bits of it). This is a long running thread that sleeps and does a thing in a loop. So I'm trying to get rid of that sleep in my tests.

7:22 (if that makes any sense)

7:22 clgv: ucb: open source license?

7:22 ucb: yuppe

7:22 clgv: fork+fix ;)

7:23 gfredericks: this kind of makes me want to create a lib called foo-slash-bar that jush has a huge collection of dynamic vars that call static jdk methods

7:23 ucb: but no worries, I'm initting that timeout to something bearable like 1s for the time being.

7:23 gfredericks: at some point there was a static-fn thing going on?

7:23 clgv: gfredericks: awesome would be a lib based on ASM to modify and redefine classes ;)

7:23 ucb: (it did exactly that)

7:24 gfredericks: #'foo-slash-bar.java.lang.Thread/sleep

7:24 clgv: ucb: why not 1ms?

7:24 ucb: clgv: I think the lib takes the timeout in seconds

7:24 let me check

7:25 clgv: damn ;)

7:25 does it fail on 0?

7:25 ucb: yuppe, it's in seconds

7:25 I've not tried 0

7:25 I guess that it'd be fine for a test (even if it hammers the cpu while it runs)

7:25 clgv: seems to work overhere ;)

7:26 ucb: ah, coole!

7:26 clgv: it's active polling without signals?

7:26 D'oh!

7:28 augustl: ucb: if you can control the code, rewriting code so you can pass in an executor or something would be much more pleasant

7:28 i.e. make the Thread/sleep pluggable

7:28 ucb: augustl: yes, indeed, but I don't control the code sadly

7:28 and in any case, I'm abusing this thing

7:28 so I guess I'm just asking for trouble

Logging service provided by n01se.net