#clojure log - Aug 12 2012

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

0:08 howard_: Good morning/afternoon/evening. Does anyone know if there is any known issue using (read-line) with clojure-contrib/server-socket?

0:09 I noticed that in my program, read-line will run into what appears to be infinite loop when a client disconnects

0:23 llasram: howard_: Probably not the best time to ask for help -- midnight US EDT and 9pm US PST on a Saturday :-)

0:27 gfredericks: it's still worth a try though

0:27 * gfredericks goes to bed

1:28 brainproxy: anyone tried making a rootbeer-clojure float?

1:28 https://github.com/pcpratts/rootbeer1

3:58 Bahman: Hi all!

3:59 Anybody using borneo library for Neo4j here?

4:00 Is it possible to set attributes for relationships using that library?

4:00 https://github.com/wagjo/borneo

4:13 Found it. http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/set-prop!

4:29 wuehli: und ich kann es auch verstehen, dass Excel so populär ist

4:29 ouch, sorry

5:33 ro_st: anyone using midje have a solution for test coverage?

5:35 * talios posts a quick and nasty video showing Frege (Haskell on the JVM) running under OSGi - http://www.youtube.com/watch?v=RDsuPdMptCU - nice, I think this could be wicked awesome.

6:52 * McMartin grumbles at 4clojure

6:52 McMartin: Does it deliberately choke on certain constructs?

6:53 Raynes: Anything in particular?

6:53 McMartin: I keep getting timeouts on the only problem I have left to solve, and my local copy of the solution solves all the problems combined in under a second.

6:53 Which is Latin Square Slicing

6:54 I rewrote a sequence that used nth to instead use take/drop and that at least cause *some* test cases to resolve

6:54 Raynes: *shrug*

6:54 Some things just take longer in the sandbox.

6:54 It sucks, but it's hard to fix it.

6:54 It certainly isn't deliberant.

6:55 deliberate*

6:55 McMartin: Also, for some problems (this one included) there's this 15 second delay before anything happens

6:55 This doesn't happen with all problems

6:55 Is this a known thing one can trip over?

6:55 Raynes: The time outs? Yes.

6:55 McMartin: No, this isn't strictly a timeout

6:55 It's a big delay at the start, possibly compilation delay?

6:55 But some problems seem to get hit by it way harder than others

6:56 talios: woohoo - there's a new La Clojure build that supports IntelliJ IDEA 12 available. rockin.

7:27 howard: If you are looking for a Clojure implementation of document database engine, please check out https://github.com/HouzuoGuo/ClojureDB

7:31 * McMartin grumbles

7:31 McMartin: The other possibility is that there is a completely unreasonable timeout on this problem.

