#clojure logs

2011-04-04

00:00amalloyMiggyX: raek has a blog post somewhere that does this
00:00amalloy$google executors in clojure raek
00:00sexpbotFirst out of 33 results is: Executors in Clojure - raek's blog
00:00sexpbothttp://blog.raek.se/2011/01/24/executors-in-clojure/
00:42bettspHi guys, I'm working my way through The Joy of Clojure and I'm having trouble with an example
00:43bettsphttp://pastie.org/1753072
00:43bettspThis reports "No implementation of method: :cat of protocol: #'user/Concatenatable found for class: java.lang.String"
00:47amalloybettsp: works for me. maybe you're on the wrong clojure version
00:47brehautbettsp: can you run *clojure-version*
00:48brehaut(in your repl)
00:48bettspbrehaut: Well I'm going through vimclojure (nailgun), my lein file depends on 1.2.0
00:49amalloybrehaut: this should work on 1.2.0 - try doing what brehaut asked to see if you're *actually* on 1.2.0
00:49bettspamalloy: Yep, 1.2.0
00:49amalloyhm
00:50bettspMaybe it's a weird Nailgun / vimclojure quirk
00:50bettspLet me try using clj directly
00:50amalloyyou may need to restart your repl
00:50amalloysome things have a sort of "once-only" semantics
00:51bettspamalloy: Yeah, I think that was it. Thanks
00:53amalloywhen all else fails, try rebooting
00:57ataggartamalloy: do you have permissions on jira?
00:57amalloyno
00:57ataggartk
00:57amalloywhat for, ooc?
00:58ataggartI can submit tickets, add/delete attachments, etc., but I can't change any of the field values, e.g., "waiting on". I was just wondering if that was expected, or I'm missing some obvious button somewhere.
00:59ataggartI'd rather not pester Stu every time I update something.
01:27ataggart&(Integer/toBinaryString -2)
01:27sexpbot⟹ "11111111111111111111111111111110"
01:27ataggart&2r11110
01:27sexpbot⟹ 30
01:42marko_can I create this task in leiningen on intelliJ: clean, deps, jar and move .jar to other destination folder with one combined command?
03:54marko_is it possible to get current file path with File. on clojure? say im on ns projects.core and want to get whole system path to the same file?
03:57marko_im trying (.getPath (File. ""))
04:19TobiasRaederMorning
06:42markskilbeckHi, all.
06:42markskilbeckIs it possible to open a jar from the repl?
06:51zmyrgelI have a list of vectors like ([1 a] [2 b] [3 c] ...). What would be a idiomatic way to return the vector with highest number from it?
06:52alfborgeIs it sorted?
06:52zmyrgelno
06:52zmyrgelmaking changes to my code and previous version had just a list of numbers so I had (apply max my-list)
06:53alfborgeWill you use the list to retrieve other vectors later?
06:53opqdonut_zmyrgel: reduce with a (fn [x y] (if (<= (first x) (first y)) y x))
06:53zmyrgelno, I just need the highest vector from it
06:56zmyrgelopqdonut_: seems to work just fine
07:01yasonzmyrgel: (last (sort yourlist)) but efficiency-wise the right solution really depends on how you use the list of vectors
07:02raek_,(apply max-key first '([1 a] [2 b] [3 c]))
07:02clojurebot[3 c]
07:02zmyrgelraek_: seems nice solution, no need for extra code
07:03raek_markskilbeck: what do you mean by "open a jar"? use libraries from it?
07:03zmyrgelyason: It's part of my chess game tree evaluation
07:03markskilbeckI apologise for my poor terminology. I just want to use the gtk.jar, without having to quit and restart the repl.
07:03markskilbeckIs that possible?
07:03zmyrgelThe max value goes to new list where I choose the minimum value and that again to new list
07:04raek_markskilbeck: you can use (add-classpath "file:///absolute/path/to/file.jar"), but add-classpath has been deprecated
07:04zmyrgelthough my minimax seems to have slight error in it :)
07:05zmyrgelseems to return the game state of the cutoff point and not the next state
07:05markskilbeckraek_: I noticed that. Still, I get an error when doing (import 'org.gnome.gdk Event)
07:05markskilbeckClass doesn't exist.
07:06raek_markskilbeck: there's an error in you syntax: (import '(org.gnome.gdk Event))
07:07raek_either that or simply (import 'org.gnome.gdk.Event)
07:07markskilbeckOh I see.
07:08markskilbeckThanks raek_
07:14raek_anyone know where I can read about the details why add-classpath was deprecated?
07:14yasonzmyrgel: if you do this operation constantly, then you could either keep the list sorted, keep track of the biggest item before hand, or use a reduction as described above to run through the list quickly. But if this isn't in the inner loop and especially if the list is quite short, it's probably cleanest to just sort+pick last
07:14raek_all I know is that it turned out to not work consistently
07:33markoim running clojure.contrib.shell-out to execute a shell script, but the problem is, that output of shell script is printed after execution, not realtime, can this be solved somehow?
07:53waxrose,(instance? Integer 10)
07:53clojurebottrue
07:53waxroseweird
07:56markskilbeckwaxrose: why is that weird?
07:56waxrosemarkskilbeck, My REPL is outputting that as false.
07:56waxroseWhich I know it shouldn't.
07:56markskilbeckI get true.
07:57waxrosehmm, maybe my repl is out of wack
07:57clojurebotc'est bon!
08:00raekin 1.3, boxed integer numbers are always of type Long
08:01waxroseoh, thanks
08:02waxroseI thought I was going crazy. :3
09:17TimMchey wax
09:57fliebel&(let [kv (clojure.lang.MapEntry. :a 1)] (identical? kv (first (into {} [kv]))))
09:57sexpbot⟹ false
09:57TimMcNot terribly surprising.
09:58fliebelTimMc: I guess, not, but why does it tear apart these entries?
09:58TimMcMaps can be implemented as trees, hash tables, etc.
09:59TimMcI suspect the entries *have* to be torn apart for those.
10:00fliebelTimMc: And then? In the end you need to get the key and the value back together, right?
10:00TimMcFor iteration, sure.
10:02fliebelI guess I don't understand enough of maps then…
10:04fliebelOkay, say you have a binary tree, which you go down in left or right with hash < node or whatever. Now, dos it really matter if you store the value down there or the MapEntry? Hm, I guess it's just efficiency then?
10:05fliebelAnyway, I made a type that implements IMapEntry, and when iterating over it, I naively expected to get back my objects, rather than vanilla objects.
10:09kumarshantanuhi, anybody deeply familiar with Leiningen plugins here? (eval-in-leiningen and eval-in-project)
10:10TimMcNot I, but ask your question anyway.
10:11alfborge`This is probably a stupid question, but are the people behind leiningen and cake enemies?
10:11alfborge`Or friends?
10:13TimMcFriendly competitors, I think.
10:13TimMcI don't actually know who the maintainer of cake is.
10:13alfborge`I suspect he's from ruby... cake => rake ... hmmm...
10:14TimMcAh, yeah. And it is written in Ruby.
10:14TimMcThe two tools maintain basic config compatibility, which is nice.
10:15fliebel… Don't reifies have a type?
10:15fliebelTimMc: It's wrapped in some Ruby souse I think. The meat of it is Clojure.
10:21kumarshantanumy Leiningen question is here: http://groups.google.com/group/leiningen/browse_thread/thread/fbec0e9ef37a9111/3296ec2ccd087913#3296ec2ccd087913
10:22kumarshantanuTimMc: if you'd like to answer the question (link above)
10:32fliebelHow much faster are types than multimethods?
10:34raekJustin Balthrop (ninjudd) is the maintainer of cake. Interview where he mentions why cake was made: http://blog.fogus.me/2010/11/30/take-6-justin-balthrop/
11:02mattmitchelli need a function like filter, but to only return the first matching item. is there one that exists?
11:03ogonzalezmattmitchell, some
11:03zmyrgelsome?
11:05ogonzalezhmm I think it's quite not the same
11:06ogonzalezhttp://richhickey.github.com/clojure-contrib/seq-utils-api.html#clojure.contrib.seq-utils/find-first
11:07mattmitchellperfect thanks!
11:07ejacksonmattmitchell: does (comp first filter) work for you
11:08Raynesmattmitchell: (comp first filter) is a good solution. Since filter is lazy, you aren't really doing any unnecessary computation.
11:08mattmitchellejackson: I think so:
11:08mattmitchell(comp first filter)
11:08mattmitchell#<core$comp$fn__3642 clojure.core$comp$fn__3642@368bca43>
11:08mattmitchellhow does that work?
11:09mattmitchelloh i think i see
11:09mattmitchelloh nice :)
11:09Raynes&((comp first filter) (partial = 3) [1 2 3 4 3 5])
11:09sexpbot⟹ 3
11:10ejackson&((comp first filter) (partial >= 3) [1 2 3 4 3 5])
11:10sexpbot⟹ 1
11:10mattmitchell... brain working hard ...
11:10ejacksonhmmm.... that was unexpected
11:11ejackson&((comp first filter) even? [1 2 3 4 3 5])
11:11sexpbot⟹ 2
11:11mattmitchellinteresting
11:11mattmitchellthat's really cool!
11:13raek((partial >= 3) 1) is (>= 3 1)
11:13Raynes(some even? [1 2 3 4 3 5])
11:13Raynes&(some even? [1 2 3 4 3 5])
11:13sexpbot⟹ true
11:13Raynes&(some #(and (even? %) %) [1 2 3 4 3 5]) ; I do this more often than I'd like to admit.
11:13sexpbot⟹ 2
11:14ejacksoneep
11:15mattmitchellRaynes: yeah that's what i was doing before
11:15ejacksonraek: thanks, I always get that backwards.
11:16raek&(letfn [(pick [p?] (fn [x] (when (p? x) x)))] (some (pick even?) [1 2 3 4 5]))
11:16sexpbot⟹ 2
11:16raeksome is a bit weird to use, since it excpects a kind of funtion that you usually don't have
11:16mattmitchellraek: and the word
11:16mattmitchelloops
11:16Raynesraek: I'm so ashamed. ;>
11:17mattmitchelland the word "some" seems very much plural
11:17raek(except for maps and sets)
11:17Raynesraek: I bet there are a few of those in sexpbot and clojail. I'm not even sure that amalloy thinks to change them during his tidy sessions.
11:18ejacksonmattmitchell: if you prefer the threading style:
11:18ejackson&(->> [1 3 5 6 8 10] (filter even?) first)
11:18sexpbot⟹ 6
11:18raekhadn't thought of using and there...
11:18raekneat
11:19raekRaynes: ashamed of what?
11:19mattmitchellejackson: so is that actually different from (first (filter even? [1 2 3 4])) ?
11:19raek&(macroexpand-1 '(->> [1 3 5 6 8 10] (filter even?) first))
11:19sexpbot⟹ (clojure.core/->> (clojure.core/->> [1 3 5 6 8 10] (filter even?)) first)
11:19Raynesraek: Using some where I should be using (comp first filter).
11:19ejacksonno, its just sometimes easier to read as the order of functions appears in the code in the order in which they are execute
11:19ejacksonrather than inside-out as with the standard syntax
11:20mattmitchellejackson: i see, yeah
11:25msilverman2hi guys, what's the easiest way to append something to a list? it looks like conj in lists prepends your data
11:26Raynes&(cons 0 '(1 2 3 4))
11:26sexpbot⟹ (0 1 2 3 4)
11:26msilverman2that's prepending
11:26ejackson&(concat '(0 1 2 3) (4))
11:26sexpbotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
11:26RaynesThat was unrelated to your question. Sorry.
11:26msilverman2ahh, sorry
11:26ejackson&(concat '(0 1 2 3) 4)
11:26sexpbotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer
11:27Raynes&(concat '(0 1 2 3) '(4))
11:27sexpbot⟹ (0 1 2 3 4)
11:27ejacksondammit Raynes !
11:27ejackson:P
11:27RaynesThere isn't really a good way to do that though. You really shouldn't.
11:27ejacksonagreed, its a bit nasty
11:27RaynesIf you need to prepend data, you probably should be using vectors.
11:27Raynesappend*
11:27RaynesForgive me, I didn't sleep much last night. :(
11:28ejacksoni dunno about that, your trigger finger is pretty Clint Eastwood today :)
11:28Raynes:p
11:29ejacksonor is that all the caffeine ?
11:29RaynesI am caffeine free.
11:30RaynesI've been caffeine free since last September.
11:30RaynesI binged on coke at the Conj and slept about 2 hours the night before the conference started.
11:30ejacksonoooooooh
11:31RaynesSince ninjudd and friends took me to a bar and I was too young to drink, I drank coke so I could still get the teenage rebellion out of my system.
11:31ejacksoni never manage to go very long w/o, although I'm strictly drip fed on the stuff now, after a similarly binge filled youth
11:31RaynesI miss caffeine, but I missed getting sleep at night more.
11:32dnolen,(conj [1 2 3 4] 0)
11:32clojurebot[1 2 3 4 0]
11:32dnolenmsilverman2: ^
11:32ejacksonbut that's a vector, he wanted lists, no ?
11:32msilverman2it's all good
11:32msilverman2we're just using concat
11:32msilverman2but is there a better way with lists?
11:32dnolenmsilverman2: just not that concat is slow - linear in the length of the list.
11:33dnolens/not/know
11:33sexpbot<dnolen> msilverman2: just know that concat is slow - linear in the length of the list.
11:33RaynesNot really. Lists are not designed for that.
11:33msilverman2figured
11:33dnolenmsilverman2: lists are useful, but is there any reason to not use a vector?
11:33ejacksonRaynes: an interesting fact for you is that the drinking age in the UK is 18, you should arrange that the conj happens here at the appropriate time :)
11:33msilverman2no :) good point
11:33Raynesejackson: Heh. Good to know.
11:34ejacksonnot that I wish to involve myself in corruption, you understand.
11:34RaynesI don't have much of an indulging personality.
11:34ejacksongod, this is an IRC channel, I've probably just got myself on all sorts of FBI lists now.
11:34thorwilthere's no clojure-contrib 1.2.1 ... using contrib 1.2.0 with clojure 1.2.1 doesn't pose any problems?
11:35fliebelDoe anyone happens to have written a 'memoizing' macro? That would bind a vec of functions to memoized versions during the body of the macro.
11:35Raynesejackson: It'll be fine. Maybe a cavity search and the airport or two, but you'll make it.
11:35Rayness/and/at/
11:35sexpbot<Raynes> ejackson: It'll be fine. Maybe a cavity search at the airport or two, but you'll make it.
11:36ejacksoni thought that was standard practice these days ?
11:36raekthorwil: yes. tje new stuff in clojure 1.2.1 is just some bug fixes
11:36Raynesejackson: Touché.
12:01pyris it me or are all the clojure/cassandra projects outdated and/or unmaintained ?
12:13kumarshantanufliebel: do you want those functions to be dynamically re-bound?
12:15fliebelkumarshantanu: I just need a macro that does (binding [foo (memoize foo) bar (memoize bar)] ~@body)
12:15kumarshantanufliebel: if the functions are known beforehand, then writing one should be straightforward I guess
12:15fliebelkumarshantanu: No, they should be passed in.
12:16fliebelStill rather straightforward, but I just wanted to know if anyone had one lying around.
12:16kumarshantanufliebel: so you want to pass a vector (variable size) of functions?
12:16kumarshantanuoh okay
12:16fliebelyea
12:17fliebelso it'll involve some looping and concatenating maybe...
12:22mecIs there a better way to implement nested-for? https://gist.github.com/901895
12:22malkomalkowhat's the best idiomatic way to filter a seq based on multiple criteria?
12:24mec(for [s someseq :when (test1 s) :when (test2 s)] s)
12:24Raynesmalkomalko: Combinations of and and or.
12:25Raynes&(filter #(and (> % 10) (< % 20)) [7 8 9 10 11 12 13 14 15 21 30 45])
12:25sexpbot⟹ (11 12 13 14 15)
12:25malkomalkoyah, that's what I figured, I'm trying to pass in a map to dynamically build up my and list
12:25malkomalkojust trying to figure out how to do that
12:26malkomalkothat will be a good start, thanks
12:29fliebelIs a sorted map more expensive to insert and delete from, or doesn't it matter because they are both trees anyway?
12:32raekfliebel: it probably has log_2 instead of log_32, or something
12:33fliebelraek: That would make sense.
12:34raekso, 2^n entries would make a tree of depth n
12:49mattmitchellis there a fn like select-keys, but instead where you specify the keys you *don't* want?
12:53mecmattmitchell: you could do something like (select-keys m (seq (clojure.set/difference (set keys-you-want) (set (keys m)))))
12:53mecbut i'd think theres a better way
12:54mattmitchellmec: ok excellent
12:54mecoh flip those around (clojure.set/difference (set (keys m)) (set keys-dont-want))
12:56mattmitchell,(clojure.set/difference #{:id :one :two} #{:two})
12:56clojurebot#{:one :id}
12:56mattmitchell,(seq (clojure.set/difference #{:id :one :two} #{:two}))
12:56clojurebot(:one :id)
12:57malkomalkois something like this possible? it seems like % loses context
12:57malkomalkohttps://gist.github.com/15106a3022c4c28d03b6
12:57mattmitchell,(select-keys {:id => 1 :one => "1" :two => "skip this"} (seq (clojure.set/difference #{:id :one :two} #{:two})))
12:57clojurebot9
12:57mattmitchellhmm
12:57mattmitchell,(doc select-keys)
12:57clojurebot"([map keyseq]); Returns a map containing only those entries in map whose key is in keys"
12:58mattmitchell,(select-keys {:id => 1 :one => "1" :two => "skip this"} [:id :one])
12:58clojurebot9
12:58mec,{:id => 1}
12:58clojurebotjava.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 3
12:59mattmitchellwhy is that?
12:59mec,(select-keys {:id 1 :one "1" :two "skip this"} [:id :one])
12:59clojurebot{:one "1", :id 1}
12:59mattmitchellomg no! sorry, i'm mixing in my ruby :(
12:59mattmitchelli switch back and forth all day eh eh
13:00mattmitchell,(select-keys {:id 1 :one "1" :two "skip this"} (seq (clojure.set/difference #{:id :one :two} #{:two})))
13:00clojurebot{:id 1, :one "1"}
13:00mattmitchellthere we go!
13:00mecinstead of difference i would do (apply disj (set (keys m)) keys-you-dont-want) or if you konw the keys just (disj (set (keys m)) key1 key2)
13:01mattmitchell,(doc disj)
13:01clojurebot"([set] [set key] [set key & ks]); disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s)."
13:07mecmalkomalko: im not sure what you're trying exactly but doseq always returns nil, i think you want for. Also #(and (for ...)) wouldnt work you need something like #(every? identity (for ...))
13:07malkomalkoI'm trying to build in a list to of statements to filter on based off a map
13:08malkomalkowow, awesome grammar...
13:08meclol
13:08meccan you give me an example of the result?
13:12Raynesmattmitchell: Sounds like you lead a very complicated existence.
13:12mattmitchellRaynes: why do you say that?
13:13RaynesYou switch between Clojure and Ruby all day long and get the two mixed up. Sounds like a confusing lifestyle. :p
13:14mecI dont think its too hard ;p i cought myself writing lua style maps once
13:14mattmitchellRaynes: seriously, tell me about it. we just started using clojure a few months ago.
13:14mattmitchelland now half of our stuff is in clojure, half in ruby
13:16ejacksonyeah, its the same for me. I now get annoyed with python etc when I can't do things like make lists keys in maps.
13:19mattmitchelleh eh. sometimes when i switch back to ruby and see "if(xxx)", i just stare at it ??? it takes me a minute to remember that it's ruby and there is no prefix notation
13:21malkomalkohey mec... what's the diff between (filter #(every? identity (for...)..) vs (filter #(every? (for ..)..)
13:22fliebelmalkomalko: unified diff?
13:22fliebelANyway, I don;t think the later is valid
13:22pdk(doc identity)
13:22clojurebot"([x]); Returns its argument."
13:23technomancyif you're using for anyway, you should use the :when clause rather than having a sepraate filter call
13:23pdki think there's something wrong with the formatting in both though
13:23malkomalkothis worked
13:23malkomalkohttps://gist.github.com/15106a3022c4c28d03b6
13:23amalloyRaynes: i did write raek's "pick" in amalloy/utils, though i called it verify. i haven't ported any of that to sexpbot yet though
13:24malkomalkobut i just feel like I'm not doing it the best way
13:25amalloymattmitchell: i disagree about the word "some". i agree the function "should" act like (comp first filter), but i remember using "some" in the same context as "there exists" back in school. "some positive x", etc
13:25pdkthere's no function some that uses it in that sense though
13:31mattmitchellamalloy: i see what you mean. This example... returns true, which is what I would expect: (some even? [2 3 4 5 6])
13:32amalloymattmitchell: right. i kinda wish it returned 2: "find some even number from this list"
13:32amalloyas do you
13:33kephale00yeah perhaps some as is should actually be named some?
13:33mattmitchellamalloy: yeah 2 makes sense too. i originally was looking for something like ruby's "detect" -> http://www.ruby-doc.org/core/classes/Enumerable.html#M001485
13:33mattmitchelldetect returns the first item in the collection when the "predicate" is true
13:34kephale00, (some #(if (even? %) %) [2 3 4])
13:35clojurebot2
13:35kephale00i retract my statement about renaming some, its just how you use it
13:36amalloykephale00: just a sketch, i know, but it's generally bad form to use a single-branch if. prefer when (in this case, "and" would work as well)
13:36kephale00amalloy: noted and appreciated
13:36pdkand standing in for when is kinda hackish
13:39amalloypdk: meh. and is designed for short-circuiting on purpose. in languages lacking a when construct, you might well write "divisible = y != 0 && x % y == 0"
13:40kephale00i've run into and being used in such situations in common lisp a number of times
13:40kephale00wow.. its confusing to read that without denoting AND in some way
13:41mecmalkomalko: this may be better, but I think it can be simplified further, im just not sure how https://gist.github.com/gists/fd02f373dd819b5e4536/edit
13:41amalloykephale00: yes, not a well-written example :P
13:42amalloyhaha github's 500 page is adorable
13:43mecmalkomalko: sorry this one https://gist.github.com/fd02f373dd819b5e4536
13:45amalloymec: i missed the start of that discussion, i guess. what is this code trying to do?
13:49mecamalloy: no idea
13:49amalloyhaha
13:49mecmalkomalko: ok this is deffinitly the one https://gist.github.com/fd02f373dd819b5e4536
13:53fliebel1What is this supposed to mean? RetryEx clojure.lang.LockingTransaction http://pastebin.com/11xTUfKn
13:54hiredman_fliebel1: means your code is trying to dos the stm
13:54hiredman_"pleases stop"
13:59fliebel1hiredman_: Haha, sure… I know what is the problem idk.
14:05fliebel1More weird errors, this is what I get upon closing my Swing window: http://pastebin.com/UjdhDhcX
14:06ieureIs there a decent XML/HTML parser for Clojure similar to lxml for Python?
14:06fliebel1Note that there is none of my nses in there, and a few mentions of Leiningen.
14:07fliebel1ieure: I think there is a lot of XML stuff in Java, and some in clojure.contrib as well.
14:07kumarshantanuhi, can anybody here tell me how does leiningen set the classpath (to include project sources)? e.g. for "lein test" or "lein repl"
14:07amalloykumarshantanu: less `which lein` - it's fairly straightforward iirc
14:08ieurefliebel1, Yeah, what I’m really after is a single lib that lets me use the same code to parse HTML and XML.
14:08fliebel1ieure: Oh, like tagsoup?
14:08amalloyieure: tagsoup
14:08technomancykumarshantanu: see the leiningen.classpath namespace
14:09ieurefliebel1 / amalloy, Looks like exactly what I want.
14:09ieureThanks.
14:09ieureamalloy, BeautifulSoup is a Python library.
14:09amalloyyeah, i looked it up
14:09amalloyagain :)
14:09ieureIt’s crazy handy.
14:10amalloyieure: i think tagsoup was first
14:13fliebel1Grr, does anyone know why I might possibly get IndexOutOfBoundsException when closing a Swing window?
14:14fliebel1amalloy: I have the same.
14:14kumarshantanuamalloy: thanks, yes the script includes both "src" and "test" folders in classpath
14:14fliebel1But worse, I forget about one completely and end up on the wrong page, not remembering the other one.
14:16kumarshantanutechnomancy: yes, I can see the classpath using leiningen.classpath/classpath -- but surprisingly, any attempt to (require (symbol "foo.valid-ns")) and (resolve (symbol "foo.valid-ns/bar")) fails - returns nil
14:17kumarshantanuI am trying to do this inside a leiningen plugin (that a host project uses)
14:17technomancythat is the classpath that eval-in-project will use to run any code that needs access to the project's dependencies and/or source
14:18technomancykumarshantanu: HACKING.md may be helpful here
14:18kumarshantanutechnomancy: I am doing this inside eval-in-project -- is that a right thing to do?
14:19technomancyyeah, if you need access to the project source, you need to run inside eval-in-project
14:22kumarshantanutechnomancy: ah, seems I found a clue -- actually i am declaring `:eval-in-leiningen true` in the host project, because unless I do that leiningen.compile isn't available to the plugin
14:23kumarshantanuand HACKING.md seems to say that if I set `:eval-in-leiningen true` then that will be an exception and therefore (I guess) sources will not be included in the classpath (!!)
14:28technomancykumarshantanu: you can't have code eval both in leiningen's process and the project's. you have to pick one.
14:32kumarshantanutechnomancy: not sure if I followed that - I want to have the host project's deps+sources on the classpath (like test, repl) and want to eval-in-project from the plugin at the same time. That seems to require that I declare `:eval-in-leiningen true` (because unless I do that, leiningen.compile namespace isn't available to the plugin)
14:34kumarshantanuI guess I am missing something obvious, but not sure what
14:52fliebel1What is the `~@ trickery for turning a supplied symbol into a qualified one? `(foo ~bar) -> (some.ns/foo some.other.ns/bar) It works without it, but I suppose it's cleaner to have them qualified?
14:54pdk,`x
14:54clojurebotsandbox/x
14:54amalloyfliebel1: ##(let [supplied bar] `(foo `~supplied))
14:54sexpbotjava.lang.Exception: Unable to resolve symbol: bar in this context
14:54amalloy&(let [supplied 'bar] `(foo `~supplied))
14:54sexpbot⟹ (clojure.core/foo clojure.core/supplied)
14:54amalloydangit. maybe not
14:55fliebel1amalloy: Yea, I want to get whatever 'bar points to
14:56fliebel1&(let [x 'y y 1] `(~(resolve x)))
14:56sexpbotjava.lang.SecurityException: You tripped the alarm! resolve is bad!
14:56fliebel1,(let [x 'y y 1] `(~(resolve x)))
14:56clojurebot(nil)
14:56fliebel1oh
14:59amalloyfliebel1: resolve doesn't get access to locals (nothing does)
15:01amalloyincidentally, trying to manually namespace-resolve symbols supplied by the user sounds like a bad idea. why do you want it?
15:07msilverman2is there anyway to run a single deftest with lein?
15:08technomancymsilverman2: you can use test selectors; see the tutorial
15:09technomancykumarshantanu: I see. you can't change the classpath of leiningen itself, and a plugin runs inside the leiningen process.
15:09msilverman2thanks
15:13fliebel1amalloy: If it's a bad idea, I don't wan it. I just thought using unqualified symbols was bad practice most of the time. But thinking about it, symbols supplied by the user should be 'clean'
15:13msilverman2technomancy: I got this after following the tutorial: Could not locate robert/hooke__init.class or robert/hooke.clj on classpath:
15:14kumarshantanutechnomancy: sorry for the repeated ping! I located the problem (of not resolve'ing a symbol) was in my own code -- it works for me now. Thanks so much!
15:14amalloyfliebel1: right. symbols supplied by the user should be left alone unless your intent is to transform them. they don't need to be qualified, because in the user's scope they already resolve to something
15:15technomancymsilverman2: oy, I need to update the tutorial about that. you need to add [robert/hooke "1.1.0"] to your :dependencies in project.clj for that to work.
15:15technomancykumarshantanu: aha; great.
15:15msilverman2thanks
15:15msilverman2what does that package do?
15:16technomancymsilverman2: all manner of wonderful hackery
15:16msilverman2lovin it...
15:16technomancybasically an extension mechanism for functions you don't have controll over
15:16technomancyhttps://github.com/technomancy/robert-hooke
15:17technomancysorta like monkeypatching, but a little safer
15:20fliebel1Can I use Java methods like one can use methods in Python? I mean, (someclass/method otherclass arg arg)
15:21fliebel1I am having trouble shaping a piece of api in a easy and extensible manner.
15:24fliebel1In Python, you have explicit this/self, which allows you to apply methods of one class to another. Since methods in deftypes and such also have the self, I was wondering if I could reuse them that way.
15:30amalloyno
15:30fliebel1okay
15:31amalloybut i think extend-type allows you to specify a map protocol-functions to implementations
15:31amalloyso you can reuse the clojure *functions*
15:31fliebel1yea… Thinking about it…
15:31amalloyah, i guess you have to use the raw extend function
15:32fliebel1okay
16:31thorwil(type body) tells me that body is a com.google.appengine.api.datastore.Text
16:31thorwilbut (isa? body com.google.appengine.api.datastore.Text) doesn't seem to be true
16:34technomancythorwil: yeah, that's confusing. you want instance? instead.
16:35technomancyisa? isn't really about isa?
16:35thorwilwhat's the right way to test for class membership, then?
16:37thorwiloh. not clear evena fter reading the doc
16:37dnolen,(doc isa?)
16:37clojurebot"([child parent] [h child parent]); Returns true if (= child parent), or child is directly or indirectly derived from parent, either via a Java type inheritance relationship or a relationship established via derive. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to the global hierarchy"
16:38technomancy,(doc instance?)
16:38clojurebot"([c x]); Evaluates x and tests if it is an instance of the class c. Returns true or false"
16:39thorwilyeah, now in contrast it's very clear :)
16:40thorwili'm testing with a java.lang.String
16:40thorwiltrying instance? gives me java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Class (NO_SOURCE_FILE:0)
16:40dnolenthorwil: reverse arg order.
16:41thorwilthanks
16:41thorwillooks like it's getting time for me to log off soon ;)
17:04kephale00I'm not sure what this stems from. I am using lein to make an uberjar within a function that is called from -main I do an EVAL on a list representation of a function call (J 3 4) which is a function defined inside my core.clj. This fails when I call it from the uberjar. When I run it in swank I don't get the issue.
17:04kephale00I resolved this by calling (use 'myns.core) at the start of my -main, but really weird.
17:06kephale00errr… not calling lein from a function
17:07kephale00there should be a period after uberjar
17:11amalloykephale00: a lot of the calling environment's context doesn't get passed on to eval. i know eval doesn't have access to lexical bindings, for example. i thought it got the benefit of your use/require forms, but i wouldn't be astonished to find out it didn't
17:13kephale00amalloy: aha. the thing that caught me off guard was the difference between the uberjar and swank, but maybe that is because when calling the function in swank I am already in the namespace or something along those lines. The thing is that everything that caused the issue was contained within the core.clj
17:13kephale00but all is well… until i find something else to break
17:14amalloy*generic warning about eval being evil*
17:14kephale00heh
18:29SomelauwOkay, I am install cake
18:29SomelauwI did sudo ln -s bin/cake /bin/cake
18:29SomelauwAnd tried typing cake but nothing happened.
18:32sritchie,(not (not-any? #{:jobtracker :namenode} [:jobtracker :slavenode]))
18:33clojurebottrue
18:33sritchieis there a version of this with contains? that will return a bool?
18:33amalloySomelauw: you installed a relative symlink in the wrong place
18:34amalloynow /bin/cake is a file saying "look in ./bin/cake", that is /bin/bin/cake
18:34sritchieor! is it idiomatic to wrap this in a predicate like (defn master? [roles] ... and trust that the user will use it as a predicate?
18:35amalloysritchie: huh?
18:35sritchieI'm writing a predicate that will check if any item in the supplied collection can be found in that set
18:35amalloyare you looking for ##(some #{:a :b} [:c :a])?
18:36sexpbot⟹ :a
18:36sritchieamalloy: yup, that's great. my other question was, is there a function like some that returns an explicit boolean
18:36SomelauwSo, I should give an absolute path?
18:36amalloyif you really-really want the user to only get out a boolean instead of a truthy-thing, you can cast to boolean
18:37amalloySomelauw: if you're going to install it in an absolute place, yeah
18:37amalloyi just put cake in ~/bin, though
18:37sritchieokay, but it's idiomatic to trust that a function called "master?" is going to return a truthy value, not necessarily a bool
18:37amalloyeg ##(boolean (some #{:a :b} [:c :a]))
18:37sexpbot⟹ true
18:38amalloy(def master? (comp boolean (partial some #{:namenode :jobtracker}))) for some amusing point-free nonsense
18:39sritchiepoint free or bust
18:40amalloybrehaut: in haskell that would be something like... master = boolean . some #{:foo :bar}, yes? (imagining that haskell has clojure's functions, anyway)
18:40brehautyup
18:40amalloywoo
18:41brehautplus maybe a type hint to dodge the monomorphism restriction (sigh)
18:41amalloy@$#@?
18:41SomelauwOkay, I put it in my bin as well.
18:42brehautamalloy: cat trouble?
18:42amalloybrehaut: no, just you
18:42amalloyas in, "what is this monomorphism nonsense"
18:42SomelauwI tried running "cake repl" and now it is downloading something.
18:42amalloySomelauw: sounds good
18:44brehautamalloy: oh right. its a think in the haskell type system that was added to simplify some type errors early on and that is now regretted; some instances of generic types are only allowed to have a single morphism or specific type unless you go out of you way to ok it with the compiler. its dumb.
18:44brehautamalloy: in particular you hit it a lot with point free stuff in the repl
18:45SomelauwAnd now it is printing a lot of resource not found messages.
18:45amalloybrehaut: that sounds well beyond my superficial knowledge of haskell
18:45brehautamalloy: heres a fun quote from the haskell wiki "The monomorphism restriction is probably the most annoying and controversial feature of Haskell's type system. All seem to agree that it is evil, but whether or not it is considered a necessary evil depends on who you ask."
18:45brehauthttp://www.haskell.org/haskellwiki/Monomorphism_restriction
18:47SomelauwBut the repl is working now
18:48amalloyconfirmed: reading that page causes my brain to bubble, but no information is imparted
18:49brehautamalloy: that summarises it pretty well ;)
19:10ieureHm, was #^{…} the old reader macro for metadata?
19:10amalloyyes
19:10amalloyit still works (more or less) but don't use it in new code
19:10amalloyieure: ^
19:10ieureYeah. I just saw it in clj-http and wasn’t sure if that was the case or not.
19:11ieureWanted to make sure I understood what was going on, since there’s no mention of it on http://clojure.org/reader
19:11gigamonkeyThis may be silly but can the dispatch function in a multi-method itself be a multi-method?
19:12ieureMultimethods all the way down.
19:12gigamonkeyGreat.
19:12amalloygigamonkey: yes. sounds silly but i'm sure there's some reason for it somewhere
19:12ieuregigamonkey, I have no idea, really.
19:12ieureTry it and find out!
19:12gigamonkeyieure: heh. I haven't even got Clojure installed yet.
19:12gigamonkeyLame, I know.
19:13ieuregigamonkey, Gotta start somewhere.
19:14gigamonkeyBah, this is where I hate that Clojure is built on top of Java. Maven, Ant, blech.
19:14brehautgigamonkey: are you trying to install from source?
19:15ieuregigamonkey, It is one of the best and undoubtedly the worst thing about it.
19:15gigamonkeybrehaut: I think I'm going to skip that for the reasons just mentioned. ;-)
19:15ieuregigamonkey, I recommend that you start by installing Leiningen, rather than Clojure.
19:15ieurehttps://github.com/technomancy/leiningen
19:15brehautgigamonkey: the reasons you mentioned are exactly the reasons you never have to install from source ;)
19:16gigamonkeyI would not have guessed that "a build tool for X" can be installed "rather than" X
19:17ieuregigamonkey, Yes, well. Lisp & JVM make for strange bedfellows.
19:18ieureThe nature of Clojure (JVM-based, young, relatively active development) mean that you really want to stick the appropriate JAR files into your workspace per-project rather than dicking around with installing stuff on the system.
19:18ieureAnd Leiningen is the tool which makes that not suck.
19:18OablIt's even more fun with other dialects (i.e. building SISC is a pita).
19:21SomelauwI think that because clojure being build on top of java makes it practical.
19:21gigamonkeySomelauw: no doubt. However I don't actually care about that. ;-)
19:21gigamonkeyDo I need a special version of SLIME for use with Clojure or is stock SLIME okay?
19:21cemerickIndeed; it being on the JVM means it'll be deployed far wider than probably any other lisp (if it isn't already).
19:22amalloygigamonkey: get clojure-mode.el
19:22ieuregigamonkey, I have the latest installed from ELPA, works fine.
19:22ieureAnd yeah, clojure-mode.
19:22gigamonkeyELPA?
19:22technomancygigamonkey: newer slimes break with Clojure; the version that worsk can be got via package.el or at https://github.com/technomancy/slime
19:22amalloyi think stock slime is probably okay, but clojure-mode.el has some nice stuff in it
19:22ieuregigamonkey, JFGI
19:23amalloy$google elpa
19:23sexpbotFirst out of 83900 results is: Welcome to ELPA
19:23sexpbothttp://tromey.com/elpa/
19:23technomancygigamonkey: but if a sufficiently-motivated CL-head could bring swank-clojure up to date with the latest slime developments I'd be happy =)
19:23amalloywonder if that's right
19:23amalloy$google elpa emacs
19:23sexpbotFirst out of 930 results is: Welcome to ELPA
19:23sexpbothttp://tromey.com/elpa/
19:23amalloywhew
19:23gigamonkeytechnomancy: how well understood are the issues that need fixing?
19:24technomancygigamonkey: not very, unfortunately. the author of swank-clojure went MIA a couple years ago, and I took over in maintenance mode, but it's kind in a "don't poke it to hard" state.
19:24technomancymy knowledge is pretty cursory
19:24technomancy*too hard
19:25gigamonkeyieure: of course the "latest" SLIME in ELPA doesn't seem, in fact, to be the latest SLIME.
19:26kephale00gigamonkey: i think we're supposed to use marmalade now
19:27technomancygigamonkey: the problem is the slime devs don't seem to value stable releases, so publishing via package.el was my way of saying "this version here; we're calling that a release" and getting off the cvs treadmill
19:30SomelauwWhat is the best way to return multiple values?
19:30ieureSomelauw, Depends on what you need to do with them.
19:30brehauttechnomancy: OT: did see that clj-time got a non-snapshot the other day?
19:30ieureSomelauw: A list, vector, or map are fine. Just use whatever’s appropriate for the conventions in the callers.
19:30SomelauwOkay, I have a list and I would like to remove and return a random element from that list.
19:30technomancybrehaut: whew; finally
19:31brehauttechnomancy: weevejester and mmcgrana to the rescue.
19:31SomelauwIt would be convenient to have syntax like (def [a b c] [1 2 3]) or something to easily return multiple values.
19:31gigamonkeykephale00: marmalade instead of what?
19:32amalloygigamonkey: i'm worried it might have been a pun on the word slime
19:32kephale00gigamonkey: oh, you mentioned elpa, i figured you were using that instead of marmalade
19:32amalloySomelauw: that syntax exists for let. you don't often want to def a zillion things wholesale
19:32SomelauwSince lists are immutable, I thought I should return both the removed element and the list with that element removed.
19:33amalloy&(let [[a b c] (range)] b)
19:33sexpbot⟹ 1
19:33OablSomelauw, how about... (defn foo [] [(do something) (another thing)]) (let [[a b] (foo)] (...))
19:34ieureSomelauw, I’d make sure that you _need_ to return both first. "I thought this would be a good idea" is a great way to write a bunch of code you don’t really need.
19:34ieureThat said, you’re going to find some nice features of Clojure if you do.
19:34Somelauwlets are fine too, but it is also usefull to be able to do the same with def, probably.
19:34amalloyhaha probably
19:35amalloySomelauw: you might find https://github.com/amalloy/amalloy-utils/blob/master/src/amalloy/utils/seq.clj#L74 handy if you want to take random elements out of a list
19:35gigamonkeytechnomancy: do you know if there was ever any attempt to get clojure-swank included in the main SLIME?
19:36technomancygigamonkey: there was a long time ago. they might be more open to it now that Clojure has matured a bit. I don't have the cycles to push for that myself though; I'm just keeping up the status quo.
19:36amalloySomelauw: in practice it really isn't useful. if you want to do something like that you'll want to do some processing on the elements anyway; and then you end up using a macro that expands into (do (def x (some-function-of 1)) (def y (some-function-of 10)))
19:36technomancyplus I'm too old to have the patience for CVS =)
19:37ieuretechnomancy, Slime is in CVS? Savages.
19:37technomancyieure: it's true.
19:38Somelauwamalloy: lazily shuffling a list of elements is also a cool idea, thanks.
19:39gigamonkeytechnomancy: yeah, that's kind of astounding to me.
19:40amalloysomeone get out the chloroform, and run cvs2git while the slime devs are out of commission
19:46technomancygigamonkey: essentially every time someone mentions swank-clojure, I make thinly-veiled attempts to pass off maintainership. no luck so far. =)
19:46amalloytechnomancy: i cloned swank-clojure! sadly by the time i got around to looking at it i forgot what i wanted to fix
19:47technomancyamalloy: this does not disqualify you from potential maintainership, just so you know.
19:48amalloytechnomancy: yeah, i'm keeping my teflon coat on just in case you try to stick me with it
20:31gigamonkeytechnomancy: well, I was a long-ago hacker on SLIME and do grok Common Lisp. So maybe if I get into Clojure I'll take a look. But doubtful.
20:32technomancygigamonkey: I know, I've read the book. no worries though; I'm not really expecting anyone to take me up on it =)
20:33technomancyit's really only an issue for people who want to hack CL and Clojure simultaneously, which is a pretty small minority. stumpwm users mostly, I figgure.
20:37gigamonkeyYes, if/when that population is larger, it'll probably get sorted.
23:13hboonCan someone help take a look at a 12 line macro using try-catch, would like some help with it - https://gist.github.com/902956
23:16ataggartthe ~name emits a namespaced symbol, which isn't allowed on the lefthand side of the let bindings
23:16ataggartwait, no
23:16ataggarthow are you calling it?
23:16hboonthe syntax itself is right (and taken from redis-clojure)
23:17hboonit's called from another macro
23:17hbooni would like to make it not call the second release-connection (the one in finally) if there's an exception (i.e. if the catch is triggered)
23:18hboonie. in procedural languages, you set a flag in catch and check for it in finally
23:18ataggartmove the one in finally to immediately after ~@body
23:19ataggartthat'll work so long as it doesn't also throw an exception
23:19hboonthis macro will be used in a different ns, in case that matters (because I was having problem trying to use (def *flag* true), etc
23:20hboonok. sounds like that ought to work. Excellent!
23:20hboonwell, just for curiosity sake.. how would I do it if it does throw an exception and catch wasn't catching Exception, but a subclass?
23:21hboonwhat's the functional equivalent of doing it instead of a global flag? (heck I can't even figure out to use a global flag since it's in a macro)