#clojure logs

2011-08-26

00:08gstampis there any way to pass JVM arguments to the lein swank subprocess? I'm trying to setup profiling
01:11technomancygstamp: :jvm-opts in project.clj
01:19polypus74trying out clj-redis. there is no select command available, anybody know anything about it?
01:22gstamptechnomancy: it seemed like those options were not being passed down to the JVM spawned by lein-swank
01:24amalloypolypus74: aleph-redis surely supports select
01:25duck1123yeah, Aleph's redis support has all the commands
01:27amalloyat least in the sense that it has none of them, and will happily send any old junk. the protocol is self-documented enough that aleph can parse the right "answer" without knowing what the command means
01:27technomancygstamp: just confirmed it works here
01:28polypus74amalloy: ty, i'll have a look, although i just read that having > 1 db is discouraged and may even be deprecated, so i may go another route
01:28technomancygstamp: it should be a vector of strings
01:29duck1123polypus74: Where did you hear that? If anything, I've been hearing more and more about people clustering redis
01:29polypus74not more than one instance, more than one indexable db, which is different
01:30gstamptechnomany: okay, strange. that's what I've I'm using. I'll double check
01:32polypus74duck1123: https://github.com/xetorthio/jedis/issues/85, fourth comment from bottom
01:33amalloypolypus74: deprecated on jedis, maybe, but i don't see anyone saying you shouldn't do it with redis in general
01:51gstamptechnomancy: Looks like I was mistaken. It seems to work fine. Sorry about that.
01:52scottjamalloy: where's your utils repo ago?
01:52scottjagain
01:52amalloyscottj: github.com/amalloy/amalloy-utils - but most of it's been absorbed into ninjudd's useful
01:52amalloygithub.com/flatland/useful
01:55scottjamalloy: ty
02:14ibdknoxfor those following along, I updated the pinot readme with all sorts of goodness, including the visualization stuff:
02:14ibdknoxhttps://github.com/ibdknox/pinot
02:17amalloyscottj: just for my vanity, what function were you looking for in amalloy-utils?
02:18ibdknoxamalloy: the one that spits out my entire program... I can't seem to find it in there though.
02:18amalloyibdknox: lazy-loop is usually pretty close, in my experience
02:19ibdknoxhaha
02:21scottjamalloy: actually I misremembered I was looking for readable dates
02:25amalloyah, excellent. now i'll be moderately humble for at least a week or two
02:27scottjanyone else keep a directory of clojure project they don't use around just for grepping through when wondering about an idiom or util?
06:41marmshi
06:41marmsif I use gen-class to extend a Java class, is it possible to access private fields of the super class ?
06:43marmsoh dear I just discovered the exposes-method arg
06:43marmsnevermind
06:47tsdhWhy does (let [^java.awt.Image i (java.awt.image.BufferedImage. 10 10 java.awt.image.BufferedImage/TYPE_INT_RGB)] (.getHeight i)) give a warning that getHeight cannot be resolved? BufferedImage is a subclass of Image...
06:50tsdhAnd, yes, I know that I can omit the hint in the example. My real use is something is (let [^java.awt.Image (.getImage myImageIcon)] (.getHeight i)).
06:54tsdhAnd how do I import a nested class in a ns? :import (foo.bar Baz.InnerBaz) doesn't do the trick...
06:56tsdhAh, Baz$InnerBaz. :-)
06:56khaliGhm i'd like to launch fleetdb at the start of my clojure app. is there a nice way to do this?
07:35McOmghallcould someone provide info on constructing a lazy string from a reader without using line-seq?
07:36McOmghallthat function seems to fail when I use it for composing a huge webpage from URL
08:07McOmghallnoone?
08:08raekMcOmghall: how does it fail?
08:09McOmghallraek: java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn (repl-1:2)
08:10McOmghallwith this code:
08:10McOmghall(defn fetch-url [url]
08:10McOmghall "Retrieves the web page specified by the url."
08:10McOmghall (with-open [the-stream (.openStream (java.net.URL. url))]
08:10McOmghall (let [reader (new BufferedReader (new InputStreamReader the-stream))]
08:10McOmghall (repeatedly (str (.read reader))))))
08:10McOmghallwhen I try to take the ``first'' or any seq operator on the result
08:11raekthere are multiple things I would like to comment on:
08:11raekrepeatedly takes a function, so you need to write something like (repeatedly #(str (.read reader)))
08:12raekrepeatedly is lazy, so the .read calls will happen outside the scope of with-open
08:12raekthat can be solved by wrapping the repeatedly call with doall
08:13raeka lot of the code can be simplified by using clojure.java.io
08:13raek(with-open [reader (io/reader (io/to-url url))] ...)
08:14raekbut one inmportant question is what unit of data do you want to read? lines? bytes?
08:14raekcharacters?
08:15McOmghallit must be bytes or characters because of 2 reasons
08:16McOmghallthe web page I try to fetch is very big, so a line analysis is not really adequate
08:16McOmghalland I am writing a parser for it, so it is more easily done with a character stream
08:18McOmghallline-seq doesn't work because, I think, the page lasts too much on being loaded
08:19raekanyway, if you want a lazy sequence of characters of the stream, I recommend something like (defn char-seq [reader] (lazy-seq (let [x (.read reader)] (when-not (neg? x) (cons (char x) (char-seq reader))))))
08:20McOmghallok, thanks raek
08:20raek(defn do-stuff [url] (with-open [reader (-> url io/to-url io/reader)] (do-stuff-with-lazy-seq (char-seq reader))))
08:20McOmghalli'll try that
08:21raeklaziness and with-open does not really mix well, so I believe that trying to encapsulate them together is not going to work
08:22raekwhat do you mean by "lasts too much on being loaded"?
08:22raekchar-seq does pretty much what line-seq does, but with .read instead of .readLine
08:22McOmghalli've worked a previous version with line-seq and printed the results
08:23mprenticec.c.zip-filter.xml/xml-> is a function, not a macro like ->. that threw me off for a while.
08:23McOmghallthe last element of the sequence was not the last element of the page
08:24McOmghallso I thought it was because it was not fully loaded when the lazy sequence was created
08:24raekwas the page chopped off at the end?
08:24McOmghallyes
08:24raekit might be possible that the server closed the connection before the client consumed the whole thing
08:25raekMcOmghall: does wrapping the line-seq call in a doall make any difference?
08:25raek(warning: that will load the whole page into memory)
08:27raekMcOmghall: I think you shoould investigate exactly where the problem is before abandoning line-seq and/or laziness.
08:27McOmghallyeah, I need lazyness because the page is too big to have a copy in-memory
08:28raek(also: if the server closes the connection before reaching the end of the file, I would expect something to throw an exception)
08:28raekso to repeat: gather more information on what actually happens
08:30McOmghallthank you, this was useful
08:30McOmghalli'll investigate
08:41timvisherhey all
08:41timvisherdoes anyone know how to make ring send utf-8 encoded documents?
08:42timvisheri.e. setting the Content-Type on the response?
08:44raektimvisher: ring will send the data encoded in UTF-8, but you have to include a Content-Type header with the charset parameter set to UTF-8
08:45raek{:status 200, :headers {"Content-Type" "text/html; charset=UTF-8"}, :body "<blink>Hello Web!</blink>"}
08:45timvisherraek: I'm trying to avoid having to create a response map every time
08:45timvisherbut that is certainly an option. :)
08:45timvisherring.middleware.content-type
08:45timvisheralso found that
08:45raektimvisher: what do you mean? in ring you always have an response map
08:45raekyes, you can use function to factor out common code, as usual... :-)
08:46timvisheri'm sorry, i'm using ring through compojure
08:46timvishercompojure at least guesses a good response map from your data
08:46timvisheror you can return one manually
08:46timvishertrue true re using a function
08:46raekI usually make a html-response function that takes a body and returns the map the way I want it
08:48timvisherdo you use compojure?
08:48raekI prefer Moustache myself, but I have used compojure too
08:50raekwith moustache I tend to write each handler as a separate defn and then use the moustache app macro to dispatch them
08:54timvisherthanks for the pointer
08:54timvisherthat works, even if it's not exactly what I was hoping for
08:54timvisherthanks
08:55robbe-How should I interpret errors like
08:55robbe-java.lang.NullPointerException (NO_SOURCE_FILE:0)
08:56robbe-When the file loaded allright, it seems.
09:17dnolenrobbe-: it almost always mean the file did not load right.
09:19robbe-Wel, it did. :-)
09:19robbe-Error goes away if I uncomment the line causing the error.
09:42robbe-I've traced it back to (.hashCode nil) by the way.
09:43raekrobbe-: if you call (require 'your-ns :reload), do you get an exception directly, or only when you call something from that namespace?
09:50robbe-Only when I called the function, ultimately to calling what I described above.
09:51robbe-I suppose the answer to my original question is "generally, you're probably doing something with nil while you shouldn't - or file didn't properly load." - At least that's how I interpret it now.
09:51dnolenrobbe-: sorry it wasn't clear to me when the error was happening, or what you mean by the "file loaded". yes, null pointer exceptions don't give line numbers.
09:51dnolennot sure why.
09:52robbe-It wasn't all really clear for me either, leading me to asking rather unclear questions probably. ;-)
09:53dnolenrobbe-: actually that's not true, they do give line numbers, but not if the code error happens during compilation.
09:56robbe-That's odd, it was during runtime and I didn't get a line number.
09:56robbe-Furtermore, that line was executed once, before being executed with nil.
09:57robbe-Furthermore*
10:03raekrobbe-: but you should be able to see the line number of the function where it happens in the stack trace, right?
10:03robbe-There's no stack trace.
10:04raekrobbe-: what do you mean? are you using an IDE or a bare REPL in a terminal?
10:04robbe-http://pastebin.com/CBxCGSdB
10:05raekrobbe-: call (.printStackTrace *e) to get the stack trace in a bare REPL
10:06robbe-Ah, now that's a good one to know.
10:06robbe-I was hating clojure for throwing me errors and not saying where they come from.
10:06robbe-:)
10:07robbe-Also (completely unrelated) there seems to be somthing wrong with my awk print command there. :P
10:09raekyeah, the bare REPL is a bit akward to develop in...
10:09robbe-(There, forgot that $ has to be escaped in the makefile.)
10:10robbe-Any recommended IDEs for Clojure for a vim enthousiast?
10:10robbe-I also irrationally hate eclipse.
10:10robbe-Just saying.
10:10robbe-:P
10:11gtrakemacs
10:11MasseRrobbe-: vim
10:11gtrakthere's a vimclojure
10:11tsdhI'm toying around with chouser's lazy qsort for The Joy of Clojure, but using it, I get an StackOverflowError. http://pastebin.com/MxrBHRRx
10:11MasseRAnd slimv
10:11robbe-Well, I still have the bare REPL thing to fight with then. :P
10:12raekI know that people are using vim for clojure dev, and that there exists something similar to what slime/swank does in emacs, but not much more than that
10:12MasseRrobbe-: slimv handles that for you (in theory)
10:12MasseRI use it mainly for paredit
10:12tsdhCould someone check if it works with clojure 1.2? (I'm using a 1.3 snapshot...)
10:12robbe-I'll google slimv then. Thanks for the tip.
10:13gtrakis there a decent guide to refactoring? moving function defs around, etc..?
10:15coopernurserobbe-: I always suggest IntelliJ. zero tooling issues since I switched to it from slime
10:16gtrakdoes intellij do good leiningen integration
10:17sjlrobbe-: I use SLIMV with a few files from VimClojure and rarely deal with the REPL
10:17sjlrobbe-: I mostly use <localleader>ee to just veal the top-level form I'm in. Quick and painless.
10:18sjl*eval
10:26zoldarhello, I have a java interop problem. I'm defining a bunch or records based on interfaces defined in java. After compilation record's methods have proper type hints in java IDE. However, constructor still has Object arg0, Object arg*.. as arguments - is there any way to expose type hints for java env? Or is some sort of factory interface the only way to go ?
10:27gtrak`Object arg0 etc.. is not a typing issue, eclipse uses the source of the interfaces to name the args, you'd have to output source code for it to know what to do
10:27gtrak`maybe the 'Object' part is a typing issue
10:30zoldargtrak`, so, how could I expose that information to eclipse/other java ide?
10:30st3fanhow would i translate python's if foo in ('cheese', 'bacon') to clojure?
10:30gtrak`some kind of plugin that uses a clojure AST
10:30st3fani now have (if (or (= ..) (= ...))) but i an wondering if there is a shortcut
10:30sjlst3fan: (if (#{"cheese" "bacon"} foo) …)
10:31st3fanhm nice
10:31sjlst3fan: Yeah, Clojure Sets are functions too.
10:31manutter,(let [foo "cheese"] (if (#{"cheese" "bacon"} foo) :contains-fat :fat-free)
10:31clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
10:31manutter,(let [foo "cheese"] (if (#{"cheese" "bacon"} foo) :contains-fat :fat-free))
10:31clojurebot:contains-fat
10:32zoldargtrak`, a plugin for IDE? I guess I will stick to some kind of factory then...
10:32gtrak`zoldar, or maybe the opposite, write some clojure that outputs java source for ide's to pick up
10:33gtrak`or just forget java
10:33gtrak`;-)
10:33zoldargtrak`, not an option unfortunately
10:33zoldarbut thanks for pointers anyway
10:35gtrak`private constructor and a factory method solves the problem? then that's easiest
10:45zoldargtrak`, but you intrigued me with clojure writing java - do you mean that I would explicitly output some java source code to files which would be later compiled?
10:45gtrak`you could, yea, say with stringtemplate or something
10:46zoldarthat's an idea..
10:46gtrak`just another layer of abstraction
10:47gtrak`but there might be a simpler way, I haven't had to deal with that stuff really
11:11irrumator_anyone work with kawa (a scheme on the jvm) here before? can you compare it to clojure?
11:12irrumator_kawa: http://www.gnu.org/s/kawa/
11:13duck1123Ok, I've never really figured this part out. What do I need to do if c.t.logging isn't showing the right namespace?
11:14duck1123I have one project where it's working right, but then another where all I get is clojure.tools.logging$eval129$fn__130
11:33stuartsierraduck1123: It's probably an issue of when c.t.logging is resolving *ns*, e.g. at macroexpansion time.
11:36upwardindexIs there some kind of style guide for clojure code?
11:37triyo_I have cljs code spread over multiple modules. When I run a cljs.closure/build I get a `nth not supported on this type: PersistentArrayMap`. If I move all the code `as is` in to a single module, all works fine. Seems strange
11:37manuttertriyo_: sounds like a syntax error in a :use or :require clause
11:39duck1123stuartsierra: would that be because I have a macro that does logging? If I moved the logging call to an internal fn, would that fix this?
11:39stuartsierrapossible
11:40triyo_manutter: hmm, doesn't seem like it. (ns blog.validation.form (:require [blog.validation.preds :as preds] [blog.validation.core :as core]))
11:40stuartsierraA macro probably shouldn't log directly, though it may expand to code which does logging.
11:40duck1123that's what I meant
11:41triyo_If I remove the `:require` though, all works
11:41triyo_so one would think its a syntax error, but it seems well formed.
11:42manuttertriyo_: try extra square brackets around the whole list: (:require[[blog.validation.preds :as preds][blog.validation.core :as core]]))
11:42duck1123I have a "spy" macro that logs the code and pprints the data https://github.com/duck1123/ciste/blob/master/src/main/clojure/ciste/debug.clj
11:42triyo_manutter: Assert failed: Only [lib.ns :as alias] form supported (and alias (= :as as))
11:43manuttertriyo_: hmm, never mind then :/
11:43triyo_manutter: this is clojure script btw
11:43triyo_*clojurescript
11:44manutterdoh, missed the "cljs"
11:44triyo_thought so :)
11:44manuttersome day I'll break down and visit the eye doctor again
11:45triyo_I think it might be a bug. I'll have a look at the source and issue db
12:04TimMc,(-> " foo" (.trim) (.length))
12:04clojurebot4
12:04TimMcOh, Java.
12:05manutterwow, really?
12:05jarel,(.trim "foo")
12:05clojurebot"foo"
12:05manutter,(macroexpand '(-> "foo" (.trim) (.length))
12:05clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
12:06manutter,(macroexpand '(-> "foo" (.trim) (.length)))
12:06clojurebot(. (clojure.core/-> "foo" (.trim)) length)
12:06TimMcmanutter: It's a nbsp
12:06manutterAh
12:06manutter,(macroexpand-all '(-> "foo" (.trim) (.length))
12:06clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
12:06manutter,(macroexpand-all '(-> "foo" (.trim) (.length)))
12:06clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: macroexpand-all in this context, compiling:(NO_SOURCE_PATH:0)>
12:06manutterI should just give up.
12:06TimMcIs clojurebot shitting itself again?
12:07TimMc,(macroexpand '(-> "foo" (.trim) (.length)))
12:07clojurebot(. (clojure.core/-> "foo" (.trim)) length)
12:07jarel,(.length "foo")
12:07clojurebot3
12:07jarelhuh
12:08TimMc,(macroexpand `(-> "foo" (.trim) (.length)))
12:08clojurebot(. (clojure.core/-> "foo" (.trim)) length)
12:09scgilardi~botsnack
12:09clojurebotThanks, but I prefer chocolate
12:09TimMc,(-> "\u00a0foo" (.trim) (.length)) ; to be clear
12:09clojurebot4
12:09jareloic
12:09TimMcApparently, String.trim is not to be trusted.
12:09hiredmanstop calling .length
12:10hiredmanuse count
12:10jarelhttp://en.wikipedia.org/wiki/Nbsp
12:10manutterTimMc: but if it's a non-breaking space, isn't the correct behavior to treat it like a non-space?
12:10TimMchiredman: Ah, right.
12:10TimMcmanutter: It's whitespace.
12:11TimMcActually, I just found a good discussion of this: http://closingbraces.net/2008/11/11/javastringtrim/
12:11manutterok, I can see that, since comma is also whitespace (in clojure)
12:12TimMcWhat does that have to do with trimming?
12:14manutternothing really, just thinking out loud about the difference between "visible appearance" and "should be trimmed" (or ignored)
12:14manuttercarry on. :)
12:15robbe-I like how Clojure internally translates '!' to 'BANG'. :-)
12:20coopernursehey folks. I'm using noir with hiccup to build up some html
12:20coopernurseand I'd like to make part of my response conditional
12:20fbru02hey all... stupid question.. where did clojure.contrib.string end up going after the contrib split??
12:20lazybotfbru02: What are you, crazy? Of course not!
12:21fbru02lazybot: snack
12:21coopernurseso, for example: [:tr [:th "Ballot name"] [:th "Vote"] [:th "View Results"] [:th "Edit"] [:th "Delete"] ]
12:21manutterlol, good one lazybot
12:21coopernurseI'd like to make the last two [:th ] elements conditional based on a variable
12:21manutterisn't it just clojure.string now?
12:21coopernurseis there a simple way to inline that expression?
12:21coopernurseconcat perhaps?
12:21fbru02manutter: didn't know that , let me check
12:22arohnercoopernurse: if
12:22coopernursearohner: yeah, I've been fiddling with if
12:22arohner(if foo [:th "Edit"] [:th "Delete"])
12:22coopernursebut I don't have the syntax right
12:23arohnerhow so?
12:23manutter,(let [x [:tr (if true [:th "Vote"]) ]] x)
12:23clojurebot[:tr [:th "Vote"]]
12:23TimMc,[:tr (if true [:th "Vote"]) ]
12:24clojurebot[:tr [:th "Vote"]]
12:24TimMc,[:tr (if false [:th "Vote"]) ]
12:24clojurebot[:tr nil]
12:24manutterhmm, wonder how hiccup renders [:tr nil]
12:24coopernursemanutter: good question
12:24coopernursethis is a good start.. I'll try these
12:24arohnerhiccup ignores nils
12:25arohnerthat would become <tr /> or <tr></tr>
12:25arohnerdepending on whether it's a self-closing tag
12:25TimMcAnyway, use when instead of if.
12:25duck1123aside from setting a ref and then reading it later, is there any good way to make my function return the results of my try block when a finally is in use?
12:26manutter,(let [x [:tr (when false [:td])]] x)
12:26clojurebot[:tr nil]
12:26TimMcmanutter: What's with the let?
12:26coopernurse,[:tr [:th "Ballot name"] [:th "Vote"] [:th "View Results"] (if true [:th "Edit"] [:th "Delete"]) ]
12:26clojurebot[:tr [:th "Ballot name"] [:th "Vote"] [:th "View Results"] [:th "Edit"]]
12:26coopernurseso [:th "Delete"] is ignored, as that's the "else" value
12:27manutterTimMc: wasn't sure if clojurebot understood ,[ or not
12:27TimMc,"hi"
12:27clojurebot"hi"
12:27manuttercool :)
12:27TimMcYeah, it just goes for it.
12:27TimMc, so if you accidentally start with a comma...
12:27clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: so in this context, compiling:(NO_SOURCE_PATH:0)>
12:28arohnerduck1123: you could use an atom in a let
12:28coopernursehow do I destructure this list? (concat) and (cons) don't seem to do it
12:28coopernurse,[:tr [:th "Ballot name"] [:th "Vote"] [:th "View Results"] (if true (concat [:th "Edit"] [:th "Delete"])) ]
12:28clojurebot[:tr [:th "Ballot name"] [:th "Vote"] [:th "View Results"] (:th "Edit" :th "Delete")]
12:28arohner(let [result (atom nil)] (try (swap! result (constantly body))) (finally blah) @result)
12:28hiredmanduck1123: what?
12:29hiredmana finally doesn't change the result of an expression
12:29duck1123arohner: I guess you're right, atom would be better for this. Just wondering if there was something I was misiing
12:29hiredman,(try 1 (finally 2))
12:29clojurebothiredman: Titim gan éirí ort.
12:29hiredmanclojurebot: what?
12:29clojurebotwhat is wrong with you
12:29TimMchaha
12:29hiredmanoh, right
12:29TimMcIs try disallowed?
12:30TimMcduck1123: hiredman's example returns 1
12:30manuttercoopernurse: you don't need the concat, just put the [:th "Edit"] directly, as the "then" clause of your if statement.
12:31coopernursemanutter: but I want both edit and delete if the case is true
12:31duck1123ok, it seems I was going down the wrong path here. I wasn't getting the result I expected. I now see why
12:31manuttercoopernurse: oh ah, just a sec
12:31coopernursethis works, but is silly
12:31coopernurse,[:tr [:th "Ballot name"] [:th "Vote"] [:th "View Results"] (if true [:th "Edit"] nil) (if true [:th "Delete"] nil) ]
12:31clojurebot[:tr [:th "Ballot name"] [:th "Vote"] [:th "View Results"] [:th "Edit"] ...]
12:31hiredmanduck1123: (finally ...) is the closest thing clojure has to a statement, it has no result
12:33manutter,[:tr [:th "Ballot"][:th "Vote"] (when true [:th "Edit"] [:th "Delete"])]
12:33clojurebot[:tr [:th "Ballot"] [:th "Vote"] [:th "Delete"]]
12:33manuttercoopernurse: ^^^
12:33tufflaxthat didnt work manutter
12:33duck1123manutter: wrap them in a list
12:33arohneryou need a (list) in there
12:33coopernursemanutter: hmm.. what happened to edit?
12:33manutteroh wait, miscounted
12:33TimMcmanutter: when returns the last expression's value
12:34manutterYeah
12:34tufflaxI think duck1123 is right, a list is what you need
12:34tufflaxthat's how prxml works at least
12:35coopernurseyeah, just not sure how to clobber the list container that wraps around it when I do this
12:35duck1123just don't be tempted to try to use a vector. That causes problems
12:35coopernurse,[:tr [:th "Ballot"][:th "Vote"] (when true (list [:th "Edit"] [:th "Delete"]))]
12:35clojurebot[:tr [:th "Ballot"] [:th "Vote"] ([:th "Edit"] [:th "Delete"])]
12:36fbru02manutter: thank that worked
12:36arohnercoopernurse: the ([]) is fine, hiccup ignores it
12:36coopernurseoh really?
12:36coopernurselemme try that
12:36manutterheh, at least I got one thing right today
12:36arohnermanutter: that's better than most people :-)
12:37coopernursearohner: ah, so it does. thank you!
12:37manutterWait, no wonder, it's Friday the 26th -- that's TWICE Friday the 13th! Augh!
12:39TimMca.k.a. FridayFriday the 13th :-P
12:39duck1123double friday all the way
12:46grioshello, I'm new on clojure and I'm studying compojure's code. I cannot understand how file-path is evaluated in this function: http://pastebin.com/EAFn859D Any hint?
12:49bsteubergrios: well it must have been defined before
12:49bsteuberor what do you mean "how it is evaluated"?
12:51griosit is not defined before (imho): https://github.com/weavejester/compojure/blob/master/src/compojure/route.clj
12:51griosi cannot understand why it works :)
12:51coopernursegrios: it's scoped in by the use block. it comes from ring.middleware.file-info
12:52coopernursegrios: oops.. I'm wrong.. one sec
12:52coopernursebut I think it's one of the libs in the use block
12:52duck1123I wasn't able to find it
12:53coopernursehmm me either
12:54raekgrios: if you have a repl with compojure ready, you can find out with (in-ns 'compojure.route) (resolve 'file-path)
12:54bsteuberthat's weird indeed :)
12:54coopernursejust did it..
12:54griosraek: compojure.test.route=> (in-ns 'compojure.route) (resolve 'file-path) #<Namespace compojure.route> nil
12:54coopernursenil
12:54griosops
12:54grioswait...
12:55raekgrios: ah, now I see it. it's not a var, it's part of a destructuring form
12:55raek{{file-path :*} :route-params}
12:55grioswhat?
12:55clojurebotwhat is short for ,(doc ...)
12:56bsteuberlol
12:56raekif there is a map like {:route-params {:* <foo>}}, file-path will be bound to <foo>
12:56bsteubersilly me
12:56bsteuberoverlooked the let
12:56raek,(let [{{file-path :*} :route-params} {:route-params {:* "/mystery"}}] file-path)
12:56clojurebot"/mystery"
12:57coopernurseheh, nice
12:57bsteuberah not that silly, it's hidden in the get
12:58griosah okay, thank you raek; I spent my two hours without success, now I know why :)
12:59griosso , let [{{file-path :*} :route-params} {:route-params {:* "/mystery"}}] file-path) < === > {:route-params {:* <foo>}}
13:01raekit has two parts. the right side is a map value (like the one you wrote to the right of < === >) and the left side is a destructuring form to "reach into" the map and bind a value in it to the symbol "file-path"
13:02mattmitchell_How do I insert a value to a list, at a specific position?
13:02raekgrios: (let [{{file-path :*} :route-params} {:route-params {:* "/mystery"}}] ...) = (let [{file-path :*} {:* "/mystery"}] ...) = (let [file-path "/mystery"] ...)
13:03raekmattmitchell_: (concat left-half [element] right-half)
13:03mattmitchell_raek: OK simple enough, thanks
13:04griosraek: ok; but the let is after the destructuring form, isn'it?
13:04arohnermattmitchell: there's not a direct way to do it because it can't be done efficiently on that datastructure
13:04griosI'm looking here: http://pastebin.com/EAFn859D
13:05raekgrios: the GET macro expands into, among other things, another let form
13:05mattmitchell_arohner: ok so nothing like (insert-aftert 2 '(0 1 3) 1) => '(0 1 2 3) etc.?
13:06arohnermattmitchell_: you can write that, but it will require something that looks like raek's suggestion, with a take and a drop
13:06mattmitchell_err, that example is messed up but you know what i mean :)
13:06mattmitchell_arohner: ok cool
13:06griosraek: ah ok, compile-route calls in the last let-request
13:07raekgrios: when you write (GET ...path... foo ...body...) it will become something like (... (let [foo ...request-map...] ... ...body... ...) ...)
13:07griosok
13:07TimMcmanutter: Looks like whitespace recognition in Java is best accomplished this way: [\p{javaWhitespace}\p{Zs}]+
13:07griosdo you have discovered it expanding macros?
13:07raekgrios: you can run macroexpand or macroexpand-1 on the code to see what it expands to
13:08raek,(macroexpand-1 '(if-let [x y] z))
13:08clojurebot(clojure.core/if-let [x y] z nil)
13:08raek,(macroexpand '(if-let [x y] z))
13:08clojurebot(let* [temp__3723__auto__ y] (if temp__3723__auto__ (clojure.core/let [x temp__3723__auto__] z) nil))
13:10griosthanks raek
13:10manutterTImMc: I'll have to bookmark that...
13:10manutternow, where's the "Save Bookmark" command in irc...?
13:11raekgrios: it's possible that the destructuring happens in something else than a let, though. function parameters support destructuring too, for example.
13:13griosreak: "file-path" example works because GET is a macro; if it would be a function it had not worked, correct?
13:13raekgrios: exactly
13:14raekmacros are powerful (and trickyto read!) because the change the rules of evaluation
13:14griosI can see :)
13:14griosokay, I'm feeling enough smart, and I can go home
13:14griosbye
13:14griosand thank you
13:19di-csuehsI feel an approaching enlightment....or at least a learning experience...just need help getting over the edge.
13:22di-csuehsI'm using an API which uses the the with- idiom, but by the time my function calls the api's function which refers to the configuration var, it is unbound.
13:22di-csuehsThis must mean I am not understanding the binding order.
13:22raeklaziness combined with 'binding' often yields this problem
13:34TimMcMan, I would never have thought of that.
13:37di-csuehsunintended laziness...only there is no such thing...it is all supposed to be lazy.
13:39di-csuehsmap returns a lazy sequence...so by the time it gets eval'd, the config var has gone away
13:39raek,(binding [*out* 123] (lazy-seq [*out*]))
13:39clojurebot(#<StringWriter (#<StringWriter >)
13:39hiredmanthat came out odd
13:39iceyHave any of you had good luck with hiring Clojure devs? I'd love to start using it more seriously for a few things, but I don't know anything about how many people out there can write it well, and I would hate to have to rewrite stuff later because I can't find anyone to help maintain / work on it
13:42hiredmanthey are out there
13:43TimMcmanutter: Here's what I ended up writing as a utility: https://gist.github.com/1173941
13:44TimMcConvert to Clojure as needed/desired.
13:44arohnericey: a good place to start is with people already in the clojure community
13:44arohnerbloggers, OSS contributors, etc
13:44technomancyicey: it's pretty good if you can hire remote workers
13:44technomancywe haven't had any trouble finding qualified candidates
13:45technomancyif you limit yourself by locality you put yourself in a much harder place.
13:46iceytechnomancy: yeah, remote would be an option; this is something that's a bit down the road anyways. I guess my biggest worry comes from the fact that a lot of the problem space I work in is pretty boring :)
13:46arohnericey: what is the problem space?
13:47iceyarohner: for what i'm working at the moment - health insurance rate comparisons / rating engines
13:47technomancyusing clojure could be a good way to spice it up a bit
13:48kzarHow do you tell emacs to kill a clojure thread again? C-c C-b I thought but it's not working
13:48arohnerC-c C-c, doesn't always work
13:48arohnerthat kills the repl
13:48iceyclojure is definitely a good fit for the problem space
13:48kzarC-c C-c ran the closest s-exp for me
13:49arohnerin the repl buffer
13:49iceyi've been watching the language for years and it seems amazingly stable for how young it is. now i'm just at the point of having fears related to switching away from one platform (.net) and onto something significantly more exotic (clojure, not the jvm)
13:50TimMcicey: Sounds like an *important* problem space, though -- there's not enough consumer information/empowerment in the insurance market.
13:53iceythere is a lot of domain knowledge required, so i am looking for whatever weapons i can use to increase developer productivity as much as possible
13:54iceyactually, it's not even a domain knowledge problem as much as it is a "every company does shit totally differently" problem :)
13:54TimMchaha
13:54TimMcI can already see that you'll need dynamically scoped binding.
13:55TimMc(with [*company-does-weird-stuff* true] (process-things))
13:56iceymy current solution uses c# and is scriptable with ironpython... i thought i'd be able to take it to the carriers and say "hey here's the api, just fill in the blanks to hook in to this system"; but python was too much of a stretch so we ended up writing all the scripts ourself
13:56iceyi figure if i'm going to write all the guts & gear code then it might as well be in something that provides more flexibility
14:01iceylol, i guess no questions are original; just found a really great thread on the mailinglist that features someone with a lot of my concerns... from 2009 :) (thanks again everyone)
14:04tcepsaWhen defining a namespace with hyphens in it, is it true that you
14:04tcepsashould name the corresponding directories and file with underscores
14:04tcepsawhere the hyphens go?
14:04tcepsae.g. test.record-types would be in test/record_types.clj ?
14:05Vinzenttcepsa, yes
14:06tcepsaOkay, so then if I define some records (using defrecord) in that
14:06tcepsanamespace, what's the correct way to access them from another namespace?
14:07tcepsaBecause test.record-type.TestRecord gives me a "class not found" exception
14:07tcepsaBut test.record_types.TestRecord works
14:07raektcepsa: you need to import the record types like java classes
14:07tcepsaOh! Okay, I'll give that a try
14:08tcepsa(I had been using :use and :require)
14:08raekso, you end up needing both use/require and import...
14:09tcepsaraek: Okay, what should that look like?
14:10raek(ns ... (:require your-ns) (:import your-ns.TheRecordType))
14:12tcepsaraek: Thanks, I'll see if I can get that to work
14:14raekbut it sounds a bit weird that test.record_types.TestRecord worked but not test.record-type.TestRecord
14:14raektcepsa: which clojure version are you running? I vagely recall that something like this was fixed in clojure 1.2.1
14:15raekhttp://dev.clojure.org/jira/browse/CLJ-432
14:16raektcepsa: anyway, it's often simpler to expose a "constructor function" instead
14:17tcepsaraek: Ah, thanks, I'll double check that
14:18raeklooks like test.record_types.TestRecord is the "correct way" in some sense. yuck.
14:18tcepsaraek: Hmmm, okay. That would explain why it's still not working
14:19tcepsaOkay, yeah, if I do
14:19tcepsa(ns ... (:require scratch.record-types) (:import scratch.record_types.Example))
14:19tcepsathen it works
14:20tcepsaBut if I use a dash in the :import then it fails
14:21tcepsa(It looks like I am using version 1.2.1)
14:22tcepsaIs there a way to check the Clojure version from within the REPL?
14:23raek,(clojure-version)
14:23clojurebot"1.3.0-master-SNAPSHOT"
14:23tcepsaThanks, yes, I am using 1.2.1
14:25TimMctcepsa: You had an "s" at the end of record_types, but not record-type. Probably just a transcription typo, but I thought I should mention it.
14:25Vinzenthm, samething here
14:25Vinzent(but not with 1.2.0)
14:26tcepsaTimMc: Good catch! That was a transcription error this time (but would
14:26tcepsahave been very frustrating if it were the actual problem!)
14:28Vinzenthttp://paste.org.ru/?c3yyiv - and in the 1.2.0 defrecord returns foo-bar.Foo. Interesting
14:31tcepsaIs there some way to submit this as an issue?
14:33TimMc&findfn "a-b" "a_b"
14:33TimMc$findfn "a-b" "a_b"
14:35stuartsierratcepsa: In 1.3 defrecords create real constructor functions.
14:36tcepsastuartsierra: Ah, okay, then I'll switch to that. Thanks!
14:36scottjibdknox: have you tested output-to and output-dir on cljs-watch? I tried them last night and they didn't seem to work
14:36ibdknoxscottj: are you using zsh?
14:36scottjibdknox: yes and escaped {
14:37scottjI think I ran it under bash though too to test
14:37scottjcljs-watch src \{:output-to "public/cljs/bootstrap.js" :output-dir "public/cljs/"\}
14:37ibdknoxscottj: it works on bash for me, zsh doesn't get any args at all
14:37ibdknoxever
14:37scottjthat's the line I used, I ended up editing cljs-watch
14:38ibdknoxscottj: I also tried with cljsc and that had the same issue
14:38scottjok I'll retest in bash
14:38ibdknoxyou shouldn't need to escape in bash
14:39sridfyi - we just released a new version of Stackato with support for Clojure; invite codes here - http://www.reddit.com/r/programming/comments/jv8uo/activestate_adds_python_django_support_to/
14:39ibdknoxsrid: congrats
14:40scottjibdknox: might want to ignore .#foo.cljs files (emacs autosaves I think)
14:40ibdknoxhm, I thought I did that
14:40scottjor probably any .foo.cljs
14:40ibdknoxI think I lost one of my commits somewhere
14:41ibdknoxyeah, vim does the same thing
14:41amalloy$findfn "a-b" "a_b"
14:41lazybot[clojure.core/munge clojure.core/namespace-munge]
14:41amalloyTimMc: sorry for the inconvenience, he's back
14:42scottjibdknox: just tried under bash and it doesn't work
14:42ibdknoxhm
14:42ibdknoxbtw
14:42ibdknoxit does ignore . files...
14:43scottjbut still shows exception on them? :: watcher :: Building ClojureScript files in :: src/java.io.FileNotFoundException: The file src/emailatask/cljs/.#frontend.cljs does not exist.
14:44ibdknoxare you sure you have my latest?
14:44Vinzent->MyRecord looks strange
14:45scottj"fix bug that causes bootstrap.js to be created as a dir." latest commit
14:45ibdknoxscottj: k, I can repro the options not taking
14:45scottjthere's no build process to create a new cljs-watch is there? it looked like the script had the source inline
14:46scottjibdknox: gtg
14:47ibdknoxscottj: thanks, I'll get it fixed up
14:49hiredmanVinzent: reads as "to MyRecord"
14:49tcepsastuartsierra: As it stands, I am having the same problem (with
14:49tcepsadefrecord and hyphenated namespaces) in 1.3.0-master-SNAPSHOT as in 1.2.1
14:50Vinzenthiredman, I understand, but still looks strange
14:51cemerickFunny that ->Foo comes up just now. http://dev.clojure.org/jira/browse/CLJ-833
14:52TimMcsrid: The article has a broken link to Stackato
14:52tcepsahttp://pastebin.com/G3yhyjUq
14:53sridTimMc: ah ok, here's the link - http://www.activestate.com/cloud
14:53TimMcYeah, it's just missing a "/" to make it an absolute path.
14:54TimMclooks like it escaped into the last link in your reddit comment
14:55tcepsaNow with more documentation: http://pastebin.com/Mr5atT21
14:55tcepsaDefrecord doesn't play nicely with hyphenated namespaces
14:56VinzentI'm curious why defrecord should create a function? Why not (new-from-map Foo {:a 1}), or something similar?
14:58stuartsierraDunno. It was a long-thought discussion on the dev.clojure.org wiki.
15:07Vinzent(record MyRecord 1 2) and (record-map MyRecord :a 1 :b 2) seems ideal, imo
15:07Vinzent(as described here http://groups.google.com/group/clojure-dev/browse_thread/thread/4a0447939ebed7c4)
15:08cemerickVinzent: record and record-map would have to be macros, and thus couldn't be used with HOFs
15:08hiredmanI've noticed http://dev.clojure.org/display/design/JIRA+workflow doesn't seem to address assigning, should assign issues to yourself?
15:08hiredmancemerick: macros or use reflection
15:09hiredmanboth are distasteful
15:09cemerickRight; neither of which are kosher
15:09Vinzentcemerick, ah, so it's done for speed
15:09arohneris it possible to create a class with several constructors, using gen-class? I have (defn -init ([] (...)) ([foo] ...) ([foo bar] ...)), but (show) only lists the first constructor
15:09cemerickThus, the implicit fn definitions — which I'm not a fan of, but… *shrug*
15:10coopernurseanyone know of a function in ring / compojure / noir that given a relative url returns a full url with host/port/context prepended?
15:10cemerickVinzent: Seems like a reasonable expectation.
15:10arohnercoopernurse: I'm pretty sure that doesn't exist
15:11coopernursearohner: ok.. servlet api has some stuff that can help with that, but a convenience function would be nice
15:11coopernurseooh.. maybe hiccup.core/with-base-url
15:14coopernursehmm, nope
15:15coopernurselooks like that's just a macro that takes the base url
15:15amalloycoopernurse: doesn't java.net.URL do something like that?
15:17coopernurseamalloy: I don't believe so. you need the host/port from the HttpServletRequest
15:21coopernursesomething along these lines. I'll see about porting it. http://www.java2s.com/Code/Java/Servlets/GetRelativeUrlforservlet.htm
15:32LauJensenDo we have any examples of scraping webpages behind logins? ie. negotiating cookies and all that
15:32coopernurseLauJensen: the apache HttpClient lib will automatically store/send cookies. not sure if there's a clojure wrapper for it yet
15:33coopernurseperhaps: http://clojars.org/diamondap/clj-apache-https
15:33LauJensencoopernurse: Excellent, thanks
15:34coopernurseyou bet. docs are at github: https://github.com/rnewman/clj-apache-http
15:34coopernurseor is that a different lib? http vs https. author looks different
15:35coopernursesorry, yeah those two links are different libs
15:35coopernursebut they appear to wrap the same HTTPClient lib under the hood, so both probably do what you need
15:37coopernurseI'm not seeing an obvious way to access the HttpServletRequest in noir.. anyone know if defpage exposes it? or do I have to write middleware
15:51SomelauwWhat would be the best way to implement a datastructure in clojure? I know clojure likes to use dicts for everything, but dicts are slow, you can't overwrite the way that for iterates over them and you can't decide how to should be printed. So I think that would be one of the cases in which you should use genclass.
15:52amalloySomelauw: noooo, not genclass
15:52amalloydeftype please
15:52hiredmangen-class is slow
15:53amalloyreally?
15:53hiredmanyes
15:53stuarthallowayslow/fast doesn't mean much without a requirement
15:53stuarthallowaybut +1 hiredman
15:54hiredman"gen-class just adds another layer of dispatch"
15:54stuarthallowayif you are writing a datastructure, deftype is your friend
15:54amalloySomelauw: https://github.com/flatland/ordered/blob/develop/src/ordered/map.clj is an example of mine, implementing maps that retain insertion order
15:54hiredmandeftype removes one
15:54amalloythe final version is kinda unreadable due to performance optimizations, but you can probably see sorta what's going on?
15:56amalloySomelauw: https://github.com/flatland/ordered/blob/1ed7e95d093c9de74701a7239d7ba04c9f7464d0/src/ordered/set.clj is a less messy implementation of ordered sets
15:59Somelauwamalloy: Thanks, I will look at them.
15:59stuarthallowayanybody here use the clojure maven plugin and have context on http://dev.clojure.org/jira/browse/CLJ-822?
16:05Mike|homeI saw a function that looked like this: (fn [[a b]] [b (+ a b)]) Is the inner [a b] destructuring?
16:05amalloyyes
16:05Bronsayes
16:05Mike|homeRadical.
16:06Bronsai'd say awesome
16:06amalloyMike|home: i smell fibonacci
16:06ibdknoxlol
16:06coopernursethere's a technique noir is using in cookies.clj that I may want to emulate, but I want to make sure I understand what's going on
16:06Mike|homeIndeed, amalloy :)
16:06coopernurselooking at: https://github.com/ibdknox/noir/blob/master/src/noir/cookies.clj
16:06arohneranyone have ideas on why (future (+ 1 1)) would fail, even on in a clean repl session?
16:06coopernursespecifically, I want to make sure I understand (binding ) that happens in noir-cookies
16:07Mike|homeI still feel pretty stupid because I can't do much with Clojure, even though I've been at it for a few weeks. Haha.
16:07ibdknoxcoopernurse: it creates a threadlevel binding
16:07coopernurseibdknox: ok, great. that's what it appears
16:07ibdknoxcoopernurse: which means, in this case, that it will have that value for that specific request
16:07coopernurseso all calls to other cookie funcs by that thread will use those local bindings
16:07ibdknoxcoopernurse: during that request, yes
16:08coopernurseibdknox: that's what I figured - otherwise noir would be broken with concurrency > 1
16:08ibdknoxibdknox: yep :)
16:08ibdknoxlol
16:08ibdknoxI like talking to myself
16:08coopernurseheh
16:08ibdknoxcoopernurse: what are you trying to do?
16:09coopernurseibdknox: well, I'm still puzzling over how to build a full URL based on the current request context
16:09coopernurseso I'm planning on writing a lib that might pull a similar trick
16:09manutterarohner: odd, if I try (future (+ 1 1)) I get java.util.concurrent.RejectedExecutionException
16:09coopernurseuse (binding) to make the request thread local, and expose functions that operate on that binding
16:09ibdknoxcoopernurse: wait, you just want the requested uri?
16:09manutterarohner: is that what you're seeing?
16:09arohnermanutter: yeah
16:10arohner(.isTerminated clojure.lang.Agent/soloExecutor) => true
16:10coopernurseibdknox: no, I want to create an url relative to the base url of the current request
16:10manutterarohner: that's weird, I'm sure I played with future before, without issues.
16:10ibdknoxcoopernurse: by default any url missing the root slash will be relative
16:11arohnermanutter: https://github.com/technomancy/leiningen/issues/265
16:11coopernurseibdknox: so, for example, if the current request is: http://example.com:2913/foo/bar
16:11coopernurseibdknox: and the context root is /foo (which I have no way of knowning in advance)
16:11coopernurseibdknox: and I ask for a relative url of: "/baz", then I expect: http://example.com:2913/foo/baz
16:12Mike|homeAgh. I'm packing to move, but I ran out of boxes.
16:12manutterarohner: ah
16:12Mike|homeBetter start making piles.
16:12ibdknoxI see
16:12coopernurseibdknox: I'm trying to construct the absolute url, without having to know how the WAR was deployed, which the servlet api provides hooks for, but you need the HttpServletRequest
16:12ibdknoxcoopernurse: gotcha. Sounds like that would be reasonable
16:12Bronsauser=> (future (+ 1 1))
16:12Bronsa#<core$future_call$reify__5508@2586b11c: 2>
16:12Bronsauser=> @*1
16:12Bronsa2
16:13coopernurseibdknox: but noir doesn't appear to expose the request, and even if it did, passing it around seems crufty.. so this (binding) trick looks good
16:13Bronsafor me it works
16:13ibdknoxcoopernurse: well, you can easily create a middleware that adds the uri to the params passed to defpage, but I think your solution sounds more robust
16:14amalloycoopernurse: yeah, that's one of the things binding is for. i have a middleware that binds *url* to the uri of the request
16:14hugodstuarthalloway: for adding clojure.test to zi, I ended up writing a macro that used binding in 1.2 and with-redefs in 1.3
16:14coopernurseamalloy: ibdknox: cool, thanks. I will explore. definitely the sort of code you want to make sure you get right, lest wires get crossed
16:14stuarthallowayhugod: the dynamic binding fix is now pushed
16:16ibdknoxstuarthalloway: shot in the dark, but do you happen to know when speakers will get notified for the conj? We want to buy our tickets soon.
16:16amalloy(inc ibdknox)
16:16lazybot⟹ 2
16:17hugodstuarthalloway: thanks
16:17stuarthallowayibdknox: we hope to announce before early bird is over
16:17stuarthallowaybut if we don't ...
16:18amalloythough, ibdknox, i wouldn't be surprised if they could arrange a refund if it turns out you get to speak :P
16:18stuarthalloway(1) anybody who buys now will get refunded if they are a speaker
16:18ibdknoxstuarthalloway: great, that works
16:18mwillhitehey all, brand new to clojure and java…trying to set up my dependencies w/ leiningen, but I'm not sure how to request the correct package: http://pastie.org/2435373
16:19mwillhitestarting with the java.awt stuff, where can I find the resource?
16:19amalloymwillhite: those are all packages included in the jre, so you don't have any special dependencies
16:20mwillhitewell I get this error: Exception in thread "main" java.lang.ClassNotFoundException: quote.(java.awt AWTException Robot Rectangle Toolkit) (core.clj:1)
16:20mwillhiteso maybe one of those don't actually exist…
16:20mwillhiteobviously I'm just copying and pasting code here…
16:21amalloythey should exist, and they do when i try it. are you sure what you pasted is your actual code?
16:21mwillhiteyep
16:21mwillhiteweird…
16:21coopernursemwillhite: what JDK are you using, and what OS?
16:22mwillhiteI'm on Lion
16:22mwillhitenot sure how to find the JDK
16:22amalloycoopernurse: i doubt it matters. the exception indicates his clojure syntax is broken, not anything class-related
16:22niko22when using emacs/slime i get a "byte-code: Failed to download Clojure jars" - any suggestions?
16:23amalloymwillhite: there are two many close parens at the end of your import. this makes me strongly suspect that your actual code is (ns (import ...))
16:24mwillhiteit is…
16:24mwillhitelet me paste the entire file
16:24mwillhiteits small
16:24amalloyugh. that's why i asked you if you pasted your actual code
16:24mwillhiteI deeply apologize
16:24amalloywhat you pasted would be correct in isolation; being wrapped in (ns) slightly alters the meaning
16:24coopernursemwillhite: yeah, you could start a REPL and just try: (import '(java.awt AWTException Robot Rectangle Toolkit))
16:25mwillhitehttp://pastie.org/2435398
16:25mwillhiteah, so my whole code should be wrapped in the namespace
16:25amalloyyou want more like (ns (:import (java.awt AWTException ...) (java.awt.image ...)))
16:25mwillhiteyeah that makes sense
16:25mwillhiteException in thread "main" java.lang.IllegalArgumentException: Parameter declaration quote should be a vector (core.clj:1)
16:25amalloythis is a confusing distinction, i'm aware. basicalle, (import) is a function, so needs its arguments quoted. (ns) is a macro, which doesn't need quoting
16:26tcepsamwillhite: Not your whole code; only the imports should be in the
16:26tcepsans form.
16:26amalloyand it uses :import instead of import to clarify the difference
16:26mwillhiteoh
16:27mwillhiteokay, so updating to the syntax amalloy suggested gets it to compile
16:27lancepantzamalloy: hi
16:27mwillhitethanks people
16:27tcepsaSweet
16:31mwillhitegiven the code in this pastie: http://pastie.org/2435398
16:31mwillhiteshouldn't I be able to do this from the repl:
16:31mwillhite(screen-grab "screen.jpg")
16:32tcepsamwillhite: You need to be in the correct namespace in the REPL
16:32coopernursemwillhite: you need to namespace qualify it, or use (in-ns) to switch to the screencap.core ns
16:32mwillhiteI'm using the lein repl…
16:32coopernurseso this should work: (screencap.core/screen-grab "screen.jpg")
16:32mwillhiteI thought that put me in the right namespace
16:32mwillhiteokay
16:32coopernurseif the prompt says: user=>
16:32coopernursethen you're in the user namespace, which is the default
16:32mwillhiteit does
16:33mwillhiteoh right okay
16:33coopernurseif you do this: (in-ns 'screencap.core)
16:33coopernursethen the prompt will change
16:33mwillhitescreencap.core=> (screen-grab "screen.jpg")
16:33mwillhitejava.lang.Exception: Unable to resolve symbol: screen-grab in this context (NO_SOURCE_FILE:6)
16:34coopernursehave you loaded the file into the repl?
16:34mwillhitewhats interesting too, is when I tried the first method (from user=>) including the namescape, it said it couldn't find the namespace
16:34mwillhiteI just typed 'lein repl' from the project root
16:34coopernurseah
16:34coopernursetry: (load-file "yourfile.clj")
16:35tcepsaWhat's the path (including filename) of that file?
16:35tcepsa(It has to be in a specific location relative to your project
16:35tcepsaroot for lein repl to find it and load it for you)
16:35coopernurseright, so absolute path is best for now
16:36tcepsaShould be in src/screencap/core.clj
16:36mwillhite/Users/mwillhite/apps/clojure_hacks/screencap/core.clj
16:36coopernurseyeah, pass that to load-file
16:36mwillhiteI was digging into clojure a few months back and I never had to load my file before, maybe thats new?
16:36mwillhitewill try
16:37mwillhitegetting a file not found exception
16:37tcepsaWhat coopernurse suggested should work. To get it to load
16:37tcepsaautomatically, you need to put your screencap directory in a directory
16:37tcepsanamed src
16:37mwillhite(load-file "/Users/mwillhite/apps/clojure_hacks/screencap/core.clj")
16:37mwillhiteoh I missed a dir
16:38mwillhitek, got it loaded…
16:38coopernursegreat, so you should be able to call screen-grab now
16:38mwillhitewell that seemed to work…not sure where it put my file tho :P
16:38mwillhiteoh, same dir
16:39coopernursenice
16:40mwillhiteI have to say, I've always been super impressed by the help received from this channel (and the seemingly inifinite patience), thank you so much for helping me out
16:40coopernursemwillhite: totally welcome.. happy to have a question I actually can answer
16:40mwillhite:)
16:40coopernurseyeah, I found the tooling a little hard to wrap my head around at first
16:41coopernursebut once you learn the basic handful of tricks to eval files and whatnot, then it's a very productive platform imho
16:41mwillhiteyeah, especially having been completely immersed in javascript and ruby for the past 5 months…my clojure mind has withered a bit
16:42mwillhiteI'm really excited about learning it, just need to find the right application so my employer will let me do it during the day
16:42coopernurseyeah, I have to keep a doc in evernote for each lang/platform I use to remind me of the incantations like these
16:42coopernurseheh, yeah I know what you mean
16:43ordnungswidriganybody using emacs from emacsformacosx.com? I have problems with german keyboard and keybindings
16:43mwillhiteI need to start documenting the tricks as I learn, I think that will help a lot
16:44coopernursemwillhite: yeah, I'm inconsistent with it. I found using something like evernote, where you don't have to think about naming a file, you can just paste stuff in and organize it later, has helped
16:44coopernursemwillhite: anything to eliminate any barriers to taking notes
16:44mwillhiteyeah totally, I'm a fan of evernote…thanks again for your help
16:44coopernurseyou bet
16:44coopernursehave fun
16:45tcepsaamalloy: Same here!
16:47hiredmanwe had a sonian meetup, where it was discovered one of my cowokers has an org-mode were he lists the topics and his agreement/disagreement with another coworker, so we he is accurately able to say "I agree with so-and-so 40% of the time"
16:47ibdknoxlol
16:48tcepsaNice!
16:48technomancyneeds a web frontend though. http://iagreewithdanlarkin.com
16:49technomancyyou could get achievement badges, etc.
16:49hiredmanit needs some kind of crowd sourcing statistical backing, so you just answer a few questions and it gives you a good guess at your agreement percentage with danlarkin
16:49danlarkinoh boy
16:50danlarkinwhat is this I don't even
16:52scottjcemerick: both your theories apply to me, I had no clue about ->Blah and it definitely didn't look like a constructor to me, I thought of threading too.
16:52cemerickdamn, fogus is never around when I have an opportunity to gloat! ;-)
16:53cemerickscottj: I've no doubt some docs will get in, eventually. Hopefully for 1.3.0, but we'll see how that goes.
16:57iceyDo people lean one way or the other on clojureql vs clojure.contrib.sql?
16:58stuartsierracemerick: I'll gloat for you the next time I see him.
16:59cemerickstuartsierra: ha, much obliged.
16:59stuartsierra'later.
16:59scottjicey: both are used quite a bit, I don't have a large enough sample to say one is more popular than the other
16:59amalloyicey: hasn't c.c.sql been put down in favor of c.j.jdbc?
16:59iceyamalloy: entirely possible; i'm a noob :)
17:00iceyscottj: good enough for me, thanks... just making sure i'm not looking at using a solution that nobody uses or has flaws that i haven't found in google yet
17:10kzarIs there a function you can use a predicate that just returns the argument? I want to use not-any?, watching out for non-nil values
17:11scottjkzar: example of inputs and output?
17:12raekkzar: identity
17:12kzarraek: aha thanks
17:14amalloykzar: though (every? nil? xs) seems clearer for your actual goal
17:14kzaramalloy: oh yea, good point
17:27coopernurseok, this appears to work for concurrency=1. but if someone has a moment to check my use of (binding) here I would be grateful. https://gist.github.com/1174475
17:29amalloycoopernurse: the semantics are the same, but i'd use declare instead of def
17:30coopernurseamalloy: thanks, changing..
17:30zoldarI have a defrecord refering to vars (functions, atoms etc.) in the same namespace. When I aot compile the namespace and try to use the record class in java code, it ends up with "Var some.ns/some-var is unbound" pointing to a reference to that var in the defrecord. What may I be missing?
17:31amalloyanyway, you certainly don't have any binding-related problems
17:32amalloyi'd write your port test as (when-not (#{80 443} port) (str ":" port))
17:32coopernurseamalloy: love it, thanks
17:33amalloythough i guess that could cause silent failure if, say, port is an int and 80 is a long. though i think that's fixed in 1.3
17:33coopernurseooh
17:33coopernurselet me try that
17:34coopernursegetPort() is an int
17:34coopernurseliteral numbers are ints right, depending on their size?
17:34coopernurse,(type 80)
17:34clojurebotjava.lang.Long
17:34coopernurseoh
17:34coopernursein my repl is says Integer
17:35amalloycoopernurse: right, that changed in 1.3
17:35coopernurseok, interesting
17:35amalloy&(class 90)
17:35lazybot⇒ java.lang.Integer
17:36amalloy&*clojure-version*
17:36lazybot⇒ {:major 1, :minor 2, :incremental 0, :qualifier ""}
17:36amalloy,*clojure-version*
17:36clojurebot{:interim true, :major 1, :minor 3, :incremental 0, :qualifier "master"}
17:36coopernurseah, good to know
17:37coopernurseso = tests will work between int and long, but not set membership
17:37amalloyright
17:37coopernurseis that a bug or feature?
17:37hiredmanthe hoops you have to jump through to get a boxed integer in 1.3 are kind of a drag
17:38hiredmanI mean, maybe it's good for performance, but if a java method requires an Integer you have to do something like (Integer/valueOf (int 10))
17:38coopernurseyeah, that particular case is very subtle
17:39hiredmanthat is one word you could use to describe it
17:39amalloyhaha
17:39coopernurseso is that how 1.3 is going to stay? or is there talk of changing it?
17:39amalloy,(Integer. (int 10))
17:40clojurebot10
17:40amalloyhiredman: that's simpler, at least?
17:40dnolenhiredman: eh? (Integer. 10) works
17:40amalloy,(Integer. 10)
17:40clojurebot10
17:40dnolen,(type (Integer. 10)
17:40clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading>
17:40dnolen,(type (Integer. 10))
17:40clojurebotjava.lang.Integer
17:40hiredmanah, no kinding
17:41hiredman"autoboxing, unless you're an int or float"
17:43hiredmanwhat really through me was (int 10) was throwing an exception
17:43hiredman(Long cannot be cast to Integer or something)
17:47dnolenhiredman: ? I haven't seen anything like that.
17:50hiredman,(type (int 10))
17:50clojurebotjava.lang.Long
17:51hiredmanyou cannot pass that to a method that takes an Integer
17:51zoldarI've put together the minimal example describing my problem: http://pastebin.com/P4C3FxXM
17:52hiredmanyou need to load the namespace from java
17:52paul__hey, I'm trying to apply a function with side effects to a collection, that also updates the collection, and (dorun (map (fn... dosnt seem to be working
17:52paul__any ideas?
17:52hiredman,(doc dorun)
17:52clojurebot"([coll] [n coll]); When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. dorun can be used to force any effects. Walks through the successive nexts of the seq, does not retain the head and returns nil."
17:52hiredman^- "returns nil."
17:53hiredman,(doc doall)
17:53clojurebot"([coll] [n coll]); When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. doall can be used to force any effects. Walks through the successive nexts of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time."
17:53paul__ah, Ill try that
17:53paul__thanks
17:54paul__OK, it looks like that'll work
18:07chewbrancaanyone have any recommendations for coercing a String to an InputStream?
18:08chewbrancabasically I'm trying to save an attachment to a couchdb document, the method in clutch I'm using expects either a File or an InputStream, but I need to save from a string, and created a temporary file on the disk just seems like a bad way to accomplish it
18:09chewbrancas/created/creating/
18:09lazybot<chewbranca> basically I'm trying to save an attachment to a couchdb document, the method in clutch I'm using expects either a File or an InputStream, but I need to save from a string, and creating a temporary file on the disk just seems like a bad way to accomplish it
18:09manutterTry (StringReader. the-str)
18:09manutterhmm, that's probably not sufficient
18:09coopernurse(ByteArrayInputStream. (.getBytes the-str))
18:10chewbrancamanutter: yeah actually tried that but didn't work
18:10manutterdoh, I was just about to say that
18:10manuttermy google-fu is too slow
18:12chewbrancacoopernurse: excellent! thanks that did the trick
18:12coopernursechewbranca: sweet
18:13amalloyyou should really make sure you write it with the character encoding you intend to
18:13coopernurseamalloy: heh, was just writing that
18:13ordnungswidrigI just thought of that
18:13coopernurse(ByteArrayInputStream. (.getBytes the-str "utf-8"))
18:13coopernursefor example
18:14chewbrancaok cool, thanks, adding that in
18:15chewbrancaalso, what's the clojure idiomatic way of naming conversion functions? right now I'm going with string-to-input-stream
18:15amalloymeh
18:16amalloythere are people who will like that, or will like str->input-stream. i like stream-from-string, personally
18:17chewbrancaamalloy: ok, so more of a style preference, I'm not a huge fan of string-to-input-stream
18:34scottjhow about input-stream?
18:35scottjand use protocols or multimethods
18:35amalloyscottj: clojure.java.io already does that
18:37scottjchewbranca: so I think the idiomatic way is just it after the result type
18:43chewbrancascottj: I tried using input stream but it treats the string as a file path, rather than a raw string. ByteArrayInputStream is working well though
18:45tomojinput-stream should accept a byte array
18:45tomojlike (input-stream (.getBytes "foo"))
18:51chewbrancatomoj: ahhh nice, that's a bit cleaner that directly using ByteArrayInputStream
19:10justicefriesclojure is absolutely ruining ruby for me.
19:11tomoj:D
19:11technomancyjusticefries: yeah, there needs to be a warning label for that
19:11justicefriesyeah....
19:12justicefriesthink I'm okay with it. ;)
19:12justicefriesthe one thing I'm not sure of, and maybe this is because I just haven't done it...
19:12justicefriesbut how it fares organizationally against large codebases a la Rails.
19:15scottjjusticefries: I think the conventions aren't there so each project is going to look different, it's up to your to organize them well
19:16justicefriesah sure.
19:55SomelauwHi, does anyone remember the command to shutdown cake?
20:01SomelauwNevermind, I already killed it using top.
20:04amalloycake kill
20:07SomelauwThat works
21:26tnksI don't know Clojure at all, but a friend was curious if Clojure had a currrying facility.
21:27amalloywell. because it has first-class functions, it is possible to curry. but it doesn't happen automatically like in haskell
21:27hiredmansort of depends what you mean by that
21:27tnksor maybe a more appropriate question is "how does Clojure solve problems other languages would use currying or partial eval to solve?"
21:27amalloy(instead, it allows functions to have a variable number of arguments)
21:27danlarkinit doesn't have currying like haskell has currying
21:27hiredmanbut sure you can create functions that are the partial application of another function
21:27hiredman,((partial + 1) 2)
21:27clojurebot3
21:28tnksawesome.
21:28tnkspartial is really half the battle.
21:28tnksI'm going to send him here.
21:28hiredmana lot of people just function literals
21:28hiredman,(#(+ 1 %) 2) ; this sort of thing
21:28clojurebot3
21:29hiredmanpartial is prettier though
21:29dnolenred-black tree balance checking, https://gist.github.com/1174834 (yes I know, syntax needs to improve, working on it)
21:29tnksyeah, I'm not sure how to parse the latter.
21:29amalloydebatable. partial is more elegant, i think, but neither is pretty
21:29tnkswhat's the "%"?⇧
21:30amalloy&'#(inc %)
21:30lazybot⇒ (fn* [p1__12654#] (inc p1__12654#))
21:30amalloy&(#(inc %) 2)
21:30lazybot⇒ 3
21:30hiredman,'#(+ % 1)
21:30clojurebot(fn* [p1__10191#] (+ p1__10191# 1))
21:30hiredman% is the argument
21:31hiredmanamalloy: "prettier"
21:31hiredmanpartial also doesn't generate more classes
21:31tnksokay, this feels very similar to the _ partial eval Scala has.
21:32tnkswhere % feels like _
21:39dnolenwill probably let vector patterns take [], and seqs will match with ([] :seq).
21:45amalloyaw, hiredman, generating more classes is fun! who doesn't love classnames like sandbox10558$eval12677$foo__12678$fn__12679$bar__12680?
22:34mbacis there an unless primitive in clojure?
22:34amalloy&(doc when-not)
22:34lazybot⇒ "Macro ([test & body]); Evaluates test. If logical false, evaluates body in an implicit do."
22:35mbaccool!
22:36amalloymbac: of course, it's easy to write your own
22:37mbacsure
23:17dnolengotta love open source, https://gist.github.com/1174909
23:26sridis it possible to register custom type convertors for clojure's json library? at the minimum, i want to convert timestamp number in the JSON to java.sql.Timestamp objects automatically.
23:27technomancysrid: clojure has lots of json libs.
23:27technomancycheshire allows that
23:27technomancyas does clojure-json
23:28sridi am using org.clojure/data.json, but I can switch to one of those
23:28technomancyoh, hm... well, it allows for customization on encoding. I don't know about decoding.
23:34sridwhenever I add a new dependency via `lein install` or `lein deps`, is it mandatory to kill *slime-repl* and do clojure-jack-in again? all of this takes time. jvm is slow
23:35sridhow about jambojure?
23:35technomancylupus yonderboy
23:36sridit appears i can't use (use ...) alone in the repl. it must be wrapped in (ns foo ...). that sucks
23:36hiredmanI decided I wanted a persistent map as a service, running on my laptop to be available for other little bits of code (like my irc->sqs notifcation stuff)
23:36hiredmansrid: you need to quote the form
23:37hiredman,(use 'clojure.zip)
23:37clojurebotWARNING: next already refers to: #'clojure.core/next in namespace: sandbox, being replaced by: #'clojure.zip/next
23:37clojurebotWARNING: replace already refers to: #'clojure.core/replace in namespace: sandbox, being replaced by: #'clojure.zip/replace
23:37clojurebotWARNING: remove already refers to: #'clojure.core/remove in namespace: sandbox, being replaced by: #'clojure.zip/remove
23:37clojurebotnil
23:37sridright, thanks
23:37hiredmanwhoops, that must have broke a lot of things
23:37technomancyclojurebot: ABORT, ABORT
23:38clojurebotNo entiendo
23:38sridchesire doesn't see to have custom decoders (only encoders)
23:39hiredmanso I wrote this thing on top of infinispan that I can run via launchd to provide persistent key/value storage
23:39technomancysrid: update-in?
23:39hiredmanand I need a name for it
23:39technomancyhiredman: army-of-one?
23:40hiredmanah!
23:40hiredmanentrepot
23:40technomancybecause seriously, do you have a data center under your desk?
23:41hiredmanno? that would be ridiculous...
23:42hiredmanit's totally sweet, I store a map of irc nicks to email addresses in entrepot so now my sqs thing can use gravatars
23:42amalloydnolen: that's more like a bean than a pojo, fwiw
23:42dnolenamalloy: forgive my total Java ignorance, how so?
23:43sridtechnomancy: (update-in foo [1 :last_updated] f) <- here update-it only updates index 1, so i need to it multiple times passing 2 3 etc... I suppose.
23:43sridcall it*
23:43technomancysrid: sure; a combination of map and update-in, I guess
23:43amalloydnolen: well, pojo is Plain Old Java Object: conforms to no special specifications or conventions. beans were introduced so that property inspectors could manipuate properties by calling conventional get/set/is methods
23:45dnolenamalloy: open to better names, tho clearly this is not really a bean a either.
23:45amalloyand there's a reasonably well-tested camelCase->dash-case function at https://github.com/flatland/useful/blob/develop/src/useful/string.clj
23:45amalloyfeel free to steal it
23:46amalloytechnomancy: hey, i have a CA and i wrote that
23:46amalloyi think. *checks blame*
23:47technomancybut your CA only covers contributions to clojure and contrib!!1eleven
23:47amalloythat's probably true. funny if it weren't so sad :P
23:48dnolenamalloy: thx, sent it along to darevay.
23:48srid(map (fn [q] (update-in q [:creation_date] #(Timestamp. %))) json)
23:48sridbeauty.
23:51amalloypretty cool, though, dnolen
23:51amalloy`(. ~this ~(symbol n)) should probably be `(. ~this (~(symbol n)))
23:52amalloybut i guess since this isn't your code i won't bother you with it :)
23:52dnolenamalloy: always feel free to send corrections via pull requests :)
23:53amalloydnolen: i sure will. let me know when you add this to match and i'll have a look then
23:54dnolenamalloy: that'd be great. will do.