7:34 hyPiRion: McMartin: It's Clojail, and I don't like it either ;(

7:35 McMartin: Right, but what I mean is, it goes green-green-green-green-green-green-green-green-green-red-with-timeout

7:35 When it works at all, anyway

7:35 My localside testing shows a 25x slowdown on that test case.

7:35 All the way down to a quarter of a second

7:36 So if the timeout is set to like 100ms, that would also explain this

7:36 hyPiRion: Ah.

7:37 McMartin: Whoa hey

7:37 * McMartin reorders his iteration, gets it down to 40ms.

7:37 McMartin: Maybe that will work better

7:37 hyPiRion: heh

7:38 I suspect you already know that for-comprehensions is a no-no. Go loop whenever you can.

7:38 McMartin: I've been getting the reverse the results from the clojail, as it happens.

7:39 loop-recur is my natural state, having wandered to Clojure from Scheme and its named lets.

7:39 hyPiRion: It's a shame though - for comprehensions solve a lot of the problems very elegantly.

7:39 McMartin: SUCCESS.

7:39 Well, that's the thing; for works in places where recur has murdered me

7:40 At any rate, I am now in fact #1.

7:40 hyPiRion: Congratulations.

7:41 McMartin: ALso, at some point it became 0440, I should probably try sleeping

7:41 Sleeping the sleep of VICTORY

7:41 Anyway, thanks to those who reminded me that there are things I should mess with.

7:41 hyPiRion: hahah

7:42 McMartin: And now to translate my real projects into proper Java because I'm going to target Froyo phones =(

7:45 Anyway, check out this horrible meta-for I had to make:

7:45 (defn nest-ranges [xs] (if (empty? xs) '(()) (let [sub (nest-ranges (rest xs))] (mapcat (fn [n] (map #(conj % n) sub)) (range (first xs))))))

7:46 hyPiRion: wow, mapcat

7:46 long time, no see.

7:46 McMartin: Not only that, actual lists

7:46 hyPiRion: heg

7:46 McMartin: You give it a vector of bounds and it gives you a sequence of vectors iterating up to those bounds as if you'd declared them as for variables in that order

7:47 hyPiRion: 4clojure - for your obfuscating needs.

7:47 McMartin: Sorta

7:48 It's pretty straightforward if you tab it into proper whitespacing

7:48 It's just a problem you almost never need to solve, because the *number of loop variables* is usually constant

7:49 It turns out my algorithm for that 4clojure problem, however, was a case where they weren't.

7:49 hyPiRion: yeah

7:49 McMartin: (There's a loop of possible alignments of rows, where the number of variables is the current size of latin square we're searching for)

7:51 OTOH, I think solving http://www.4clojure.com/problem/113 actually made me a worse programmer.

7:56 hyPiRion: McMartin: Well, it's just a reify, isn't it?

7:57 but yeah, it's not exactly pretty.

7:59 McMartin: Yes, now I know how to use reify to do that

7:59 As a result, I am now a worse programmer

7:59 It's like mastering PHP~

8:07 hyPiRion: McMartin: haha

8:07 You should look up reify and how to extend types and so forth - it's not that hard.

8:12 McMartin: Yeah

8:12 I've played with proxy in Swing some

9:25 magopian: hello there: i'm working on problem 121 on 4clojure.org, and wondering if there's any way to evaluate something like '(+ 1 2) without using eval?

9:26 gfredericks: well it's a list

9:26 so you can check if the first thing is '+

9:26 and then add the other things if it is

9:27 the trickiest part is probably getting the recursion right for the arbitrarily nested cases

9:29 magopian: gfredericks: mmmm i think i get it

9:29 then i'll need to see how i can use '{a 1 b 1} in the ":or" part of a map binding-form

9:30 it's strange that i can't just "apply (first l) (rest l)" on '(+ 1 1)

9:30 well, at least, it's strange to me ;)

9:31 gfredericks: cuz it's a symbol; to get a symbol into a var or function you have to use resolve or eval, both of which are probably prohibited there because it would sidestep what they're getting at

9:31 magopian: sure

9:31 so + is a symbol, not a function?

9:32 or is it a symbol only because it's inside a list?

9:33 gfredericks: there's three things going on

9:33 ,(type '+)

9:33 clojurebot: clojure.lang.Symbol

9:33 gfredericks: + unevaluated is a symbol

9:33 which is just data

9:33 ,(resolve '+)

9:33 clojurebot: #'clojure.core/+

9:34 gfredericks: when you resolve it _in the context of your namespace_, you get back a var

9:34 so + in another namespace might refer to a different var

9:34 magopian: and in the var, there's the function

9:34 gfredericks: ,(deref (resolve '+))

9:34 clojurebot: #<core$_PLUS_ clojure.core$_PLUS_@5506ff2e>

9:34 gfredericks: yep, you deref the var and there's the actual function you want

9:35 magopian: i'm going to re-read that several times ;)

9:35 so i could use resolve and deref instead of eval ?

9:35 gfredericks: when you use vars in normal code, the resolving is done at compile-time, and the derefing is done at runtime

9:35 if 4clojure didn't forbid it you could

9:35 magopian: oh ok got it ;)

9:35 anyway, it's not the point of the exercise (to use eval or resolve+deref), but i think i understand now ;)

9:36 gfredericks: that's cool it took me a year or so :D

9:36 magopian: awesome, thanks a ton gfredericks that was _really_ clear and understandable ;)

9:36 gfredericks: no problem

9:36 magopian: (i love 4clojure ;) it really got me to like functional programming ;)

9:37 gfredericks: (inc 4clojure)

9:37 lazybot: ⇒ 1

9:37 magopian: i still have to discover what is clojure especially good at, compared to other functional programming languages, like common lisp

9:37 cshell: magopian: data tranformation and manipulation

9:38 * gfredericks goes off to do something else

9:38 magopian: thanks again gfredericks ;)

9:38 Scriptor: magopian: also, common lisp isn't as functional as clojure

9:38 magopian: cshell: you mean, thanks to its data structures?

9:38 Scriptor: you mean, "not as pure" ?

9:38 i'm still just discovering functional programming, so bear with me ;)

9:39 Scriptor: magopian: not really purity, just in general clojure embraces a functional style and immutability more

9:39 Nikelandjelo: ,((resolve '+) 1 1)

9:39 clojurebot: 2

9:39 Scriptor: also, 4clojure is a double-edged sword

9:39 hyPiRion: huh, resolve.

9:39 Nikelandjelo: ,((deref (resolve '+)) 1 1)

9:39 clojurebot: 2

9:39 Scriptor: I thought my reverse interleave was clever until I saw the usual solution

9:39 Nikelandjelo: When I do (resolve '+) I get a var, not function, right?

9:40 hyPiRion: ,(resolve 1)

9:40 clojurebot: #<ClassCastException java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.Symbol>

9:40 xeqi: Nikelandjelo: invoke on a var is defined to deref automatically

9:40 magopian: Scriptor: can you explain why it's a double-edgd sword?

9:40 Nikelandjelo: xeqi: thanks

9:41 Scriptor: magopian: look above, it was mostly tongue-in-cheek :)

9:41 magopian: Scriptor: ok, got it ;)

9:41 Scriptor: only in that when you think you do have a good solution there always seems to be a better one

9:41 magopian: yeah, i feel that with nearly each problem i solve ;)

9:41 hyPiRion: ,(let [evl (fn [x] ({'* *, '+ +, '- -, '/ /} x x)] (map evl '(+ - * / + 1 2 3)))

9:41 clojurebot: #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: Unmatched delimiter: ]>

9:41 hyPiRion: eww

9:41 ,(let [evl (fn [x] ({'* *, '+ +, '- -, '/ /} x x))] (map evl '(+ - * / + 1 2 3)))

9:41 clojurebot: (#<core$_PLUS_ clojure.core$_PLUS_@5506ff2e> #<core$_ clojure.core$_@182cce06> #<core$_STAR_ clojure.core$_STAR_@50d5f71> #<core$_SLASH_ clojure.core$_SLASH_@225693fe> #<core$_PLUS_ clojure.core$_PLUS_@5506ff2e> ...)

9:42 wmealing__: hyPiRion, my headd..

9:43 hyPiRion: wmealing__: sorry.

9:45 magopian: hyPiRion: it's missing a ") '(" between the operators and the args ;)

9:45 hyPiRion: I realized.

9:47 tomoj: what might a (non-clojure)-code generation framework look like?

9:47 hyPiRion: code generation?

9:47 tomoj: I note the cljs compiler is in imperative style

9:48 hyPiRion: Oh, parsec maybe?

9:49 tomoj: (code ["function (x) {"] (indent ["return x;"]) ["}"])

9:49 trying to work that out now but I don't think it's right

10:56 Frozenlock: Perhaps I'm late to the party and you've already discussed it, but could this work with clojure? http://news.ycombinator.com/item?id=4371851

11:06 hyPiRion: Frozenlock: theoretically, yes

11:07 However, it doesn't cover the following:

11:07 1. native methods 2. reflection 3. dynamic method invocation

11:08 Which is basically what Clojure is :p

11:20 eru`: How would I accomplish something like (let [x (some-ajax-call) y (another-ajax-call)] (f @x @y)) in ClojureScript?

11:20 Frozenlock: hyPiRion: So I should not get excited about this :(

11:28 ticking: is anybody using emacs on a mac, with [] maped to alt-number commands? I don't know how to switch from meta to als…

11:40 hyPiRion: Frozenlock: At least not yet.

11:43 unlink: Is there something like Maybe in Clojure? (Boxing values)

11:50 danielglauser: Does anyone know what the ampersand means in this line of code?

11:50 (catch Object _

11:50 (log/error (:throwable &throw-context) "unexpected error")

11:50 What is &throw-context ?

11:54 _ato: danielglauser: https://github.com/scgilardi/slingshot/blob/master/README.md (about halfway down the page)

11:55 danielglauser: _ato: You know, I have that page open and read a good chunk of it…Thanks!

11:55 alexyakushev: Is there some kind of `constantly` macro that creates a function of any arguments and evaluates its body every time when called?

11:57 gfredericks: alexyakushev: that wouldn't save much over just (fn [& _] my-body) would it?

11:57 _ato: danielglauser: also ampersand by itself doesn't mean anything, it's just part of a symbol name like the question mark in "any?". But by convention it's used for hidden macro arguments with special context information, see also: http://blog.jayfields.com/2011/02/clojure-and.html

11:59 hyPiRion: alexyakushev: constantly?

11:59 ,(doc constantly)

11:59 clojurebot: "([x]); Returns a function that takes any number of arguments and returns x."

11:59 hyPiRion: oh, I see.

12:00 ,(doc repeatedly)

12:00 clojurebot: "([f] [n f]); Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied) lazy sequence of calls to it"

12:00 clj_newb: is there a function to parse a Character to a number other than (Character/digit) ?

12:01 cjfrisz: How do you read something from a file as though it's a sequence/S-expression?

12:01 A la Scheme's read? (http://scheme.com/tspl4/io.html#./io:s81)

12:02 alexyakushev: hyPiRion: constantly returns the same value every time, but I want it to be revaluated

12:02 ,(map (constantly (rand)) (range 5))

12:02 clojurebot: (0.9167970343709244 0.9167970343709244 0.9167970343709244 0.9167970343709244 0.9167970343709244)

12:03 hyPiRion: ,(repeatedly 5 rand)

12:03 clojurebot: (0.9477552907069643 0.4584298110320799 0.15597111467683888 0.6704665582926552 0.9412675879153743)

12:03 alexyakushev: hyPiRion: yep, I know about repeatedly, but that's not what I want, that was just a demonstration

12:04 hyPiRion: Hm.

12:05 You could always wrap it in a (fn [&] ...), to get the same result

12:05 alexyakushev: I can, I just thought maybe there is already a macro for that

12:05 hyPiRion: actually what I exactly need is (defmacro const [& body] `(fn [& _#] ~@body))

12:06 hyPiRion: okey, I don't think there is one.

12:06 alexyakushev: hyPiRion: Thanks anyway!

12:06 hyPiRion: constantly, repeatedly, partial are the closest I know of

12:06 no problem

12:07 VickyIyer: Hello All, I am trying out a small example but for some reason when I run it I am getting an arity exception, can some one tell me what the problem is: (defn hypt[x y]

12:07 (let [x2 (double-me x)

12:07 y2 (double-me y)]

12:07 (Math/sqrt (+ x2 y2))))

12:08 (hypt [23 45])

12:08 ArityException Wrong number of args (1) passed to: double-me$hypt clojure.lang.AFn.throwArity (AFn.java:437)

12:09 hyPiRion: VickyIyer: when you say (defn hypt [x y] ...), you say that there are two arguments passed to the function, x and y. Thus, (hypt x y) is correct, while (hypt [x y]) is only one argument.

12:09 try out (hypt 23 45) instead

12:10 VickyIyer: oh ok, now it ran thanks, but then the arguments must be passed as a vector right

12:11 hyPiRion: VickyIyer: No - it's just to tell how many arguments the function will have.

12:12 or do you mean that in (defn foo arglist ...), the arglist must be a vector? If that's what you meant, you're correct

12:13 Scriptor: VickyIyer: no arguments should be getting passed as a vector in your example

12:13 VickyIyer: what I am confused about is when I define the function I define it as (defn hypt [ x y]....) which basically means that a vector is taken as an input then my understanding was to call this function we must also use a vector like (hypt [2 3]) this is what is conkfusing me

12:13 Scriptor: defn uses a vector to list the parameters it has, but that doesn't affect the type of the parameters

12:14 VickyIyer: that doesn't mean it takes a vector, that's just the syntax for defn

12:14 just like in python you have def foo(a, b)

12:15 that doesn't mean foo takes a tuple of a and b, it just means foo takes two parameters, a and b, and python uses parentheses to group the arguments

12:15 *group the parameters

12:15 VickyIyer: ok so what do I have to do to send a vector as an input

12:16 Scriptor: a vector is just a value, so you pass it as anything else

12:16 hyPiRion: Try out (defn hypt [[x y]] instead, if you have two elements

12:16 metellus: (defn foo [[a b]]...) would take a vector containing a and b

12:16 Scriptor: uhm

12:16 metellus: or you could do (defn foo [a]) where a is a vector

12:16 Scriptor: I think destructuring might be a bit too advanced for now

12:16 VickyIyer: (defn hypt [a b] ...) takes two parameters, so you can pass it two vectors

12:17 (hypt [1 2 3] [4 5 6])

12:17 clj_newb: Is there a function to execute a function to a every item in a seq?

12:17 hyPiRion: clj_newb: map is probably what you're looking for

12:17 VickyIyer: ok I kind of got it, probably once I work through the examples the concepts would become stroger, thnks a lot for all the help

12:18 hyPiRion: ,(map inc [1 2 3])

12:18 clojurebot: (2 3 4)

12:18 clj_newb: thanks

12:18 Scriptor: clj_newb: map is mostly used when you want a new list from the old list

12:18 if you want to do something like print each element of a list, you need something else

12:18 hyPiRion: VickyIyer: It's a bit confusing at first, but it's easier once you've programmed a little with Clojure.

12:19 Scriptor: doseq, in that case

12:20 hyPiRion: Hmm, how many printlns does clojail fire off before stopping the printing?

12:20 I want to try, but there's no point of spamming the channel.

12:24 Scriptor: hyPiRion: I just pm'd it (doseq [x (range 100)] (prn x))

12:25 but it might have a higher max for pm's

12:25 hmm, something higher than 99

12:31 cjfrisz: Huh...turns out "read" works very much like I wanted it to

12:31 How did I misread that so badly?

12:44 hyPiRion: Scriptor: Heh, it's over 100 by far.

12:47 clj_newb: is it possible to reload a file? refresh its functions (using leiningen)

12:49 (use 'my-ns.core) is not working (I cant make it work)

12:51 lysu: hi, help, I have a function (defn f [p & more] (do something)), and an vector (def arr ["1" "2"]), how can I call 'f' as (f p "1" "2") like java not (f p ["1" "2"])?

12:53 _ulises: lysu: see apply

12:53 ,(doc apply)

12:53 clojurebot: "([f args] [f x args] [f x y args] [f x y z args] [f a b c d ...]); Applies fn f to the argument list formed by prepending intervening arguments to args."

12:54 clj_newb: (apply f arr)

12:54 I think

12:54 Iceland_jack: ,(apply + [1 2 3 4])

12:54 clojurebot: 10

12:54 _ulises: ,(apply + 1 [2 3 4])

12:54 clojurebot: 10

13:01 lysu: ...oh, I see. apply has [f x args] parameters,thank you...I must more read documentation

13:52 hcastro: can someone help me understand why this query consistently returns nil yet when i run it in the management studio i get results? https://gist.github.com/3333360

15:12 qmx: what are the cool kids using for parsing w/ clojure?

16:07 clojure-newcomer: hey guys, is it possible to get any info about a multi method, like name ?

16:07 I'm passing a function into another function, and would like to get the name of the function being passed in

16:08 unsure how to get more than 'clojure.lang.MultiFn@xxxxxx'

16:14 bbloom: clojure-newcomer: some objects can have metadata

16:14 in the case of functions & other top level definitions, most of that metadata lives on their vars

16:15 clojure-newcomer: bbloom: so I could introspect on the passed in multi methods metadata ?

16:15 bbloom: the var is just a mutable indirection around a name and value, which you can get with either (var foo) or the shorthand #'foo

16:15 ,(meta identity)

16:15 clojurebot: nil

16:15 bbloom: the identity function doesn't have any meta!

16:15 but the var does:

16:15 ,(meta #'identity)

16:15 clojurebot: {:ns #<Namespace clojure.core>, :name identity, :arglists ([x]), :added "1.0", :static true, ...}

16:16 bbloom: turns out, vars are callable too!

16:16 ,(#'inc 5)

16:16 clojurebot: 6

16:16 clojure-newcomer: bbloom: thanks for your help

16:16 I'll go dig deeper on this

16:17 bbloom: yeah, def interesting

16:18 but to solve your problem, presumably for debugging purposes, you can just say "my function takes a var, not a function" and then use meta and :name on it. but really, you wouldn't want to do that outside of a debugging/testing/experimenting environment. it makes your function less useful b/c it makes the assumption that it will only ever be called with a NAMED and TOP LEVEL function. but without a var, that could also be an anon functi

16:18 any other type of callable

16:24 ,(-> #'inc meta :name)

16:24 clojurebot: inc

16:24 clojure-newcomer: bbloom: nice, thanks

16:38 bbloom: your last works in REPL but not in my prof… any ideas ? I get 'unable to resolve var: xxx in this context

16:39 *prog

16:39 bbloom: ,#'asdf

16:39 clojurebot: #<CompilerException java.lang.RuntimeException: Unable to resolve var: asdf in this context, compiling:(NO_SOURCE_PATH:0)>

16:39 bbloom: ,#'inc

16:39 clojurebot: #'clojure.core/inc

16:39 bbloom: ,#'asdf/inc

16:39 clojurebot: #<CompilerException java.lang.RuntimeException: Unable to resolve var: asdf/inc in this context, compiling:(NO_SOURCE_PATH:0)>

16:40 bbloom: clojure-newcomer: the var you're trying to get at must be in scope

16:41 clojure-newcomer: bbloom: hmmm its from a file I include via a :use

16:42 bbloom: can you create a minimal repro and send it on a paste bin?

16:42 you'll probably figure out the issue while you're creating the minimal reproduction ;-)

16:44 clojure-newcomer: bbloomer: probably because I am using [dispatch-func] and then later on #'dispatch-fund… rather than directly referencing the multi method ?

16:44 *bbloom… unsure what happened with my typing then

16:44 sorry :-)

16:44 bbloom: what are the square brackets?

16:44 an argument list?

16:44 clojure-newcomer: its an argument to the function where I am trying to do this

16:45 bbloom: ah yeah, that's not a var :-)

16:45 that's a symbol

16:45 clojure-newcomer: bbloom: ok, yup, showing my newbness

16:45 bbloom: is this all impossible then ?

16:46 bbloom: so in short: symbols are string-like-things that refer to other things; keywords are string-like things that refer themselves; vars are objects which provide thread local storage and are identified by symbols

16:46 clojure-newcomer: you just need to understand a little more deeply what's going on:

16:46 ,((fn [x] (type x) 'inc)

16:46 clojurebot: #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>

16:46 bbloom: ,((fn [x] (type x) 'inc))

16:46 clojurebot: #<ArityException clojure.lang.ArityException: Wrong number of args (0) passed to: sandbox$eval127$fn>

16:46 bbloom: ,((fn [x] (type x)) 'inc)

16:46 clojurebot: clojure.lang.Symbol

16:46 bbloom: heh. i suck at parens aparently

16:47 anyway

16:47 note that the VALUE of x is a symbol

16:47 ,((fn [x] (type x)) #'inc)

16:47 clojurebot: clojure.lang.Var

16:47 bbloom: see the difference?

16:48 clojure-newcomer: bbloom: working through it now

16:48 ...

16:49 bbloom: clojure-newcomer: however, if you're a noob, you probably shouldn't fuck with this at all. resist the urge to prematurely generalize :-)

16:50 clojure-newcomer: bbloom: definitely a noob...

16:50 bbloom: clojure-newcomer: is this your first lisp too?

16:50 clojure-newcomer: trying to find a way to dispatch on content type in a composure powered app

16:50 bbloom: yes

16:50 I fought it for years :-)

16:51 bbloom: clojure-newcomer: haha, it's ok. once you "get" symbols, you'll be like "do'h! of course! that makes perfect sense! How did I ever write code before without all of these things?"

16:51 i don't know anything about composure

16:51 but you almost definitely don't want to dispatch based on function name

16:51 that's a very ruby-ish thing to do

16:51 (is that we're you're coming from? ;-))

16:52 clojure-newcomer: bbloom: what would be the clojure _way_ / alternative ?

16:52 bbloom: clojure prefers immutable DATA

16:52 clojure-newcomer: yes, I have done a fair bit of Ruby

16:52 bbloom: so i presume composure uses ring? where you get HTTP request and response maps?

16:52 and there is a :content-type key or something?

16:52 clojure-newcomer: and you are right I am not only trying to dispatch based on a function… but on a multimethod… (even more dangerous ? )

16:53 bbloom: oh, I see what you are suggesting… interrogate request to determine path which in turn means I know the function

16:53 ?

16:53 bbloom: yeah… that just seems strange multi methods exist to facilitate dispatching, so dispatching on a dispatch primitive seems uncessary

16:53 yeah, so you can dispatch on a property of the request map

16:54 clojure-newcomer: bbloom: I'm kind of dispatching to negotiate API version and user agent… and then separately to negotiate content type to wrap the result of the former dispatch… sound mental ?

16:54 bbloom: coolio, I will try what you suggest… and thanks for the help!

16:54 bbloom: (defmethod respond-by-content-type (fn [request] (get request :content-type)))

16:54 soorry, that should be defmulti

16:54 (defmulti respond-by-content-type (fn [request] (get request :content-type)))

16:55 that's saying: define a multimethod called respond-by-content type who's dispatch function is "get the content type from the request"

16:55 and since keywords can be called like functions and behave similar to 'get, you can do:

16:55 clojure-newcomer: bbloom: looks like the kind of thing I want to do

16:55 bbloom: (defmulti respond-by-content-type :content-type)

16:55 then you do:

16:56 (defmethod respond-by-content-type :json [request] ….)

16:56 or :application/json or whatever it is

16:56 or maybe it's "application/json" as a string

16:56 *shrug*

16:57 in OOP terms, you can think about it as defining a ContentTypeResponder class and then making a function get_content_type_responder(content_type) that you then call responder.respond(request) where each TypeResponder subclass has a respond(request) method

16:58 only with a lot less typing, a lot less class names, and a lot more flexibility

16:58 clojure-newcomer: bbloom: loving multi methods, been waiting for something like this for years :-)

16:59 bbloom: clojure-newcomer: multimethods have been around since at least the 80s :-)

17:00 clojure-newcomer: everything old is new again!

17:00 clojure-newcomer: haha

17:00 bbloom: probably much further back than that

17:00 clojure-newcomer: bbloom: I'm from the Java gen :-(

17:00 I missed all the cool stuff

17:01 bbloom: it's ok, i got my start on Visual Basic 3 :-/ it's never too late to go back to basics

17:01 clojure-newcomer: Jeez :-)

17:03 bbloom: anyway, in the ruby world

17:03 to get dynamic dispatch, you need to use either inheritance or send by name

17:04 so you see a lot of foo.send("abc_#{xyz.get_foo.type.name.underscorize}")

17:04 stuff like that

17:04 right?

17:04 clojurebot: Equal Rights for Functional Objects is Baker's paper on equality and why it's impossible to define sensible equality in the presence of mutable data structures: http://www.pipeline.com/~hbaker1/ObjectIdentity.html

17:04 clojure-newcomer: bbloom: oh yeah, the nasties

17:04 bbloom: you shouldn't need to do that in clojure land b/c you have an extensible dispatch mechanism

17:05 it's called a hash table!

17:05 you can do the same thing in ruby, if you make a hash table of types to functions to call

17:05 that's all multimethods are under the hood

17:05 they are some function of argument to dispatch key, and then a map of those keys, to their respective functions

17:06 clojure-newcomer: haha, now you are making it sound easy :-)

17:06 bbloom: not easy: simple ;-)

17:06 clojure-newcomer: true

17:06 * bbloom pours clojure-newcomer a tall glass of cool aid

17:09 clojure-newcomer: bbloom: right I am gonna go make this thing work! Thanks for taking the time to stop me from committing acts of evil with this language :-)

17:10 bbloom: clojure-newcomer: my pleasure. good luck!

17:10 clojure-newcomer: thanks!

17:12 mytrile: Hey, guys. My problem is emacs related. I have clojure-swank leiningen plugin installed, but when I connect to the server in emacs and try to evaluate some function it gives me "Window #<window 3 on core.clj> too small for splitting". I'm also using emacs-live. Any ideas ?

17:40 bbloom: dnolen: you there?

17:49 nodename: Help please: running "cljsc nodels.cljs {:target :nodejs} >out/nodels.js". this was fine last time but now I get "WARNING: The form (. this toString) is no longer a property access. Maybe you meant (. this -toString) instead?"

17:50 What have I done?

17:50 bbloom: nodename: did you upgrade clojurescript?

17:50 nodename: maybe I need to?

17:51 bbloom: probably not

17:51 just wondering if you did

17:51 nodename: not sure

17:51 bbloom: and are you calling toString somewhere in your code?

17:51 either as .toString or (. x toString) or something like that?

17:51 nodename: not at all

17:51 bbloom: ok

17:52 well it *might* be fixed in a newer version of clojurescript, but in short the issue is that java and javascript have differing semantics for member access

17:52 nodename: here is nodels.cljs (copied from somewhere) that worked earlier:

17:52 bbloom: consider obj.method(arg)

17:52 nodename: $ ls

17:52 browserconnect/ getgen/ nodehello/ nodels/

17:52 ; This one doesn't yet work with :optimizations :advanced

17:52 bbloom: then consider (obj.method)(arg) that works in javascript, but not java

17:53 in javascript, you can get methods without invoking

17:53 nodename: oops, here it is:

17:53 bbloom: so in clojurescript (.-method obj) will return a function, but (.method obj) will call it

17:54 that change required cljs.core be fixed up a bunch, so the warning was added

17:54 nodename: ; This one doesn't yet work with :optimizations :advanced

17:54 (ns nodels

17:54 (:require [cljs.nodejs :as nodejs]))

17:54 (def fs (nodejs/require "fs"))

17:54 (def path (nodejs/require "path"))

17:54 (defn file-seq [dir]

17:54 (tree-seq

17:54 bbloom: generally, the warning is totally safe to ignore

17:54 nodename: (fn [f] (.isDirectory (.statSync fs f) ()))

17:54 (fn [d] (map #(.join path d %) (.readdirSync fs d)))

17:54 dir))

17:54 (defn -main [& paths]

17:54 (dorun (map println (mapcat file-seq paths))))

17:54 (set! *main-cli-fn* -main)

17:54 ~

17:54 clojurebot: No entiendo

17:54 hyPiRion: nodename: Use a pastebin please.

17:54 gfredericks: ~refheap

17:54 clojurebot: I don't understand.

17:54 ibdknox: ~gist

17:54 clojurebot: gist is forget ~paste

17:54 ibdknox: ~paste

17:54 clojurebot: paste is not gist.github.com

17:54 ibdknox: lol

17:55 hyPiRion: ~botsnack

17:55 clojurebot: Thanks, but I prefer chocolate

17:55 gfredericks: clojurebot: refheap is gist

17:55 clojurebot: You don't have to tell me twice.

17:55 hyPiRion: heh.

17:55 Raynes: ibdknox: His paste factoid is broken beyond repair.

17:55 nodename: @hyPiRion ok, sorry

17:55 ibdknox: Raynes: haha apparently

17:55 bbloom: heh.

17:55 Raynes: ibdknox: Do you have any cljs -> node experience, by chance?

17:55 gfredericks: ~refheap

17:55 clojurebot: refheap is forget ~paste

17:55 bbloom: nodename: in short, you can probably just ignore the warning

17:55 Raynes: dnolen isn't here for me to bug him.

17:56 nodename: @bbloom thanks, but I also have a run error:

17:56 $ node out/nodels.js

17:56 The "sys" module is now called "util". It should have a similar interface.

17:56 ibdknox: Raynes: I got it working briefly, but then got fed up with it

17:56 nodename: and no ls output

17:56 Raynes: Bleh.

17:56 bbloom: Raynes: i haven't tried cljs->node, but i've got experience with both. maybe i can help?

17:56 nodename: ah, yes, that was just fixed in clojurescript

17:57 nodename: https://github.com/clojure/clojurescript/commit/67e120c53774cae1a71b0a021fcdd5e3f8f888ab

17:57 nodename: Oh hold up, hold up! if I add an argument such as . I get output!

17:57 Raynes: bbloom: Well, it was all working fine until I put code in a second cljs file. Now I'm getting a weird error. I can move my code into one single file and everything is peachy. Not sure what is going on. http://github.com/Raynes/refh/tree/cljs

17:57 TypeError: Cannot read property 'q' of null

17:58 bbloom: Raynes: can you create a minimal repro? ie copy the two files & then delete code until you can't delete any more, but it still fails?

17:58 Raynes: The js output is so optimized that I can't tell what the problem is.

17:58 nodename: @bbloom ah, so recommend I update clojurescript?

17:58 bbloom: nodename: yeah, give that a try

17:58 Raynes: bbloom: It is just because of the refheap.cljs file.

17:59 nodename: pleae, from where?

17:59 Raynes: bbloom: I can move all of that code to core.cljs and it works fine.

17:59 The code is fine afaict, it's the fact that there are two files that seems to be tripping it up.

17:59 It might be a bug.

18:00 bbloom: Raynes: it's probably a bug :-P but let's try to isolate the issue

18:00 Raynes: I'm not sure how much more isolated I can get it.

18:00 bbloom: pastebin?

18:00 Raynes: You can delete every bit of the code in refheap.cljs and still get the error.

18:00 bbloom: oh whoops

18:00 djanatyn: I just grabbed the fs library by editing my project.clj and running lein deps. How do I use it in the REPL?

18:00 bbloom: you sent the file

18:00 er github link

18:00 Raynes: I sent the entire repo.

18:00 bbloom: looking now

18:00 Raynes: :p

18:01 bbloom: Raynes: your code is bugged :-P

18:01 .-strobj makes an assumption about the type of the map object

18:02 Raynes: That isn't my code.

18:02 bbloom: well whoever's code that is, it's bugged

18:02 Raynes: (as in, I didn't write it)

18:02 It isn't the problem though.

18:02 djanatyn: do I need to (require) something?

18:02 ibdknox: hah

18:02 I need to fix tht

18:03 Raynes: *shrug*

18:03 ibdknox: I wonder if that has somehow introduced some subtle bug

18:03 bbloom: well, you're getting a null reference exception

18:03 and .-strobj will be null

18:03 in many cases

18:03 Raynes: I've deleted that code entirely and it still happens.

18:03 nodename: bbloom: thanks!

18:03 bbloom: perfect. now we're isolating :-)

18:03 Raynes: And moving it to core.cljs makes it work fine.

18:04 kleini\: what's a good command line debugger for clojure?

18:04 bbloom: if refheap.cljs contains ONLY the namespace declaration, does it work?

18:04 Raynes: It does not.

18:05 bbloom: Raynes: what if you omit the ns declaration too, & just compile the two files?

18:05 Raynes: and how are you invoking the compiler?

18:05 Raynes: lein cljsbuild

18:07 bbloom: It wont compile without a namespace declaration.

18:07 bbloom: Raynes: what about with the ns declaration, but without the require clause?

18:07 ibdknox: yeah you can't compile an empty file

18:08 Raynes: bbloom: Same thing.

18:08 bbloom: hmm

18:08 you have a circular dependency

18:08 cor erequires refh.refheap

18:08 and refheap requires core

18:08 er no it does

18:08 never mind

18:08 sorry

18:08 Raynes: I was about to ask what universe.

18:08 :p

18:09 bbloom: github played a little trick on me with that goofy sliding animation

18:09 :-P

18:09 Raynes: Does the order that these things get compiled in matter? Because I have no idea what the order is.

18:11 bbloom: Raynes: In theory, it shouldn't. when compiling A with a reference to B, the compiler will pause to go compile B, unless it already has been

18:12 i don't really trust lein cljsbuild tho… the few times i tried to use it, it did weird stuff and i don't like the auto-compilation behavior. I invoked the compiler by hand in a build script or so & manually wired up my own repls

18:13 Raynes: If I couldn't use lein-cljsbuild, I'd probably just not use clojurescript.

18:13 gfredericks: or, if there is not a pen nearby, I have to convince myself that what I thought of ain't funny.

18:14 kleini\: window move 7

18:14 sorry :P

18:15 bbloom: Raynes: does it work if you turn advanced optimizations off?

18:15 if the answer is no, then the error message will be far more enlightening

18:18 Raynes: bbloom: TypeError: Cannot read property 'cljs$lang$maxFixedArity' of null

18:19 bbloom: Raynes: we'll that's a step forward! :-)

18:20 hmm…. soo that property is checked when calling apply

18:20 did it print a stack trace?

18:21 seems like somebody is trying to (apply nil …)

18:23 Raynes: bbloom: https://www.refheap.com/paste/4295

18:24 bbloom: Raynes: what's at /Users/anthony/code/refh/refh.js:12328:17 ?

18:25 Raynes: cljs.core.apply.call(null, cljs.core._STAR_main_cli_fn_STAR_, cljs.core.drop.call(null, 2, cljs.nodejs.process.argv));

18:25 bbloom: ^ There's your null apply.

18:26 bbloom: yup, cljs.core/*main-cli-fn* is nil!

18:26 :-P

18:27 looks like that code is generated out of nodejscli.cljs

18:27 Raynes: bbloom: So I guess it is expecting *main-cli-fn* to be in refheap.cljs then.

18:28 To be bound, I mean.

18:28 Sounds like a compilation order issue to me.

18:28 *shrug*

18:29 bbloom: Raynes: no

18:29 look at build in closure.clj

18:29 unless lein cljsbuild is bypassing that

18:29 it compiles all source files

18:29 & then compiles nodejscli.cljs

18:29 lazybot: java.lang.RuntimeException: Unable to resolve symbol: then in this context

18:30 bbloom: oh DUH. i know the issue!

18:31 your file is being compiled

18:31 not run

18:31 then that's going into a big bag of namespaces

18:31 which are being compiled, not run

18:32 so it's not compile order, it's execution order

18:32 nodejscli is being executed before the code that sets the main fn

18:32 Raynes: Why has God forsaken me!!!1!

18:33 bbloom: i'm not exactly sure how to go about fixing that...

18:37 Raynes: you should file a bug against cljs

18:37 include the error message, stack trace, and the line code i asked you for, and point towards nodejscli.cljs

18:37 then i'd pester dnolen to look at it ;-)

18:37 anyway, i gotta run

18:37 good luck!

18:47 cmajor7: cemerick.friend => is there a way to redirect to a different uri dynamically? It seems that the only redirect uri that is looked at is a static: ":default-landing-uri": http://bit.ly/Tw3l5N

18:48 *on a successful auth

19:03 Raynes: Dear Jira, thank you for notifying me to let me know that I commented on and/or created an issue 5 seconds ago.

19:04 talios: It's just trying to be helpful.

19:04 McMartin: That is science

19:05 Raynes: Dear Printer… meh, don't even get me started on printers.

19:06 grizlo42: Raynes: https://twitter.com/ktoro/statuses/199577756995031041

19:07 qmx: lol

19:07 Raynes: lol

19:07 McMartin: Subtle

19:08 qmx: ironically enough, after with fiddling with github issues I missed JIRA a lot :P

19:08 grizlo42: McMartin: I think that was what he was going for...

19:09 its more of a least of all evils deal

19:09 McMartin: Argh, my old coworker's appletalk printer routine is now running through my head

19:09 Appletalk was rather infamously chatty

19:09 So he would impersonate printers on appletalk networks

19:10 "I'm a printer! I'm a printer! Does anyone have any documents they want to print? 'Cause I can! Because I'm a printer! Are you a printer? That's too bad, being a printer (like me! I'm a printer!) is great!"

19:10 There were hand gestures

19:10 qmx: looks scary

19:21 Frozenlock: Is every jquery function wrapped in jayq?

19:37 the-kenny: Frozenlo`: I don't tink so. `parents' for example isn't in the .jar in my project

21:05 Raynes: dnolen: ping

21:09 JanFrederic: Raynes, I worship His Shadow.

21:24 djanatyn: I'm having trouble using the fs library I got from clojars.

21:24 it defines a function, name, that's already defined in clojure.core.

21:24 so, I tried to exclude that by using :exclude

21:24 I think I'm doing it wrong.

21:26 http://sprunge.us/VIKg?cl -- does anything stand out in this snippet as being wrong?

21:26 I think it *might* have something to do with my emacs setup. I'm not really sure how the REPL and the files I edit are connected.

21:27 jeremyheiler: You shouldn't have to quote it. Either way, I would probably use require instead. (ns clojureblog.core (:require [fs.core :as fs]))

21:27 djanatyn: what's the difference between using use and require?

21:28 jeremyheiler: by deafult require forces you to use the fully qualified name. so if I require clojure.string, in order to use "join" i would need to say (clojure.string/join "-" [seq of stuff])

21:29 djanatyn: okay. so it wouldn't try to overwrite the (nam)e function - it would just add (fs/name)

21:29 jeremyheiler: But if I use (:require [clojure.string :as string]) i would say (string/join "-" [seq of stuff])

21:29 yeah

21:29 djanatyn: cool! thank you for your help.

21:29 jeremyheiler: np

21:30 djanatyn: I changed it and tried recompiling, but now I'm getting an error

21:30 java.lang.IllegalStateException: name already refers to: #'fs.core/name in namespace: clojureblog.core

21:31 Frozenlo`: I'm trying to use jayQ and clojurescript to do this simple example: http://jqueryui.com/demos/datepicker/ but can't figure it out... So far I have (bind $datepicker :click $/datepicker). I get this error each time I click my text-field: Uncaught TypeError: Object #<Datepicker> has no method 'apply'

21:31 djanatyn: well. after restarting emacs I don't get that error. thanks!

21:31 jeremyheiler: djanatyn: good lol

21:32 was thinking something like that was the issue

21:47 qmx: is there any "autotest" runner for clojure.test?

21:47 or should I look at another test framework?

22:09 djanatyn: one more question; in the REPL, I type (use 'foo.core) to load the core.clj file in the project I'm currently working on

22:10 then I edit that file in another buffer, and compile it with C-c C-k. However, if I add new functions and definitions, the REPL doesn't reflect that unless I type (use 'foo.core) again.

22:10 Is there any way to have the REPL automatically load the file whenever it changes? that's how I worked whenever I wrote common lisp with SLIME.

22:11 or is the clojure workflow different, and should I be doing this another way?

22:12 xeqi: I usually use C-c M-n to change to the namespace in the file

22:13 and using C-c C-k to add/change functions works like that

22:17 djanatyn: xeqi: I don't completely understand what you did

22:17 did you make a new function and bind it to C-c M-n? did you change the namespace of your REPL?

22:20 xeqi: oh, blah.. I don't see that binding in clojure-mode

22:20 recently trnasistioned to nrepl.el and must of picked it up there

22:23 I think just using (in-ns 'your.namespace.here) in the repl will do the same thing

22:25 djanatyn: yes, it does! :D thank you very much!

22:49 estebann: is there a way to test if a symbol is namespace qualified?

22:51 xeqi: &(map namespace ['x 'foo/x])

22:51 lazybot: ⇒ (nil "foo")

22:51 estebann: heh

22:52 I missed that somehow.

22:52 thanks

23:23 Bahman: Hi all!

23:23 jeremyheiler: Hello

23:25 talios: 'lo

23:25 gfredericks: Hel'

23:40 treehug: is there someway to make clojure print out more meaningful textual representation of Java arrays? it gives me something like #<double[][] [[D@44022631> by default

23:42 jeremyheiler: treehug: try using pprint

23:43 treehug: oh yeah that's perfect. thanks!

23:43 jeremyheiler: np

Logging service provided by n01se.net