#clojure logs

2012-08-12

00:08howard_Good morning/afternoon/evening. Does anyone know if there is any known issue using (read-line) with clojure-contrib/server-socket?
00:09howard_I noticed that in my program, read-line will run into what appears to be infinite loop when a client disconnects
00:23llasramhoward_: Probably not the best time to ask for help -- midnight US EDT and 9pm US PST on a Saturday :-)
00:27gfredericksit's still worth a try though
01:28brainproxyanyone tried making a rootbeer-clojure float?
01:28brainproxyhttps://github.com/pcpratts/rootbeer1
03:58BahmanHi all!
03:59BahmanAnybody using borneo library for Neo4j here?
04:00BahmanIs it possible to set attributes for relationships using that library?
04:00Bahmanhttps://github.com/wagjo/borneo
04:13BahmanFound it. http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/set-prop!
04:29wuehliund ich kann es auch verstehen, dass Excel so populär ist
04:29wuehliouch, sorry
05:33ro_stanyone using midje have a solution for test coverage?
06:52McMartinDoes it deliberately choke on certain constructs?
06:53RaynesAnything in particular?
06:53McMartinI 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.
06:53McMartinWhich is Latin Square Slicing
06:54McMartinI rewrote a sequence that used nth to instead use take/drop and that at least cause *some* test cases to resolve
06:54Raynes*shrug*
06:54RaynesSome things just take longer in the sandbox.
06:54RaynesIt sucks, but it's hard to fix it.
06:54RaynesIt certainly isn't deliberant.
06:55Raynesdeliberate*
06:55McMartinAlso, for some problems (this one included) there's this 15 second delay before anything happens
06:55McMartinThis doesn't happen with all problems
06:55McMartinIs this a known thing one can trip over?
06:55RaynesThe time outs? Yes.
06:55McMartinNo, this isn't strictly a timeout
06:55McMartinIt's a big delay at the start, possibly compilation delay?
06:55McMartinBut some problems seem to get hit by it way harder than others
06:56talioswoohoo - there's a new La Clojure build that supports IntelliJ IDEA 12 available. rockin.
07:27howardIf you are looking for a Clojure implementation of document database engine, please check out https://github.com/HouzuoGuo/ClojureDB
07:31McMartinThe other possibility is that there is a completely unreasonable timeout on this problem.
07:34hyPiRionMcMartin: It's Clojail, and I don't like it either ;(
07:35McMartinRight, but what I mean is, it goes green-green-green-green-green-green-green-green-green-red-with-timeout
07:35McMartinWhen it works at all, anyway
07:35McMartinMy localside testing shows a 25x slowdown on that test case.
07:35McMartinAll the way down to a quarter of a second
07:36McMartinSo if the timeout is set to like 100ms, that would also explain this
07:36hyPiRionAh.
07:37McMartinWhoa hey
07:37McMartinMaybe that will work better
07:37hyPiRionheh
07:38hyPiRionI suspect you already know that for-comprehensions is a no-no. Go loop whenever you can.
07:38McMartinI've been getting the reverse the results from the clojail, as it happens.
07:39McMartinloop-recur is my natural state, having wandered to Clojure from Scheme and its named lets.
07:39hyPiRionIt's a shame though - for comprehensions solve a lot of the problems very elegantly.
07:39McMartinSUCCESS.
07:39McMartinWell, that's the thing; for works in places where recur has murdered me
07:40McMartinAt any rate, I am now in fact #1.
07:40hyPiRionCongratulations.
07:41McMartinALso, at some point it became 0440, I should probably try sleeping
07:41McMartinSleeping the sleep of VICTORY
07:41McMartinAnyway, thanks to those who reminded me that there are things I should mess with.
07:41hyPiRionhahah
07:42McMartinAnd now to translate my real projects into proper Java because I'm going to target Froyo phones =(
07:45McMartinAnyway, check out this horrible meta-for I had to make:
07:45McMartin(defn nest-ranges [xs] (if (empty? xs) '(()) (let [sub (nest-ranges (rest xs))] (mapcat (fn [n] (map #(conj % n) sub)) (range (first xs))))))
07:46hyPiRionwow, mapcat
07:46hyPiRionlong time, no see.
07:46McMartinNot only that, actual lists
07:46hyPiRionheg
07:46McMartinYou 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
07:47hyPiRion4clojure - for your obfuscating needs.
07:47McMartinSorta
07:48McMartinIt's pretty straightforward if you tab it into proper whitespacing
07:48McMartinIt's just a problem you almost never need to solve, because the *number of loop variables* is usually constant
07:49McMartinIt turns out my algorithm for that 4clojure problem, however, was a case where they weren't.
07:49hyPiRionyeah
07:49McMartin(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)
07:51McMartinOTOH, I think solving http://www.4clojure.com/problem/113 actually made me a worse programmer.
07:56hyPiRionMcMartin: Well, it's just a reify, isn't it?
07:57hyPiRionbut yeah, it's not exactly pretty.
07:59McMartinYes, now I know how to use reify to do that
07:59McMartinAs a result, I am now a worse programmer
07:59McMartinIt's like mastering PHP~
08:07hyPiRionMcMartin: haha
08:07hyPiRionYou should look up reify and how to extend types and so forth - it's not that hard.
08:12McMartinYeah
08:12McMartinI've played with proxy in Swing some
09:25magopianhello 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?
09:26gfrederickswell it's a list
09:26gfredericksso you can check if the first thing is '+
09:26gfredericksand then add the other things if it is
09:27gfredericksthe trickiest part is probably getting the recursion right for the arbitrarily nested cases
09:29magopiangfredericks: mmmm i think i get it
09:29magopianthen i'll need to see how i can use '{a 1 b 1} in the ":or" part of a map binding-form
09:30magopianit's strange that i can't just "apply (first l) (rest l)" on '(+ 1 1)
09:30magopianwell, at least, it's strange to me ;)
09:31gfrederickscuz 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
09:31magopiansure
09:31magopianso + is a symbol, not a function?
09:32magopianor is it a symbol only because it's inside a list?
09:33gfredericksthere's three things going on
09:33gfredericks,(type '+)
09:33clojurebotclojure.lang.Symbol
09:33gfredericks+ unevaluated is a symbol
09:33gfrederickswhich is just data
09:33gfredericks,(resolve '+)
09:33clojurebot#'clojure.core/+
09:34gfrederickswhen you resolve it _in the context of your namespace_, you get back a var
09:34gfredericksso + in another namespace might refer to a different var
09:34magopianand in the var, there's the function
09:34gfredericks,(deref (resolve '+))
09:34clojurebot#<core$_PLUS_ clojure.core$_PLUS_@5506ff2e>
09:34gfredericksyep, you deref the var and there's the actual function you want
09:35magopiani'm going to re-read that several times ;)
09:35magopianso i could use resolve and deref instead of eval ?
09:35gfrederickswhen you use vars in normal code, the resolving is done at compile-time, and the derefing is done at runtime
09:35gfredericksif 4clojure didn't forbid it you could
09:35magopianoh ok got it ;)
09:35magopiananyway, it's not the point of the exercise (to use eval or resolve+deref), but i think i understand now ;)
09:36gfredericksthat's cool it took me a year or so :D
09:36magopianawesome, thanks a ton gfredericks that was _really_ clear and understandable ;)
09:36gfredericksno problem
09:36magopian(i love 4clojure ;) it really got me to like functional programming ;)
09:37gfredericks(inc 4clojure)
09:37lazybot⇒ 1
09:37magopiani still have to discover what is clojure especially good at, compared to other functional programming languages, like common lisp
09:37cshellmagopian: data tranformation and manipulation
09:38magopianthanks again gfredericks ;)
09:38Scriptormagopian: also, common lisp isn't as functional as clojure
09:38magopiancshell: you mean, thanks to its data structures?
09:38magopianScriptor: you mean, "not as pure" ?
09:38magopiani'm still just discovering functional programming, so bear with me ;)
09:39Scriptormagopian: not really purity, just in general clojure embraces a functional style and immutability more
09:39Nikelandjelo,((resolve '+) 1 1)
09:39clojurebot2
09:39Scriptoralso, 4clojure is a double-edged sword
09:39hyPiRionhuh, resolve.
09:39Nikelandjelo,((deref (resolve '+)) 1 1)
09:39clojurebot2
09:39ScriptorI thought my reverse interleave was clever until I saw the usual solution
09:39NikelandjeloWhen I do (resolve '+) I get a var, not function, right?
09:40hyPiRion,(resolve 1)
09:40clojurebot#<ClassCastException java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.Symbol>
09:40xeqiNikelandjelo: invoke on a var is defined to deref automatically
09:40magopianScriptor: can you explain why it's a double-edgd sword?
09:40Nikelandjeloxeqi: thanks
09:41Scriptormagopian: look above, it was mostly tongue-in-cheek :)
09:41magopianScriptor: ok, got it ;)
09:41Scriptoronly in that when you think you do have a good solution there always seems to be a better one
09:41magopianyeah, i feel that with nearly each problem i solve ;)
09:41hyPiRion,(let [evl (fn [x] ({'* *, '+ +, '- -, '/ /} x x)] (map evl '(+ - * / + 1 2 3)))
09:41clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: Unmatched delimiter: ]>
09:41hyPiRioneww
09:41hyPiRion,(let [evl (fn [x] ({'* *, '+ +, '- -, '/ /} x x))] (map evl '(+ - * / + 1 2 3)))
09:41clojurebot(#<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> ...)
09:42wmealing__hyPiRion, my headd..
09:43hyPiRionwmealing__: sorry.
09:45magopianhyPiRion: it's missing a ") '(" between the operators and the args ;)
09:45hyPiRionI realized.
09:47tomojwhat might a (non-clojure)-code generation framework look like?
09:47hyPiRioncode generation?
09:47tomojI note the cljs compiler is in imperative style
09:48hyPiRionOh, parsec maybe?
09:49tomoj(code ["function (x) {"] (indent ["return x;"]) ["}"])
09:49tomojtrying to work that out now but I don't think it's right
10:56FrozenlockPerhaps 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:06hyPiRionFrozenlock: theoretically, yes
11:07hyPiRionHowever, it doesn't cover the following:
11:07hyPiRion1. native methods 2. reflection 3. dynamic method invocation
11:08hyPiRionWhich is basically what Clojure is :p
11:20eru`How would I accomplish something like (let [x (some-ajax-call) y (another-ajax-call)] (f @x @y)) in ClojureScript?
11:20FrozenlockhyPiRion: So I should not get excited about this :(
11:28tickingis anybody using emacs on a mac, with [] maped to alt-number commands? I don't know how to switch from meta to als…
11:40hyPiRionFrozenlock: At least not yet.
11:43unlinkIs there something like Maybe in Clojure? (Boxing values)
11:50danielglauserDoes anyone know what the ampersand means in this line of code?
11:50danielglauser(catch Object _
11:50danielglauser (log/error (:throwable &throw-context) "unexpected error")
11:50danielglauserWhat is &throw-context ?
11:54_atodanielglauser: https://github.com/scgilardi/slingshot/blob/master/README.md (about halfway down the page)
11:55danielglauser_ato: You know, I have that page open and read a good chunk of it…Thanks!
11:55alexyakushevIs there some kind of `constantly` macro that creates a function of any arguments and evaluates its body every time when called?
11:57gfredericksalexyakushev: that wouldn't save much over just (fn [& _] my-body) would it?
11:57_atodanielglauser: 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:59hyPiRionalexyakushev: constantly?
11:59hyPiRion,(doc constantly)
11:59clojurebot"([x]); Returns a function that takes any number of arguments and returns x."
11:59hyPiRionoh, I see.
12:00hyPiRion,(doc repeatedly)
12:00clojurebot"([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:00clj_newbis there a function to parse a Character to a number other than (Character/digit) ?
12:01cjfriszHow do you read something from a file as though it's a sequence/S-expression?
12:01cjfriszA la Scheme's read? (http://scheme.com/tspl4/io.html#./io:s81)
12:02alexyakushevhyPiRion: constantly returns the same value every time, but I want it to be revaluated
12:02alexyakushev,(map (constantly (rand)) (range 5))
12:02clojurebot(0.9167970343709244 0.9167970343709244 0.9167970343709244 0.9167970343709244 0.9167970343709244)
12:03hyPiRion,(repeatedly 5 rand)
12:03clojurebot(0.9477552907069643 0.4584298110320799 0.15597111467683888 0.6704665582926552 0.9412675879153743)
12:03alexyakushevhyPiRion: yep, I know about repeatedly, but that's not what I want, that was just a demonstration
12:04hyPiRionHm.
12:05hyPiRionYou could always wrap it in a (fn [&] ...), to get the same result
12:05alexyakushevI can, I just thought maybe there is already a macro for that
12:05alexyakushevhyPiRion: actually what I exactly need is (defmacro const [& body] `(fn [& _#] ~@body))
12:06hyPiRionokey, I don't think there is one.
12:06alexyakushevhyPiRion: Thanks anyway!
12:06hyPiRionconstantly, repeatedly, partial are the closest I know of
12:06hyPiRionno problem
12:07VickyIyerHello 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:07VickyIyer (let [x2 (double-me x)
12:07VickyIyer y2 (double-me y)]
12:07VickyIyer (Math/sqrt (+ x2 y2))))
12:08VickyIyer (hypt [23 45])
12:08VickyIyerArityException Wrong number of args (1) passed to: double-me$hypt clojure.lang.AFn.throwArity (AFn.java:437)
12:09hyPiRionVickyIyer: 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:09hyPiRiontry out (hypt 23 45) instead
12:10VickyIyeroh ok, now it ran thanks, but then the arguments must be passed as a vector right
12:11hyPiRionVickyIyer: No - it's just to tell how many arguments the function will have.
12:12hyPiRionor do you mean that in (defn foo arglist ...), the arglist must be a vector? If that's what you meant, you're correct
12:13ScriptorVickyIyer: no arguments should be getting passed as a vector in your example
12:13VickyIyerwhat 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:13Scriptordefn uses a vector to list the parameters it has, but that doesn't affect the type of the parameters
12:14ScriptorVickyIyer: that doesn't mean it takes a vector, that's just the syntax for defn
12:14Scriptorjust like in python you have def foo(a, b)
12:15Scriptorthat 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:15Scriptor*group the parameters
12:15VickyIyerok so what do I have to do to send a vector as an input
12:16Scriptora vector is just a value, so you pass it as anything else
12:16hyPiRionTry out (defn hypt [[x y]] instead, if you have two elements
12:16metellus(defn foo [[a b]]...) would take a vector containing a and b
12:16Scriptoruhm
12:16metellusor you could do (defn foo [a]) where a is a vector
12:16ScriptorI think destructuring might be a bit too advanced for now
12:16ScriptorVickyIyer: (defn hypt [a b] ...) takes two parameters, so you can pass it two vectors
12:17Scriptor(hypt [1 2 3] [4 5 6])
12:17clj_newbIs there a function to execute a function to a every item in a seq?
12:17hyPiRionclj_newb: map is probably what you're looking for
12:17VickyIyerok 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:18hyPiRion,(map inc [1 2 3])
12:18clojurebot(2 3 4)
12:18clj_newbthanks
12:18Scriptorclj_newb: map is mostly used when you want a new list from the old list
12:18Scriptorif you want to do something like print each element of a list, you need something else
12:18hyPiRionVickyIyer: It's a bit confusing at first, but it's easier once you've programmed a little with Clojure.
12:19Scriptordoseq, in that case
12:20hyPiRionHmm, how many printlns does clojail fire off before stopping the printing?
12:20hyPiRionI want to try, but there's no point of spamming the channel.
12:24ScriptorhyPiRion: I just pm'd it (doseq [x (range 100)] (prn x))
12:25Scriptorbut it might have a higher max for pm's
12:25Scriptorhmm, something higher than 99
12:31cjfriszHuh...turns out "read" works very much like I wanted it to
12:31cjfriszHow did I misread that so badly?
12:44hyPiRionScriptor: Heh, it's over 100 by far.
12:47clj_newbis it possible to reload a file? refresh its functions (using leiningen)
12:49clj_newb(use 'my-ns.core) is not working (I cant make it work)
12:51lysuhi, 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_uliseslysu: see apply
12:53_ulises,(doc apply)
12:53clojurebot"([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:54clj_newb(apply f arr)
12:54clj_newbI think
12:54Iceland_jack,(apply + [1 2 3 4])
12:54clojurebot10
12:54_ulises,(apply + 1 [2 3 4])
12:54clojurebot10
13:01lysu...oh, I see. apply has [f x args] parameters,thank you...I must more read documentation
13:52hcastrocan 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:12qmxwhat are the cool kids using for parsing w/ clojure?
16:07clojure-newcomerhey guys, is it possible to get any info about a multi method, like name ?
16:07clojure-newcomerI'm passing a function into another function, and would like to get the name of the function being passed in
16:08clojure-newcomerunsure how to get more than 'clojure.lang.MultiFn@xxxxxx'
16:14bbloomclojure-newcomer: some objects can have metadata
16:14bbloomin the case of functions & other top level definitions, most of that metadata lives on their vars
16:15clojure-newcomerbbloom: so I could introspect on the passed in multi methods metadata ?
16:15bbloomthe var is just a mutable indirection around a name and value, which you can get with either (var foo) or the shorthand #'foo
16:15bbloom,(meta identity)
16:15clojurebotnil
16:15bbloomthe identity function doesn't have any meta!
16:15bbloombut the var does:
16:15bbloom,(meta #'identity)
16:15clojurebot{:ns #<Namespace clojure.core>, :name identity, :arglists ([x]), :added "1.0", :static true, ...}
16:16bbloomturns out, vars are callable too!
16:16bbloom,(#'inc 5)
16:16clojurebot6
16:16clojure-newcomerbbloom: thanks for your help
16:16clojure-newcomerI'll go dig deeper on this
16:17bbloomyeah, def interesting
16:18bbloombut 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:18bbloom any other type of callable
16:24bbloom,(-> #'inc meta :name)
16:24clojurebotinc
16:24clojure-newcomerbbloom: nice, thanks
16:38clojure-newcomerbbloom: your last works in REPL but not in my prof… any ideas ? I get 'unable to resolve var: xxx in this context
16:39clojure-newcomer*prog
16:39bbloom,#'asdf
16:39clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve var: asdf in this context, compiling:(NO_SOURCE_PATH:0)>
16:39bbloom,#'inc
16:39clojurebot#'clojure.core/inc
16:39bbloom,#'asdf/inc
16:39clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve var: asdf/inc in this context, compiling:(NO_SOURCE_PATH:0)>
16:40bbloomclojure-newcomer: the var you're trying to get at must be in scope
16:41clojure-newcomerbbloom: hmmm its from a file I include via a :use
16:42bbloomcan you create a minimal repro and send it on a paste bin?
16:42bbloomyou'll probably figure out the issue while you're creating the minimal reproduction ;-)
16:44clojure-newcomerbbloomer: probably because I am using [dispatch-func] and then later on #'dispatch-fund… rather than directly referencing the multi method ?
16:44clojure-newcomer*bbloom… unsure what happened with my typing then
16:44clojure-newcomersorry :-)
16:44bbloomwhat are the square brackets?
16:44bblooman argument list?
16:44clojure-newcomerits an argument to the function where I am trying to do this
16:45bbloomah yeah, that's not a var :-)
16:45bbloomthat's a symbol
16:45clojure-newcomerbbloom: ok, yup, showing my newbness
16:45clojure-newcomerbbloom: is this all impossible then ?
16:46bbloomso 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:46bbloomclojure-newcomer: you just need to understand a little more deeply what's going on:
16:46bbloom,((fn [x] (type x) 'inc)
16:46clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
16:46bbloom,((fn [x] (type x) 'inc))
16:46clojurebot#<ArityException clojure.lang.ArityException: Wrong number of args (0) passed to: sandbox$eval127$fn>
16:46bbloom,((fn [x] (type x)) 'inc)
16:46clojurebotclojure.lang.Symbol
16:46bbloomheh. i suck at parens aparently
16:47bbloomanyway
16:47bbloomnote that the VALUE of x is a symbol
16:47bbloom,((fn [x] (type x)) #'inc)
16:47clojurebotclojure.lang.Var
16:47bbloomsee the difference?
16:48clojure-newcomerbbloom: working through it now
16:48clojure-newcomer...
16:49bbloomclojure-newcomer: however, if you're a noob, you probably shouldn't fuck with this at all. resist the urge to prematurely generalize :-)
16:50clojure-newcomerbbloom: definitely a noob...
16:50bbloomclojure-newcomer: is this your first lisp too?
16:50clojure-newcomertrying to find a way to dispatch on content type in a composure powered app
16:50clojure-newcomerbbloom: yes
16:50clojure-newcomerI fought it for years :-)
16:51bbloomclojure-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:51bbloomi don't know anything about composure
16:51bbloombut you almost definitely don't want to dispatch based on function name
16:51bbloomthat's a very ruby-ish thing to do
16:51bbloom(is that we're you're coming from? ;-))
16:52clojure-newcomerbbloom: what would be the clojure _way_ / alternative ?
16:52bbloomclojure prefers immutable DATA
16:52clojure-newcomeryes, I have done a fair bit of Ruby
16:52bbloomso i presume composure uses ring? where you get HTTP request and response maps?
16:52bbloomand there is a :content-type key or something?
16:52clojure-newcomerand you are right I am not only trying to dispatch based on a function… but on a multimethod… (even more dangerous ? )
16:53clojure-newcomerbbloom: oh, I see what you are suggesting… interrogate request to determine path which in turn means I know the function
16:53clojure-newcomer?
16:53bbloomyeah… that just seems strange multi methods exist to facilitate dispatching, so dispatching on a dispatch primitive seems uncessary
16:53bbloomyeah, so you can dispatch on a property of the request map
16:54clojure-newcomerbbloom: 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:54clojure-newcomerbbloom: coolio, I will try what you suggest… and thanks for the help!
16:54bbloom(defmethod respond-by-content-type (fn [request] (get request :content-type)))
16:54bbloomsoorry, that should be defmulti
16:54bbloom(defmulti respond-by-content-type (fn [request] (get request :content-type)))
16:55bbloomthat's saying: define a multimethod called respond-by-content type who's dispatch function is "get the content type from the request"
16:55bbloomand since keywords can be called like functions and behave similar to 'get, you can do:
16:55clojure-newcomerbbloom: looks like the kind of thing I want to do
16:55bbloom(defmulti respond-by-content-type :content-type)
16:55bbloomthen you do:
16:56bbloom(defmethod respond-by-content-type :json [request] ….)
16:56bbloomor :application/json or whatever it is
16:56bbloomor maybe it's "application/json" as a string
16:56bbloom*shrug*
16:57bbloomin 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:58bbloomonly with a lot less typing, a lot less class names, and a lot more flexibility
16:58clojure-newcomerbbloom: loving multi methods, been waiting for something like this for years :-)
16:59bbloomclojure-newcomer: multimethods have been around since at least the 80s :-)
17:00bbloomclojure-newcomer: everything old is new again!
17:00clojure-newcomerhaha
17:00bbloomprobably much further back than that
17:00clojure-newcomerbbloom: I'm from the Java gen :-(
17:00clojure-newcomerI missed all the cool stuff
17:01bbloomit's ok, i got my start on Visual Basic 3 :-/ it's never too late to go back to basics
17:01clojure-newcomerJeez :-)
17:03bbloomanyway, in the ruby world
17:03bbloomto get dynamic dispatch, you need to use either inheritance or send by name
17:04bbloomso you see a lot of foo.send("abc_#{xyz.get_foo.type.name.underscorize}")
17:04bbloomstuff like that
17:04bbloomright?
17:04clojurebotEqual 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:04clojure-newcomerbbloom: oh yeah, the nasties
17:04bbloomyou shouldn't need to do that in clojure land b/c you have an extensible dispatch mechanism
17:05bbloomit's called a hash table!
17:05bbloomyou can do the same thing in ruby, if you make a hash table of types to functions to call
17:05bbloomthat's all multimethods are under the hood
17:05bbloomthey are some function of argument to dispatch key, and then a map of those keys, to their respective functions
17:06clojure-newcomerhaha, now you are making it sound easy :-)
17:06bbloomnot easy: simple ;-)
17:06clojure-newcomertrue
17:09clojure-newcomerbbloom: 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:10bbloomclojure-newcomer: my pleasure. good luck!
17:10clojure-newcomerthanks!
17:12mytrileHey, 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:40bbloomdnolen: you there?
17:49nodenameHelp 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:50nodenameWhat have I done?
17:50bbloomnodename: did you upgrade clojurescript?
17:50nodenamemaybe I need to?
17:51bbloomprobably not
17:51bbloomjust wondering if you did
17:51nodenamenot sure
17:51bbloomand are you calling toString somewhere in your code?
17:51bbloomeither as .toString or (. x toString) or something like that?
17:51nodenamenot at all
17:51bbloomok
17:52bbloomwell 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:52nodenamehere is nodels.cljs (copied from somewhere) that worked earlier:
17:52bbloomconsider obj.method(arg)
17:52nodename$ ls
17:52nodenamebrowserconnect/ getgen/ nodehello/ nodels/
17:52nodename; This one doesn't yet work with :optimizations :advanced
17:52bbloomthen consider (obj.method)(arg) that works in javascript, but not java
17:53bbloomin javascript, you can get methods without invoking
17:53nodenameoops, here it is:
17:53bbloomso in clojurescript (.-method obj) will return a function, but (.method obj) will call it
17:54bbloomthat change required cljs.core be fixed up a bunch, so the warning was added
17:54nodename; This one doesn't yet work with :optimizations :advanced
17:54nodename(ns nodels
17:54nodename (:require [cljs.nodejs :as nodejs]))
17:54nodename(def fs (nodejs/require "fs"))
17:54nodename(def path (nodejs/require "path"))
17:54nodename(defn file-seq [dir]
17:54nodename (tree-seq
17:54bbloomgenerally, the warning is totally safe to ignore
17:54nodename (fn [f] (.isDirectory (.statSync fs f) ()))
17:54nodename (fn [d] (map #(.join path d %) (.readdirSync fs d)))
17:54nodename dir))
17:54nodename(defn -main [& paths]
17:54nodename (dorun (map println (mapcat file-seq paths))))
17:54nodename(set! *main-cli-fn* -main)
17:54nodename~
17:54clojurebotNo entiendo
17:54hyPiRionnodename: Use a pastebin please.
17:54gfredericks~refheap
17:54clojurebotI don't understand.
17:54ibdknox~gist
17:54clojurebotgist is forget ~paste
17:54ibdknox~paste
17:54clojurebotpaste is not gist.github.com
17:54ibdknoxlol
17:55hyPiRion~botsnack
17:55clojurebotThanks, but I prefer chocolate
17:55gfredericksclojurebot: refheap is gist
17:55clojurebotYou don't have to tell me twice.
17:55hyPiRionheh.
17:55Raynesibdknox: His paste factoid is broken beyond repair.
17:55nodename@hyPiRion ok, sorry
17:55ibdknoxRaynes: haha apparently
17:55bbloomheh.
17:55Raynesibdknox: Do you have any cljs -> node experience, by chance?
17:55gfredericks~refheap
17:55clojurebotrefheap is forget ~paste
17:55bbloomnodename: in short, you can probably just ignore the warning
17:55Raynesdnolen isn't here for me to bug him.
17:56nodename@bbloom thanks, but I also have a run error:
17:56nodename$ node out/nodels.js
17:56nodenameThe "sys" module is now called "util". It should have a similar interface.
17:56ibdknoxRaynes: I got it working briefly, but then got fed up with it
17:56nodenameand no ls output
17:56RaynesBleh.
17:56bbloomRaynes: i haven't tried cljs->node, but i've got experience with both. maybe i can help?
17:56bbloomnodename: ah, yes, that was just fixed in clojurescript
17:57bbloomnodename: https://github.com/clojure/clojurescript/commit/67e120c53774cae1a71b0a021fcdd5e3f8f888ab
17:57nodenameOh hold up, hold up! if I add an argument such as . I get output!
17:57Raynesbbloom: 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:57RaynesTypeError: Cannot read property 'q' of null
17:58bbloomRaynes: 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:58RaynesThe js output is so optimized that I can't tell what the problem is.
17:58nodename@bbloom ah, so recommend I update clojurescript?
17:58bbloomnodename: yeah, give that a try
17:58Raynesbbloom: It is just because of the refheap.cljs file.
17:59nodenamepleae, from where?
17:59Raynesbbloom: I can move all of that code to core.cljs and it works fine.
17:59RaynesThe code is fine afaict, it's the fact that there are two files that seems to be tripping it up.
17:59RaynesIt might be a bug.
18:00bbloomRaynes: it's probably a bug :-P but let's try to isolate the issue
18:00RaynesI'm not sure how much more isolated I can get it.
18:00bbloompastebin?
18:00RaynesYou can delete every bit of the code in refheap.cljs and still get the error.
18:00bbloomoh whoops
18:00djanatynI just grabbed the fs library by editing my project.clj and running lein deps. How do I use it in the REPL?
18:00bbloomyou sent the file
18:00bbloomer github link
18:00RaynesI sent the entire repo.
18:00bbloomlooking now
18:00Raynes:p
18:01bbloomRaynes: your code is bugged :-P
18:01bbloom.-strobj makes an assumption about the type of the map object
18:02RaynesThat isn't my code.
18:02bbloomwell whoever's code that is, it's bugged
18:02Raynes(as in, I didn't write it)
18:02RaynesIt isn't the problem though.
18:02djanatyndo I need to (require) something?
18:02ibdknoxhah
18:02ibdknoxI need to fix tht
18:03Raynes*shrug*
18:03ibdknoxI wonder if that has somehow introduced some subtle bug
18:03bbloomwell, you're getting a null reference exception
18:03bbloomand .-strobj will be null
18:03bbloomin many cases
18:03RaynesI've deleted that code entirely and it still happens.
18:03nodenamebbloom: thanks!
18:03bbloomperfect. now we're isolating :-)
18:03RaynesAnd moving it to core.cljs makes it work fine.
18:04kleini\what's a good command line debugger for clojure?
18:04bbloomif refheap.cljs contains ONLY the namespace declaration, does it work?
18:04RaynesIt does not.
18:05bbloomRaynes: what if you omit the ns declaration too, & just compile the two files?
18:05bbloomRaynes: and how are you invoking the compiler?
18:05Rayneslein cljsbuild
18:07Raynesbbloom: It wont compile without a namespace declaration.
18:07bbloomRaynes: what about with the ns declaration, but without the require clause?
18:07ibdknoxyeah you can't compile an empty file
18:08Raynesbbloom: Same thing.
18:08bbloomhmm
18:08bbloomyou have a circular dependency
18:08bbloomcor erequires refh.refheap
18:08bbloomand refheap requires core
18:08bbloomer no it does
18:08bbloomnever mind
18:08bbloomsorry
18:08RaynesI was about to ask what universe.
18:08Raynes:p
18:09bbloomgithub played a little trick on me with that goofy sliding animation
18:09bbloom:-P
18:09RaynesDoes the order that these things get compiled in matter? Because I have no idea what the order is.
18:11bbloomRaynes: 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:12bbloomi 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:13RaynesIf I couldn't use lein-cljsbuild, I'd probably just not use clojurescript.
18:13gfredericksor, if there is not a pen nearby, I have to convince myself that what I thought of ain't funny.
18:14kleini\window move 7
18:14kleini\sorry :P
18:15bbloomRaynes: does it work if you turn advanced optimizations off?
18:15bbloomif the answer is no, then the error message will be far more enlightening
18:18Raynesbbloom: TypeError: Cannot read property 'cljs$lang$maxFixedArity' of null
18:19bbloomRaynes: we'll that's a step forward! :-)
18:20bbloomhmm…. soo that property is checked when calling apply
18:20bbloomdid it print a stack trace?
18:21bbloomseems like somebody is trying to (apply nil …)
18:23Raynesbbloom: https://www.refheap.com/paste/4295
18:24bbloomRaynes: what's at /Users/anthony/code/refh/refh.js:12328:17 ?
18:25Raynescljs.core.apply.call(null, cljs.core._STAR_main_cli_fn_STAR_, cljs.core.drop.call(null, 2, cljs.nodejs.process.argv));
18:25Raynesbbloom: ^ There's your null apply.
18:26bbloomyup, cljs.core/*main-cli-fn* is nil!
18:26bbloom:-P
18:27bbloomlooks like that code is generated out of nodejscli.cljs
18:27Raynesbbloom: So I guess it is expecting *main-cli-fn* to be in refheap.cljs then.
18:28RaynesTo be bound, I mean.
18:28RaynesSounds like a compilation order issue to me.
18:28Raynes*shrug*
18:29bbloomRaynes: no
18:29bbloomlook at build in closure.clj
18:29bbloomunless lein cljsbuild is bypassing that
18:29bbloomit compiles all source files
18:29bbloom& then compiles nodejscli.cljs
18:29lazybotjava.lang.RuntimeException: Unable to resolve symbol: then in this context
18:30bbloomoh DUH. i know the issue!
18:31bbloomyour file is being compiled
18:31bbloomnot run
18:31bbloomthen that's going into a big bag of namespaces
18:31bbloomwhich are being compiled, not run
18:32bbloomso it's not compile order, it's execution order
18:32bbloomnodejscli is being executed before the code that sets the main fn
18:32RaynesWhy has God forsaken me!!!1!
18:33bbloomi'm not exactly sure how to go about fixing that...
18:37bbloomRaynes: you should file a bug against cljs
18:37bbloominclude the error message, stack trace, and the line code i asked you for, and point towards nodejscli.cljs
18:37bbloomthen i'd pester dnolen to look at it ;-)
18:37bbloomanyway, i gotta run
18:37bbloomgood luck!
18:47cmajor7cemerick.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:48cmajor7*on a successful auth
19:03RaynesDear Jira, thank you for notifying me to let me know that I commented on and/or created an issue 5 seconds ago.
19:04taliosIt's just trying to be helpful.
19:04McMartinThat is science
19:05RaynesDear Printer… meh, don't even get me started on printers.
19:06grizlo42Raynes: https://twitter.com/ktoro/statuses/199577756995031041
19:07qmxlol
19:07Rayneslol
19:07McMartinSubtle
19:08qmxironically enough, after with fiddling with github issues I missed JIRA a lot :P
19:08grizlo42McMartin: I think that was what he was going for...
19:09grizlo42its more of a least of all evils deal
19:09McMartinArgh, my old coworker's appletalk printer routine is now running through my head
19:09McMartinAppletalk was rather infamously chatty
19:09McMartinSo he would impersonate printers on appletalk networks
19:10McMartin"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:10McMartinThere were hand gestures
19:10qmxlooks scary
19:21FrozenlockIs every jquery function wrapped in jayq?
19:37the-kennyFrozenlo`: I don't tink so. `parents' for example isn't in the .jar in my project
21:05Raynesdnolen: ping
21:09JanFredericRaynes, I worship His Shadow.
21:24djanatynI'm having trouble using the fs library I got from clojars.
21:24djanatynit defines a function, name, that's already defined in clojure.core.
21:24djanatynso, I tried to exclude that by using :exclude
21:24djanatynI think I'm doing it wrong.
21:26djanatynhttp://sprunge.us/VIKg?cl -- does anything stand out in this snippet as being wrong?
21:26djanatynI 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:27jeremyheilerYou shouldn't have to quote it. Either way, I would probably use require instead. (ns clojureblog.core (:require [fs.core :as fs]))
21:27djanatynwhat's the difference between using use and require?
21:28jeremyheilerby 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:29djanatynokay. so it wouldn't try to overwrite the (nam)e function - it would just add (fs/name)
21:29jeremyheilerBut if I use (:require [clojure.string :as string]) i would say (string/join "-" [seq of stuff])
21:29jeremyheileryeah
21:29djanatyncool! thank you for your help.
21:29jeremyheilernp
21:30djanatynI changed it and tried recompiling, but now I'm getting an error
21:30djanatynjava.lang.IllegalStateException: name already refers to: #'fs.core/name in namespace: clojureblog.core
21:31Frozenlo`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:31djanatynwell. after restarting emacs I don't get that error. thanks!
21:31jeremyheilerdjanatyn: good lol
21:32jeremyheilerwas thinking something like that was the issue
21:47qmxis there any "autotest" runner for clojure.test?
21:47qmxor should I look at another test framework?
22:09djanatynone 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:10djanatynthen 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:10djanatynIs 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:11djanatynor is the clojure workflow different, and should I be doing this another way?
22:12xeqiI usually use C-c M-n to change to the namespace in the file
22:13xeqiand using C-c C-k to add/change functions works like that
22:17djanatynxeqi: I don't completely understand what you did
22:17djanatyndid you make a new function and bind it to C-c M-n? did you change the namespace of your REPL?
22:20xeqioh, blah.. I don't see that binding in clojure-mode
22:20xeqirecently trnasistioned to nrepl.el and must of picked it up there
22:23xeqiI think just using (in-ns 'your.namespace.here) in the repl will do the same thing
22:25djanatynyes, it does! :D thank you very much!
22:49estebannis there a way to test if a symbol is namespace qualified?
22:51xeqi&(map namespace ['x 'foo/x])
22:51lazybot⇒ (nil "foo")
22:51estebannheh
22:52estebannI missed that somehow.
22:52estebannthanks
23:23BahmanHi all!
23:23jeremyheilerHello
23:25talios'lo
23:25gfredericksHel'
23:40treehugis 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:42jeremyheilertreehug: try using pprint
23:43treehugoh yeah that's perfect. thanks!
23:43jeremyheilernp