#clojure logs

2011-04-11

00:03amalloymec: clojure-mode does that already
00:04meci mean for your lazy-loop too
00:04amalloymec: aha! funny you should ask. when i wrote lazy-loop i added a customizable variable to clojure-mode for just that reason
00:05amalloytry M-x customize-variable clojure-defun-indents. if it doesn't exist, you need a newer version of clojure-mode
00:05mecnope, i've got an old one
00:06amalloyit's only been around for like two weeks, so that's unsurprising
00:24mec,(clojure.lang.PersistentQueue. nil 0 nil nil)
00:24clojurebotjava.lang.IllegalArgumentException: No matching ctor found for class clojure.lang.PersistentQueue
00:24mechow come it says that even though thats exaclty how EMPTY is defined
00:25amalloymec: either (a) the constructor is non-public, or (b) you're wrong about EMPTY being defined that way
00:26mecah ya it isnt public
00:26amalloymec: anyway i doubt the new versions of clojure-mode are in elpa, but you can pull from github and customize indentation to your heart's content
00:26mecnight
03:22tsdhDoes anyone have a link to one of the various alternative definitions of `all' and `any' which are equivalent to reducing `and' / `or' through a sequence, just with short-cirquit behavior?
03:35angermantsdh: stackoverflow has some: http://stackoverflow.com/questions/5531964/non-macro-versions-of-clojure-and-and-or
03:40tsdhangerman: Great, thanks. Oh, and is seems that they've already hit clojure.core as `any-pred' and `every-pred' (in 1.3).
03:43mreynoldsI have a vector [0 1 2 3 4 5] and I want to loop through the vector, pulling off pairs of numbers. I'm wracking my brain, is there a way to do this?
03:50raekmreynolds: which pairs are you interested in? (0 1) (1 2) (2 3) ...?
03:50Totramonmreynolds: what do you mean with pairs
03:50Totramonheh, that
03:50mreynoldsI'd like to have [0 1] [2 3], etc
03:50mreynoldsReally, I want to map them to variables and use them
03:50TotramonI think partition does this
03:50mreynolds[key type], etc
03:51mreynoldsLooking
03:51raek,(partition 2 [0 1 2 3 4 5])
03:51clojurebot((0 1) (2 3) (4 5))
03:51Totramoninto {} (partition..
03:51mreynoldshah!
03:51mreynoldsThank you so much
03:51mreynoldsI've spent far to long looking for that.
03:51Totramon:)
03:52Totramonnevermind that into, was thinking of something different
03:52mreynoldsno worries, thanks so much!
03:52raek,(->> (range 6) (partition 2) (map vec) (into {}))
03:52clojurebot{0 1, 2 3, 4 5}
03:53raek,(->> (range 6) (partition 2) (into {}))
03:53clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.Map$Entry
03:53ejacksonMorning, Clojurati.
03:53raekarbitrary dequences do not work as map entries...
03:53raek*sequences
03:54Totramonmust have been with 2-element vectors only then
03:54Totramonthanks
03:55Totramonis that ->> considered good style btw?
03:55Totramonfirst time I saw it
03:57mreynoldsThanks all, night
03:57raekI personally think that it maybe makes that code snippet a bit easier to read (but certainly simpler to write on multiple lines) than just (into {} (map vec (partition 2 (range 6))))
03:59raekbut maybe the gain is larger for ->, since without that one the nested expressions tend to "split" the outer ones in half and separate the halves from each other
04:17markomanis there a way to change "string-key" to :string-key ?
04:19markomanor ":string-key" to :string-key as well
04:26markoman,(symbol (str ":" "key"))
04:26clojurebot:key
04:29markomanbut its not same?
04:29markoman,(= :key (symbol (str ":" "key")))
04:29clojurebotfalse
04:34raekmarkoman: ##(keyword "string-key")
04:34sexpbot⟹ :string-key
04:35raekmarkoman: symbols and keywords are different things...
04:35raekbut clojure does currently allow you to construct symbols starting with a : (which is not recommended to do, as you can see)
04:36markomani see
04:36raekalso:
04:36raek,(doc clojure.walk/stringify-keys)
04:37clojurebot"([m]); Recursively transforms all map keys from keywords to strings."
04:38markomangood to know. so there are symbols, names and keywords. something else?
04:38raekwhat are names?
04:38markomanoh, i think of (name :string-key)
04:39raek'name' is a function that takes a symbol, keyword or (since 1.2) a string and returns a string
04:40raek,(map name [:foo 'foo "foo"])
04:40clojurebot("foo" "foo" "foo")
04:40raek,(map class [:foo 'foo "foo"])
04:40clojurebot(clojure.lang.Keyword clojure.lang.Symbol java.lang.String)
04:41raekthe atomic data types in clojure are: numbers (various kinds), nil, booleans, strings, characters, regexes, symbols and keywords
04:42AWizzArdraek: atomic data types?
04:42AWizzArdThose sound like literals.
04:43raekas in, non-compound
04:43AWizzArdBut Strings seem to be collections of chars.
04:43raekor non-aggregate
04:44raekwell, the string "foo" is distinct from [\f \o \o] and (\f \o \o)
04:45raekok, atomic in the sense "indivisible" might be slightly inaccurate here
04:47markomanok. fair enough to start with. then my next step is to find keys from map like {:key1 {} :key2 {} ...} -> [key1 key2 ...]. I can map keyword, but how to collect keywords only from first map?
04:48markomanloops and iterations are still something im not familiar with clojure
04:48raekmarkoman: you want to do something for each key-value pair?
04:49markomanno, just to get string presentation of keys in list
04:49markomanactually resut would be ["key1" "key2" ... ]
04:50raekterminology: key = whay you look up from when using a map; keyword = a kind of value
04:50raek,(map name (keys {:a 1, :b 2}))
04:50clojurebot("a" "b")
04:51markoman:key = keyword key?
04:51raeka keyword used as a key, yes
04:51morphling,(keyword "key")
04:51clojurebot:key
04:52markomanright.
04:53raekmarkoman: regarding loops and iterations: in functional programming it makes more sense to think of what you want the resulting value to look like, rather than the mechanism for how to do something for each thing
04:54raek{"this is a string used as a key" "this is a string used as a value", :keyword-key :keyword-value, 'symbol-key 'symbol-value}
04:56markomanyeah, the result is what im interested at the end. i can already see most things can be done with map what im used to do with foreach
05:17markomanhmh... I have (def default-data {}) and I want to use it on other namespace but copy it, using as a template, not modify
05:18markomansimilar to: (:require default-data :as-copy data)
05:20raekif you want to access it using another name, you can do this (:use [the-ns :only [default-data] :rename {default-data some-other-name}])
05:20raekthen, 'some-other-name' will be the name for that var in the namespace
05:21markomanand I can modify some other name and it wont change original default data?
05:21raekalso, vars (the things def make) are made to be constant
05:21markomanah, I see
05:21raekyou should only change the root value of a var when fixing bugs
05:22raekin this case, changing the value of #the-ns/default-data affects the other namespace too
05:23raek(where some-other-name is the name for #the-ns/default-data)
05:23raeksorry, it should have been #'foo, not #foo
05:26markomandoes this mean :rename makes a copy of default data and when im changing renames map, it doesnt change original?
05:27raekno, no copies are made
05:27raekyou simply introduce an alias to the var
05:28raekhowever, there is no "simple" way of setting a var in another namespace
05:28markomanok. but Im going to need to alter the map on different namespaces. id like to use original as a template only
05:29raekyou can use (alter-var-root ..), but it takes the var object itself, rather the name of it
05:31raekthen, I'd suggest doing something like (ns the-second-ns (:use [the-ns :only [default-data]])) (def data (assoc default-data ...))
05:31markomanhow about using atoms in this case?
05:32raekin what namespace is the changable thing going to live?
05:32raekan atom would be good, since then you are explicit about what can change
05:33raek(in constrast to vars, which are supposed to not change, but can be anyway for fixes)
05:37markomanin qtypes ns I have: (def default-qtype-data {:create (fn [args]) :show (fn [args])}) and qtypes.checkbox ns I want to use default, but probably change :show function only. having a few default templates would reduce duplicate coding
05:39markomanso Im thinking to (def data <- default-data) and then alter :show part
05:39raekthen (:use [qtypes :only [default-data]]) to get access to the defaults, and then build the new map with (def data (assoc default-data :show (fn ...)))
05:40raekdon't alter.
05:40raekit's more ideomatic to construct the complete value, and then bind that
05:40markomanthe return of assoc, it contains all defaullt-data, not only :show part?
05:41raekyes
05:41raekand it doesn't change the original (since datastructures are immutable)
05:41raek,(assoc {:a 1, :b 2, :c 3} :b :something-else)
05:41clojurebot{:a 1, :b :something-else, :c 3}
05:42raekin the beginning, it might be easier to think of def as "assign once only"
05:43markomanthen its perfect. but of course, there are a lot of other parts too that changes. so after I make assoc :show, is there a problem I make again (def data (assoc data :list ...)
05:43clojurebot'Sea, mhuise.
05:43raekyou can "update" multiple keys with assoc
05:44raek(def data (assoc default-data :show ..., :list ..., :foo ...))
05:44markomanbecause at the end, when Im using checkbox/data it should contain final composition based on default-data
05:44raekyou should do all the composing inside one def form
05:45raekand clojure provides many functions for making these kind of things easy
05:45raekyou can also make helper funktions if the expression become too big
05:46markomanok, then its just structuring parts clearly
05:48markomanI think this is enough for now, thanks :)
06:18fliebelWhat happens when I do ##(recur) at the top level?
06:18sexpbotExecution Timed Out!
06:18fliebelI think any repl does that in a thread, so that would recur to that callable.
06:32GeoffSKi am having some fnparse (beginner) problems, can anyone help with http://pastebin.com/ex9BbFZ1
06:34GeoffSKready to run version: http://pastebin.com/dvA2yQig
06:46no_mindis there a trie implementation in clojure ?
06:49fliebelno_mind: I don't know, but you might be able to bend the rules of a finger-tree to do that.
07:29no_mindone question which has to do more with lisp than clojure per se. When should I use macro instead of a function ?
07:32ogonzalezno_mind, I'm a complete newbie but maybe when you want to alter evaluation order, alter normal language semantics in a concrete part of your program, generate some boilerplate...
07:32fliebelno_mind: When you need to define new syntax. Macroes are magic, so reserve them for magic. Do the real work with functions.
07:33no_mindthnxs fliebel
07:34raek(inc fliebel)
07:47TimMcno_mind: Remember, you can still define DSLs using functions.
08:08raek"Domain Specific Values"
08:14raekhow widely accepted is the foo->bar naming convention?
09:28TimMcraek: I use that all the time, including <-foo and ->bar multimethods. :-P
09:29TimMc s/<-foo and //
11:05amacanyone know of a good contrib.error-kit usage example?
11:26carllercheIs there a way to use defrecord w/ a one off protocol instead of defining the protocol separately?
11:37dnolencarllerche: nope.
11:43carllerchednolen: this is kind of what i'm trying to do, what would be the idiomatic way to do it? https://gist.github.com/3be71ab4c67754f522e8
11:43dnolencallerche: looks fine, but you have to define a protocol.
11:44dnolencallerche: it's only 2 more lines of code, so it's not exactly tedious :)
11:45carllerchei guess if i really cared, i could make a macro
11:46amalloycarllerche: i don't understand the goal. why would you want to define a protocol that nobody has access to?
11:46carllercheamalloy: the goal is that I will need api-key and host in every single function to talk w/ campfire, so i'm trying to avoid code to extract that information from every function
11:47carllerchei'm sure there is a much better way to do this :P
11:48amalloycarllerche: (defmulti get-api-credentials [url] host-identifying-function)?
11:49amalloysince all you really want is a flexible way to get credentials
11:50carllerchehow would I use it?
11:50carllerchealso, i'm thinking that (defn configure ) might be able to return a function that does the actual HTTP requests
11:50amalloywell, write a host-identifying-function that looks at a url like "www.campfire.com" and says, "oho, that's campfire"
11:51amalloythen (defmethod get-api-credentials ["campfire"] (GET whatever))
11:52amalloyseems a lot cleaner than creating a bunch of actually-unrelated Record classes that happen to have similar behavior
11:52carllercheah... hmmm
12:26mabesis it possible to set a static field onto record classes? I would like to manually set serialVersionUID to avoid some [de]serialization issues I'm running into (adding a field to the record, etc..)
12:52amalloymabes: i don't think so; is it feasible to use clojure's pr-str and and read for serialization, instead of java's?
12:54mabesamalloy: not in this case.. records don't support prn-str serialzation natively (although you can add that like defrecord2 does), but the bigger issue is that these records contain java objects. So, I'm already living in java land. :(
12:54amalloyalas
13:03angermanwow. QT takes ages to compile
13:03angerman(trying to compile phantomjs)
13:03RaynesYou haven't compiled until you've compiled GHC.
13:04angermanRaynes: that might be, I guess I just went with haskell platform.
13:05ejacksonRaynes: pish, you haven't compiled till you've completed LFS.
13:07technomancyepihpany is the most terrifying thing I've ever compiled. it depends on a full mozilla build, a full GNOME build, *and* webkit.
13:08ejackson:)
13:08angermanthis is so rediculous. It should at least detect that I'm on os x and use webkit as a drop-in replacement :/
13:08angermanQT feels viral on each encouter :(
13:23amac,(get {:a 1} :a (/ 1 0))
13:23clojurebotjava.lang.ArithmeticException: Divide by zero
13:24amacis there a lazy form of get that doesn't evaluate the default unless needed?
13:26lazy1,(or (:a {:a 1}) (/ 1 0))
13:26clojurebot1
13:26lazy1or does short-circuit
13:26amacaaaaaaaaaah, perfect
13:33raek,(if-let [[_ v] (find {:a 1} :a)] v (/ 1 0))
13:33clojurebot1
13:33raekamac: ^ in case you need to be "nil transparent"
13:34lazy1,(:a nil)
13:34clojurebotnil
13:34lazy1keywords are nil transparent as well
13:35lazy1The other way around will throw -> (nil :a)
13:59carllercheis it possible to get readline(ish) support in the emacs clojure repl?
14:10raeklazy1: my idea when I used the word "nil transparent" was that a nil value doesn't count as no value
14:11raek,(or (:a {:a 1}) (/ 1 0))
14:11clojurebot1
14:11raek,(or ({nil 1} nil) (/ 1 0))
14:11clojurebot1
14:12raekhrm. nevermind :)
14:12ataggart,(or ({:a nil} :a) (/ 1 0))
14:12clojurebotjava.lang.ArithmeticException: Divide by zero
14:12ataggartis what I think you meant
14:12raekthat's right
14:23TimMcOK, I'm writing a ray tracer, and I'd like to have multiple threads tossing pixels into a BufferedImage as I repeatedly repaint it to the canvas.
14:24TimMcSince BufferedImage is ultimately backed by an array, is it safe to write to it from multiple threads simultaneously?
14:25ohpauleezTimMc: sure, using it in ref
14:26TimMcohpauleez: What do refs have to do with it?
14:26TimMcThis is a Java array.
14:28ohpauleezTimMc: You're writing the ray tracer in Clojure, that is multithreaded and you want the threads to update BufferedImage concurrently
14:28ohpauleezI don't know if BufferedImage is thread-safe
14:29ohpauleezso I was suggesting you use a ref and dosync, to do the concurrent updates from the threads
14:29TimMcBleh, too much overhead.
14:30TimMcWhat I want to know is whether it is thread-safe, given that each thread will be writing to its own set of pixels.
14:31TimMcIf it isn't thread-safe I'll use getWritableTile or something.
14:31ohpauleezTimMc: might be useful: http://stackoverflow.com/questions/2857332/safe-to-update-separate-regions-of-a-bufferedimage-in-separate-threads
14:32cemerickTimMc: Rasters are basically arrays; Image subclasses have graphics contexts associated with accelerations pipelines and all sorts of other dark magic that varies from platform to platform. I wouldn't touch the latter from multiple threads.
14:33TimMcbrb
14:34cemerickFWIW, you can easily get a WritableRaster, blit to that from N threads without a problem, then create a BufferedImage from the completed result.
14:38TimMccemerick: BufferedImage has a getWritableRaster -- that's what I would use.
14:38TimMcWhat the hell, I'll just WriteSomeDamnCode.
14:39TimMcAs for the Clojure side of things... what should I use for the 4 or so worker threads?
14:41ohpauleezTimMc: Futures, perhaps?
14:41ohpauleezor just use threads
14:41TimMcI've never worked with futures or agents, so I don't have a feel yet for their use patterns.
14:42ohpauleezif all you need are threads, Futures are appropriate
14:48phenom_I'm getting some significant thread blocking when running code that uses multimethods .. any ideas on how I can change around my code to avoid this?
14:50cemerickphenom_: it's pretty unlikely that multimethods are the cause, unless you are modifying them constantly
15:35spewnI wonder if the Irssi users in this channel might find this useful: https://github.com/0/irssi-rainbow-parens
15:47TimMcWell, futures seem to work just fine.
15:49rumboldhi. i'm new to clojure. what are some ides with good clojure support?
15:50nickikthe big java ones + emacs + vim
15:50ohpauleezTimMc: Glad to hear it!
15:50rumboldi started learning emacs a bit, but im not sure if i really want to
15:51TimMcrumbold: I learned Emacs to work with Clojure -- it was worth the learning curve.
15:51TimMc(Third time I tried. :-P)
15:51ataggartrumbold: what IDEs are you familiar with?
15:51TimMcohpauleez: Now I have progressive rendering in my ray tracer!
15:51rumboldvisual studio mostly :p
15:51ohpauleezTimMc: Nice!
15:51rumboldwhat's prograssive rendering?
15:51rumbold*e
15:52TimMcrumbold: Instead of rendering the whole scene off-screen and then dumping the whole thing into a window when it is done, I'm updating the canvas line by line.
15:53rumboldah
15:53rumboldwhy not pixel by pixel?
15:53TimMcI'm rendering the scene pixel by pixel into a BufferedImage, then repainting the entire BufferedImage onto the canvas several times per second.
15:54TimMcIt ends up being more or less chunk by chunk, really.
15:54rumboldah
15:54TimMchttps://github.com/timmc/CS4300-hw6/tree/master/src/hw6
15:55rumboldi wanna write a little game in clojure. what are some good libraries for that? ill probably use penumbra for graphics, i guess. might need something for physics. although it might be simple enough to just write it myself
15:55TimMc^ core.clj does all the threads and GUI stuff, tracer.clj actually handles rendering.
15:57TimMcI should actually start writing the usage instructions soon. >_<
15:58rumboldwhat does ^ do?
15:58rumboldsome kinda java reference?
15:59mduerksenrumbold: yes, it's a type hint
15:59ohpauleezrumbold: It's used to type hint and also to attach metadata to something
16:00ohpauleezrumbold: Type hints are used in Java interop and when you compile your class
16:02rumboldis clojurebox a good choice?
16:02rumboldoh the website doesnt even work anymore
16:04jweissi see there's no dissoc-in - is there a simple way to implement?
16:07ohpauleezjweiss: (dissoc m :a :d)
16:07ohpauleezgiven something like: (def m {:a 1 :b {:c 3 :d 4}})
16:07ohpauleezshould work
16:07jweisshm that is not how i interpreted the doc but will try
16:08jweiss,(dissoc {:a 1 :b {:c 3 :d 4}} :a :d)
16:08clojurebot{:b {:c 3, :d 4}}
16:08jweisshm no
16:08ohpauleezohhh nvm, I think you're right, I was misunderstanding
16:09ataggartjweiss: you weren't the only one
16:09ataggarthmm, no it seems it doesn't
16:10ataggartmt
16:10ohpauleezjweiss: http://clojuredocs.org/clojure_contrib/clojure.contrib.core/dissoc-in
16:11choffsteinhey all! is there a good library for sending e-mails (like Ruby's ActionMailer)?
16:11jweissohpauleez: ah thanks, never woulda thought to look in contrib since update-in and assoc-in are in core
16:12ohpauleezchoffstein: Take a look at clj-mail
16:12choffsteinthanks :)
16:12ohpauleezchoffstein: Welcome: https://github.com/MayDaniel/Clj-Mail
16:12choffsteinthat's perfect!
16:12ohpauleezno idea if that's what you need
16:12ohpauleezawesome
16:16amalloyjweiss: it's easy to do with update-in: ##(update-in {:a {:b {:c 1}}} [:a :b] dissoc :c)
16:16sexpbot⟹ {:a {:b {}}}
16:18drewrchoffstein: I'm biased, but I prefer http://github.com/drewr/postal for sending
16:18jweissamalloy: ahh duh. from the doc it sounded like it can only update the value, but you just went one key higher up the structure :)
16:18choffsteinjust a bit biased, eh? ;) Thanks, i'll check it out too
16:19ohpauleezamalloy: ah right, that's better
16:19ohpauleezI actually have used that befor
16:20drewrchoffstein: sane defaults, sends via sendmail or smtp, in production use at an email company, etc.
16:20amalloyi'm surprised dissoc-in isn't implemented using update-in
16:20ohpauleezI am too actually
16:20ohpauleezand why it's using a hard recursion call like that
16:20amalloymaybe it doesn't work for a top-level key
16:20amalloy&(update-in {:a 1} [] dissoc :a)
16:20sexpbot⟹ {nil nil, :a 1}
16:21ohpauleezgood thinking
16:25mecanyone else get an error trying to run the astar function from Joy of Clojure?
16:28amalloy~source update-in
16:28clojurebot#<IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: replaceAl for class java.lang.String>
16:28amalloyhiredman: ^?
16:28amalloy$source update-in
16:28sexpbotupdate-in is http://is.gd/DuMg4s
16:29nickikI split up my little webapp into 5 namespaces (from one) now I cant do interactive development anymore. When it was in one namespace I could just recomile and hit F5 know I have to restart the webserver (lein ring server). Anybody knows that problem?
16:42mecim getting an exception that doesnt reference the file the function is in at all, how could i narrow it down?
16:44dnolenmec: what is the exception?
16:45meclazyseq cant be cast to comparable
16:46amalloymec: you have a sorted-{set,map} of lazy-seqs, perhaps?
16:48ohpauleeznickik: Why can't you do interactive development anymore? You just need to reload all the namespaces
16:49mecamalloy: sorted-set, but I wrapped the lazy-seq in a vec and it still happens
16:49nickikohpauleez: I do but it doesn't help
16:53choffsteinis there a way to set the encoding type with hiccup's form-to?
16:53mecdid lazy-seqs implement comparable at some point in the past?
16:53amalloyi doubt it
16:54amalloy(the above to mec, not to choffstein. no idea re choffstein)
16:54amalloymec: how could lazy-seqs implement comparable? they can't even know whether they have any elements
16:55mecits code straight from joy of clojure, im at a loss here
16:59amalloymec: the A* stuff you mentioned earlier?
16:59mecya
16:59mecit looks like the error is coming from (into (sorted-set) (lazy-seq of vectors)) which doesnt make sense
17:01amalloyvectors might implement Comparable by comparing elements pairwise, and if one of them has a lazy-seq as an element...?
17:03mecah thats it
17:18devnIs there a limit on how long a function name can be?
17:19amalloydevn: don't think so
17:19mecdoesnt look like it
17:20amalloyyou can have symbols of at least 10k characters, and functions can be associated with any symbol, so...
17:22devnhow do you figure 10k characters?
17:24wtetzner,(->> (repeat \a) (take 10000) (reduce str) symbol name count)
17:24clojurebot10000
17:26amalloydevn: cause i tried it once
17:26amalloylike that, tahnks wtetzner
17:27Chousukeprefer apply str instead of reduce str though :P
17:27amalloyyeah
17:27mecgets laggy at 10000000 :D
17:28dnolenso noone's done anything involving decision diagrams in Clojure, eh?
17:28amalloydnolen: like finite state machines, or something more vague?
17:29dnolenamalloy: more binary decision diagrams, multi-valued decision diagrams.
17:32dnolenamalloy: not unrelated tho, been looking at how Standard ML aggressively optimizes pattern matching. I've read some implementations use tree automata.
17:32amalloyall a big mystery to me, i'm afraid. i keep meaning to write a less-parser-looking NFA/PDA library
17:33amalloybut tree automata and multi-valued decision diagrams are not in my repertoire
17:34schlechtvIs there an idiomatic way to solve the following problem: partition a seq when the difference between the first and the last elee
17:34schlechtvelement of the partition is greater than or equal to a given value
17:36schlechtvi.e. for a difference value of 4: (1 2 3 4 5 6 7 7 7 7 7 7 9 10) -> ((1 2 3 4 5) (6 7 7 7 7 7 7 9 10))
17:36amalloyinteresting problem. it seems like a combination of iterate and take-while
17:37amalloymaybe iterate and split-with
17:38schlechtvhm, didn"t think about split-with yet... I kind got stuck trying to solve it with partition-by
17:39amalloyschlechtv: i suspect that's a dead end
17:39Chousukesounds a bit tricky
17:39amalloywas my first instinct too but i don't think you can mold it into the right shape for partition-by
17:42amalloy$findfn -4 4
17:42sexpbot[clojure.core/unchecked-negate clojure.core/-]
17:42amalloyugh where is abs
17:42mecMath/abs
17:42schlechtvme neither ... I already hacked away looping through the seq, but it grew uglied by the minute ..
17:42ohpauleezamalloy: ^ (Math/abs is WAY faster than contrib.math)
17:48amalloyschlechtv: gisting up something that seems to work in a sec
17:50amalloyhttps://gist.github.com/8ef871f0d800e6e692db needs to be wrapped up in a function, but that's the logic
17:51schlechtvamalloy, I'm awestruck, trying to even understand how that works
17:53schlechtvamalloy, seems I *will* get some sleep tonite then :-) Thanks a lot!
17:54amalloyschlechtv: i write code like this often enough that i have some tools to make it a little less primitive, but i wanted something that works with no dependencies outside of clojure.core
17:54amalloyschlechtv: welcome
17:55schlechtvamalloy, fair enough ... I need to wrap my head around the clj standard lib first anyway and your solution is great both for its practical and educational benefits :)
17:55amalloyschlechtv: it might well be cleaner to write it directly as a lazy-seq. exercise for the reader
17:56schlechtvwill do!
18:12choffsteinAny idea why I keep losing data when I try to create a file uploading using ring.middleware.multipart-params? The temp file created is correct, but the 'filesize' reported is not.
18:12Glass_Armfaggots
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12Glass_Armd
18:12clojurebotdestructuring is http://clojure.org/special_forms#let
18:12devn...
18:24devnDid that just happen?
18:25ohpauleezWow
18:27amalloyclojurebot: way to show him the door
18:27clojurebotI'm sorry, amalloy. I'm afraid I can't do that.
18:34choffsteinis there a way to slurp in files in binary mode?
18:41technomancyrebinding *out* to *err* is the simplest way to println to stderr, right? (other than invoking methods on *err* directly)
18:41devnchoffstein: clojure.contrib.io.to-byte-array
18:43hiredmantechnomancy: some common things that try to print errors (like printStackTrace) expect a printwriter, and I think *out* isn't always a printwriter
18:45technomancyyeah, I'm thinking just a simple println
18:45technomancyOTOH, the JVM is already so anti-unix maybe it's not worth bothering to make the distinction.
19:39TimMcclojurebot: <3
19:39clojurebot<3 is </3
19:39TimMcclojurebot: You're just playing hard-to-get.
19:39clojurebotI don't understand.
19:44Raynesamalloy: I think that was our first spam.
19:50amalloywhat?
19:50clojurebotWhat is meta
19:51amalloythe guy spamming "d"? we've had spam in here before
19:51amalloyclojurebot: meta?
19:51clojurebot⟹ "Returns the metadata of obj, returns nil if there is no metadata."
19:57WuHoUnited(meta clojurebot)
19:58amalloyclojurebot: meta is meta
19:58clojurebotOk.
20:30semperosbrehaut: ping
20:30brehautsemperos: pong
20:31semperosquestion on ne (what else)
20:31brehautshoot
20:31semperosI have code that throws a custom exception
20:31semperosclass org.openqa.selenium.NoSuchElementException
20:31semperoswhen this gets thrown and returned to the client, the client throws an XML error
20:32semperosAttribute name "org.openqa.selenium.NoSuchElementException:" associated with an element type "NoSuchElementException" must be followed by the ' = ' character.
20:32semperosthoughts?
20:33brehautcan you create a gist or something so i can see the code?
20:33brehautor at least the interaction?
20:33semperoshmm
20:34brehautim pretty certain im not following properly ;)
20:34semperosok
20:34semperosassume I have an XML-RPC method exposed, foobar
20:34semperosclient calls foobar
20:34semperosa function gets call that does nothing but (throw org.openqa.selenium.NoSuchElementException)
20:34semperos*gets called
20:34semperosmissed a paren there, but you get the idea
20:35brehautsure
20:35semperosso I pass back to the client a map
20:35brehautn-e should wrap that in a fault if you dont catch it explicitly (at the level of the endpoint), which should serialize fine
20:35semperosthat's what I thought
20:35semperosbecause I've gotten proper faults along the way
20:36semperosah, furhter up the stacktrace
20:36brehautok
20:36semperosI have:
20:36semperosjava.lang.IllegalArgumentException: No implementation of method: :value-type-elem of protocol: #'necessary-evil.value/ValueTypeElem found for class: clojure.lang.LazySeq
20:37brehautthat would be right :)
20:37brehauti havent provided a serialization for that because it doesnt cleanly map to the xml-rpc types
20:38brehaut(of course, its entirely reasonable that it should have a mapping)
20:38semperosok
20:38semperosso I'll accommodate for it on my end
20:38brehautyup
20:38semperosshould have looked further up the stack in the first place, that error I understood
20:38brehaut(vec my-lazy-seq) should do it
20:38semperosyeah
20:39semperoswhat do you think about nil?
20:39brehautim working on nil
20:39semperosfor :response-elem
20:39semperosI know
20:39semperosrecommendation for the present, for dealing with nil and :response-elem? just ""?
20:39scottjjust to make sure I'm not trying to do something that can't be done, it's possible to have a macro sh2 where (let [a "foo"] (sh2 (ls -l ~a))) => (let [a "foo"] (apply sh ("ls" "-l" a))) right?
20:40brehautsemperos: i think so. some sort of sentinel you arent otherwise using
20:40semperosk
20:40brehautsemperos: alternatively use a wrapper struct
20:40semperosok
20:40semperossorry, I think I keep asking the same questions in different guises
20:40brehautsemperos: its no problem :)
20:41semperosbrehaut: thanks for the help; as always, have to run now, but I appreciate your time
20:41brehautsemperos: later
20:41amalloyscottj: i don't think you can access/modify ~
20:43scottjamalloy: can you help me understand why not? doesn't the reader turn that into (clojure.core/unquote foo) and that's waht the macro gets?
20:43amalloybut if you wanted to use *a instead or something, then it would be possible
20:43amalloyscottj: the reader actually does the unquote before giving anything to your program
20:43amalloy&(read-string "~a")
20:43sexpbot⟹ (clojure.core/unquote a)
20:43amalloyhm
20:44amalloy&(let [x 1] (prn '~x))
20:44sexpbot⟹ (clojure.core/unquote x) nil
20:44amalloy&(macroexpand '(and ~x))
20:44sexpbot⟹ (clojure.core/unquote x)
20:45devnwhat's the state of the art in setting up vim with lein?
20:45devnanyone have a blog post handy?
20:45hiredmanpeople have been talking about writing ` as a macro, but no one has
20:46amalloyscottj: looks like it is possible and i'm a horrible liar. your macro will receive arguments of the form '(unquote x), which you can look for
20:46amalloyand you have access to their lexical vars via &env
20:47amalloyhiredman: you did, didn't you?
20:47amalloydevn: $ alias vim emacs?
20:47hiredmanI started once
20:47technomancydevn: I think there's a nailgun plugin; is that all it needs?
20:48scottjamalloy: maybe that's where my problem was, do I need to use &env? is there a way to do it w/o it would just be unhygeinic?
20:49amalloyscottj: yeah, i suppose you don't need env. just put an a in there
20:51hiredmanamalloy: you were correct the first time
20:52hiredman~ is translated to unquote by the reader, and as ` is expanded it is removed
20:52clojurebotIn Ordnung
20:52hiredmanclojurebot: no!
20:52clojurebotNo entiendo
20:52amalloyhiredman: he doesn't intend to put a ` in at all afaict
20:53amalloy(defmacro test [form] `'~form) (test ~foo) ; yields (unquote foo)
20:53amalloybut yes, it is liable to break if he tries to write a macro around this?
20:54hiredmanyes
20:54hiredmanactually even if ` was rewritten as a macro that would not help in this case
20:55amalloyright
20:55amalloyi think *a is clearer. a lot like the G! symbols in CL's with-gensyms
20:55scottjI was thinking $a as an alternative since that's shellish
20:56scottjbut ~ has the advantage that it can apply to lists as well as symbols
20:56amalloysure, whatever makes you happy. i just grabbed an unusual symbol; coincidentally it looked like C's deref operator
20:56amalloyscottj: urgh what
20:56hiredmanscottj: thats ~@, which is not the same
20:57hiredmanunquote-splicing
20:57scottj(sh (ls ~(+ 2 3))) vs (sh (ls ($ (+ 2 3))))
20:57scottjno, not splicing
20:57hiredmanoh, right
20:58scottjso you guys are saying I can do it, but if I ever have a macro bar where (bar (sh ...~..)) then it will break?
20:59amalloyscottj: but wait, so what? when do you need ~(+ 2 3)? plain old (+ 2 3) will work fine
20:59scottjamalloy: this is for shell commands, so (sh (+ 2 3)) runs the command "+ 2 3"
20:59hiredmanamalloy: no you'd need (let [x (+ 1 2)] (.. $x))
21:00amalloyhiredman: no; it's fine if his sh2 macro expands into (sh "ls" (+ 1 2))
21:01amalloyi guess i didn't understand the intent of your sh2 thing
21:01hiredmanmmmm
21:02scottjI didn't think about how sublists would work by default, if they were always escaped then you'd be right
21:02amalloyscottj: that seems to be overloading the ~ operator a lot. now in addition to macro-unquote, it's "when in a shell macro: if applied to a symbol then use that symbol's value; if applied to a list, parse that list as a subshell"?
21:03scottjno, all ~ would mean is this is clojure code
21:05hiredmangiven (sh2 (ls -l a)) you can check to see if ls and -l are locals or globals and if not str them
21:05amalloyscottj: perhaps use ' instead of ~? that doesn't have the nested-macro issue, and makes roughly as much sense: "don't send this to the shell for interpretation; quote it as clojure code"
21:05scottjgood idea
21:10amalloy(and i can't think of any reason you'd want ' in a sh2 call)
22:20semperosbrehaut: I've extended the ResponseElements and ValueTypeElem protocols to handle all my values
22:20semperosbut I'm still getting the following error when that org.openqa.selenium.NoSuchElementException is thrown
22:20brehautsemperos: ok
22:20semperoshttps://gist.github.com/914786
22:20brehautis it being wrapped in a fault?
22:21semperosnope
22:22brehautthat looks quite dire
22:22brehautcan you interpose something to make the request yourself and catch the response?
22:24semperoshmm
22:24semperosI can make the request using ne's call method...
22:25brehautyou need to get the http request though
22:25brehautin the textual form
22:25brehautyou can probably do it by mocking the request up using telnet
22:26semperosok
22:26brehaut(if you dont have an http proxy tool inspector handy)
22:26semperosworking on my work Windows machine
22:26semperosnothing is handy :)
22:26brehautcmd + telnet is ;)
22:27semperosI'll fiddle and bug you in a few
22:27semperosthanks
22:27brehautyou can use the necessary-evil internal API to just generate the xml for you too
22:27brehautso that you dont have to type the body of your request into telnet by hand
22:28semperosmakes sense
22:29semperosturns out windows 7 disables telnet by default, reenabling...
22:29brehautit disables the telnet client?!
22:29semperosyep
22:29semperosprofessional edition, anyway
22:29brehautthats messed up
22:29semperos:)
22:29semperosno biggy
22:29semperostop google result: http://www.fettesps.com/windows-7-enable-telnet/
22:30pdk``honestly i think the last time i used telnet
22:30pdk``was just for the star wars in telnet thing
22:30brehautpdk: an excellent use
22:32brehautsemperos: what i expect to be the issue is that (catch Exception e (fault -10 (str "Exception: " e))) that is getting something out of e that when turned into a string is invalid XML
22:32semperosright
22:32semperosmy thoughts as well
22:32brehautif you look at https://github.com/brehaut/necessary-evil/blob/master/src/necessary_evil/xml_utils.clj#L35-58 it doesnt appear to escape anything
22:32semperosnope
22:33semperosyeah, I was trying to filter out things on my end
22:38scottjis there a foo where (foo bar) returns #(bar %&)?
22:42amalloyscottj: i can't think of a trivial one, but (comp bar list) does
22:42cemerick(partial apply bar)
22:43amalloycemerick: going the opposite direction there
22:43cemerickoh, right-o
22:45scottjideas for a name? vargs?
22:45brehautarguments
22:45cemerickThe name would be longer than the code… :-)
23:00scottjI suck so much at macros, I tried spliting sh2 into a fn that gives the right code when passed a quoted expression and then a macro that just does the quoting and calls the function but I can't get it working, http://jaderholm.com/paste/sh2.html if anyone cares
23:01scottjI realize sh3 is nonsense, but not sure what it should be
23:02amalloyscottj: (defmacro sh3 [expr] (sh2 expr))?
23:03amalloyif all you want to do is make an auto-quoting version of s2, that's it
23:04amalloythat said, don't use 'sh or i will come to your house and strangle you. that won't work unless the caller of the macro has (use)'d clojure.java.shell. `sh is there for you
23:05amalloy(same for 'str)
23:07amalloyoh. and don't use list? in macros. use seq? - a lot of code is seqs
23:07scottjok, (macroexpand-1 '(sh3 (ls -l ~a))) ; => (clojure.java.shell/sh "ls" "-l" (clojure.core/str a))
23:07scottj(sh3 (ls -l ~a)) ; => {:exit 2, :out "", :err "/bin/ls: cannot access (clojure.core/unquote a): No such file or directory\n"}
23:07amalloyit turns out that makes the difference for me. with list? it fails, with seq? it works
23:08amalloyor at any rate causes the macro version to expand to the same thing as the function version returns
23:08scottjoh sweet I think seq? did it
23:08amalloyusing list? in a macro should be a compiler error :P
23:09semperosbrehaut: I think it's probably the #<> that Clojure wraps java objects in
23:09semperosit's being output as a string
23:10semperosformatting code now to put in a gist
23:10brehautsemperos: ah of course. i dont know how i didnt catch this in the past
23:11brehautsemperos: im going to write some blog content and then try to patch the xml emitter
23:11amalloyscottj: i do something similar in clojail: https://github.com/cognitivedissonance/clojail/blob/master/src/clojail/core.clj#L70
23:11semperosno worries
23:11semperosI had something similar happen earlier on, I forget where
23:11brehautsemperos: im between projects for a few hours so i'll try ot get it done ;)
23:11semperosso I ended up stopping using #<> in my own repl representations of objects
23:11semperosno worries
23:11semperosI'll work around it
23:11semperosthanks again for everything
23:13brehautno worries
23:13semperosbrehaut: here's the XML, just fyi
23:13semperoshttps://gist.github.com/914786
23:13semperosI just hacked your handle-post method to spit to files :)
23:13brehautcheers :)
23:18scottjamalloy: thanks
23:33joshua__Awesome. Just got a 24/25 on my Programming mid term. Than the teacher decided that one of the questions was worded ambiguously and that a+b answers would both get points. Now I have 25/25.
23:36pdk``what material is it teaching