#clojure logs

2011-04-14

00:00Raynesmefesto: I just realized that I forgot all about the interactive tutorial stuff you added to tryclj. I'm working on getting it live now.
00:08technomancyweird; the extra newline seems to only happen on my machine
00:18mecI've got a nested-for macro which returns a nested version of for ;p and I want to add a transform function to apply to each level, wheres a good place to pass this into the macro? https://gist.github.com/901895
00:23amalloymec: isn't that just ##(for [x (range 5) :while (< x 3)] (for [y (range 5) :when (odd? y)] [x y]))
00:23sexpbot⟹ (([0 1] [0 3]) ([1 1] [1 3]) ([2 1] [2 3]))
00:23clojurebotregular expressions is http://www.regular-expressions.info/tutorial.html
00:23mecunforntunatly not, if the nested for is empty you get something like ([1 2] () [1 3] ())
00:25amalloyokay...and that's not desired behavior for some reason?
00:26mecim trying to remember why that was necesary :x
00:26amalloy&(for [x (range 5) :when (odd? x)] (for [y (range 5) :when (odd? y)] [x y]))
00:26sexpbot⟹ (([1 1] [1 3]) ([3 1] [3 3]))
00:27amalloy&(for [x (range 5) :when (odd? x)] (for [y (range 5) :when (= 10 y)] [x y]))
00:27sexpbot⟹ (() ())
00:29amalloymec: anyway, it seems like "filtering out empty sublists" is a pretty small goal that doesn't merit a reinvention of the for macro
00:30mec&(for [x (range 5) :when (odd? x) y (range 5) :when (= 10 y)] [x y])
00:30sexpbot⟹ ()
00:30mecfor doesnt put in nils so i wanted to parallel it, just nested
00:31amalloythat was a bunch of words with no particular meaning afaict. what do you "wish" for did in this case?
00:32meci wanted it to be as if I did some partitions, which wouldnt add empty lists
00:56dnolenad-hoc logic rules are the new type hints and other nutty notions, https://github.com/swannodette/match/wiki/Crazy-Ideas
01:00mechow do you overload [[] v] and [[a & r] v]
01:00amalloymec: you don't overload them
01:00mec^ for dnolen
01:01amalloyheh. i was about to refer to him since it looked like pattern-matching
01:01dnolenthat's not possible at all currently. this what I'm thinking about...
01:01dnolenwell it's actually that works in Logos just fine.
01:02meci guess you could just combine them all and cond on the guards
01:03dnolenmec: cond is too slow. The logic system can prove things and use case when possible.
01:04dnolengoal is something 6-10X faster than multimethods, but more general.
01:14carllercheIs there a way to return a java class from a function and then initialize it?
01:15HavvySo, I want to sum up rand-int done an arbitrary amount of times. I have so far "reduce + ..." but I have no clue how to create the list. Repeat doesn't work since (repeat 5 (rand-int 5)) gives (4 4 4 4 4).
01:16amalloycarllerche: yes, but no good ways
01:16amalloyHavvy: ##(reduce + (repeatedly 4 #(rand-int 5)))
01:16sexpbot⟹ 6
01:22Derander does clojuredocs.org have a more recent db dump than oct 19, 2010?
01:22Derandergoing to a competition soon where api references are allowed but internet access is not
01:26amalloyDerander: you have to print it or something? or can you just bring your repl and use (doc bar)
01:26Deranderamalloy: I want the examples :-)
01:27Deranderslime can do doc no problem
01:33mecif I have a vector of [key val key val ...] how might I dissoc a certain key val
01:35Havvyamalloy: Thanks, once more. XD
01:41amalloymec: by not using vectors
01:45mecah hah, array-map
01:51amalloymec: hearing you mention array-map in the context of dissocing from a vector worries me. i can't think of any good reason to call array-map directly
01:51mecorder matters in this map
01:51amalloythen don't use an array-map :P
01:52amalloy&(dissoc (apply array-map (range 100 200)) 150)
01:52sexpbot⟹ {100 101, 102 103, 104 105, 106 107, 108 109, 110 111, 112 113, 114 115, 116 117, 118 119, 120 121, 122 123, 124 125, 126 127, 128 129, 130 131, 132 133, 134 135, 136 137, 138 139, 140 141, 142 143, 144 145, 146 147, 148 149, 152 153, 154 155, 156 157, 158 159, 160 1... http://gist.github.com/918953
01:52amalloy&(class dissoc (apply array-map (range 100 200)) 150))
01:52sexpbotjava.lang.IllegalArgumentException: Wrong number of args (3) passed to: core$class
01:52amalloy&(class (dissoc (apply array-map (range 100 200)) 150))
01:52sexpbot⟹ clojure.lang.PersistentArrayMap
01:52amalloyhm. it stays as an array-map. i don't think that's guaranteed, is all
01:53HavvyA string is a number. How do you tell clojure that?
01:53amalloy&(class (conj (apply array-map (range 100 200)) 300 301))
01:53sexpbotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer
01:53amalloy&(class (conj (apply array-map (range 100 200)) [300 301]))
01:53sexpbot⟹ clojure.lang.PersistentHashMap
01:54amalloymec: ^
01:54amalloyHavvy: wut
01:55mecanything more than 16 turns an array map into a hashmap
01:55Havvy&(class "6")
01:55sexpbot⟹ java.lang.String
01:55Havvy&(class 6)
01:55sexpbot⟹ java.lang.Integer
01:55mec(Integer. "6")
01:56Havvymec: There is no wrapper around that function?
01:56Havvy*clojure wrapper
01:56mecor if it could be large ##(bigint "6")
01:56sexpbot⟹ 6
01:56amalloymec: do nott rely on ordering of any kind for any kind of map (array or otherwise) unless you create the map with (sorted-map)
01:57mecwell then im back to having to remove the key/val from a vector
01:57HavvyWell, it could theoretically be big, and performance doesn't matter in this case, so bigint it is.
01:58amalloymec: at least store them as single [key value] elements
01:59amalloynot two unconnected key value entries
02:03mecit looks like array-map guarantees itself as long as you dont assoc more than 16 values total, but dissoc will not change type
02:03seancorfieldtechnomancy: saw your note about 1.5.2 - how long before we can expect lein upgrade to pick that up?
02:04amalloymec: guarantees!?! the source may look that way now, but where is it in the contract that this won't change when rich decides that it's more efficient to make the switch at 8, or finds out that array-maps are less efficient for any size at all
02:06mecok ill accept that, the API says it will maintain order as long as it is unmodified
02:17hiredmanerm, it's immutable, you can't modify it
02:29amalloyhiredman: please save me here by (a) figuring out what mec *actually* wants, and (b) suggesting a better way to do it than messing with array-map
02:29mechiredman: assoc/dissoc "modifying" may create a new type on return
02:30meci receive a vector of key vals that need to maintain order. I need to check if a certain key exists, if so get its value and remake the vector without it
02:34amalloymec: i keep telling you, keep [[k1 v1] [k2 v2]], not [k1 v1 k2 v2]. makes everything easier
02:34mecok thats easy enough but how do i remove
02:35amalloy&(into [] (remove (comp #{:bad} key) [[:good 1] [:bad 2]]))
02:35sexpbotjava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.util.Map$Entry
02:35amalloy&(into [] (remove (comp #{:bad} first) [[:good 1] [:bad 2]]))
02:35sexpbot⟹ [[:good 1]]
02:36amalloyskip the into step if you don't need it as a vector, whatever
02:36mecah ok thanks
02:39amalloyand if you do a lot of operations like this, you don't need it as a vector. mess around with it as a lazy-seq for a while, and turn it into a vector for the rare cases where you need frequent random access
02:42mecgood idea
03:16joshua__Finally got lein working again now that I'm back home. I had to wipe my repository folder and re-install lein. I think my lein deps and lein upgrade while on the schools network corrupted the downloads or something. Every checksum would fail.
04:01Deranderjoshua__: I've had all kinds of amazing fuckups caused by the proxy on my high school's network
04:02Deranderjoshua__: it lets some kinds of traffic through and blocks other kinds in random ways
04:02Derandersometimes it blackholes the traffic, sometimes it reroutes it, sometimes it does things that I can't even diagnose
04:59Copehello
05:02hoeckmorning Cope
05:06Copeello - i'm completey new to clojure, but have used ruby and python, so not a programming novice; I want to write a simple binary decision tree that plays a game like '20 questions' - can someone point me to a good place to start hacking?
05:07Copethis is purely for fun, to learn the language
05:10clgvCope: reading "Programming Clojure" or "Practical Clojure" might get you started fast
05:11clgvCope: and I think 20Q is more than a binary decision tree, but you can do a simple version that is only a binary tree
05:12Copeyes the game i want to play is really 'let me guess your animal'
05:12Copewhich is simpler
05:12Copei think
05:12Copeyou dn't need to compress the tree
05:12Copewell its less critical
05:15ordnungswidrighi, how can I enumerate the fields of a deftype?
05:19clgvordnungswidrig: you can't with clojure afaik. maybe you can do it with java reflection
05:20ordnungswidrigclgv: ok, I think I opt for wrapping deftype in a macro and adding this information as metadata to the instance
05:20clgvordnungswidrig: I already did that. wait I can post it
05:21clgvwhich gist do you like?
05:22ordnungswidrigtheres deftype+ on clojars as well
05:24ordnungswidrigclgv: which gist?
05:29clgvordnungswidrig: thats what I use to inspect deftypes http://pastebin.com/0fnkhWdk
05:29raekgist.github.com has syntax highlighting for clojure
05:30clgvordnungswidrig: for using it you just have to do (inspect-type-setup MyDefType) before (deftype MyDefType ...)
05:33clgvups I am missing a definition in it
05:34clgvordnungswidrig: here it is -> http://pastebin.com/kzGGRDip
05:45ordnungswidrigclgv: thanks!
05:50AWizzArdnice
07:20matthias__there's no java program running except swank. or whatever swank runs that is java. the java process is using 500mb ram.
07:20matthias__ive ran a program a couple times, but its not running right now.
07:20matthias__whats going on? :(
07:31clgvIs it not supported to use variable argument lists via "& options" in a parameter list of a defprotocol?
07:32clgvclojure fails at this: (defprotocol IBlubb (get-lala [this & options])) (deftype Blubb [lala] IBlubb (get-lala [this & options] lala)) (get-lala (Blubb. "haha!"))
07:32clgvwith "No single method: get_lala of interface: user.IBlubb found for function: get-lala of protocol: IBlubb"
07:36manutterclgv: does it work if you give it a fixed argument list?
07:36manutter(I don't know much about protocols, but it does sound like variable args might be a problem)
07:37clgvsure. it's pretty default usecase then ;)
07:38Kototamavariadic arguments are not supported for protocols
07:38Kototamayou can create a variadic function that wraps the call to the protocol
07:39clgvoh ok. then it should fail in the protocol or type definition. it's really strange that both of them dont throw any error because of this
07:41Kototamaseems & is recognized like a variable name in this case
07:41Kototama(defrecord B [] IBlub (do [this & options] (prn "& =") (prn &)))
07:41Kototama(do (B.) "titi")
07:41Kototama=> "titi"
07:43clgvoh ok. thats pretty buggy I'd say
07:43Kototamai don't like it neither
07:43clgvbut I have no clue where to report it or where to look if it is already reported
07:46Kototamai think tickets are managed on assembla but maybe it's on github, not sure
07:46clgvwell they should tidy that up.
07:49fogus`awayTickets are at http://dev.clojure.org/jira/browse/CLJ
07:53clgvthx
07:55clgvbut It seems I cant create a ticket
07:58matthias__so does slime keep around the stuff that the program has in ram? i keep starting the program with (start), but of course if im just using a repl, its not actually quitting the program. i think
07:58matthias__so, how do i avoid filling up the ram?
07:59matthias__maybe penumbra has a memory leak somehow
07:59cemerickclgv, Kototama: it's not a bug; records and protocols do not support rest args
08:00clgvcemerick: well than they should throw an error at me and not pretend to be successful ;)
08:02clgvcemerick: not failing on unsupported parameter specification is the bug I wanted to report
08:03cemerickclgv: It's not unsupported -- '& is just-another-symbol in that context, though we're into semantics re: supported/error. You could suggest that '& be disallowed as an arg name there.
08:04clgvcemerick: ok forbidding '& would work as well. but since "& options" has its semantic for "normal" functions, there should be something done to make clear that this semantic isnt supported by protocols
08:05cemerickPerhaps, yes.
08:05cemerickEither that, or rest arg support will arrive for protocols and records.
08:05cemerickThat could be hairy tho.
08:06clgvdoesnt java have a vararg semantic as well? I know C# does
08:06cemerickYes, but it's purely a fiction of javac.
08:07clgvok
08:07cemerickWhich is why calling a vararg method from Clojure requires (.someMethod obj (into-array [your args]))
08:08fogus`javac is delusional
08:09clgvhmm finally found a good decompiler to look at what clojure does: jd-gui :)
09:33edwAnyone here use swank autoconnect? <https://github.com/juergenhoetzel/lein-swank-autoconnect&gt; Not sure how to make it, umm, auto-connect.
09:37leafwhi all. I've just seen the commit on "get rid of checked exceptions". I am curious: what is there to gain by having or not having the "throw Exception" tag on all those java methods?
09:39markomanhow do you make a for i loop with clojure? say (for i = 0, i < 10 (println i))
09:40edwmarkoman: (dorun (map #(write %) (range 10)))
09:41edws/write/println
09:41sexpbot<edw> markoman: (dorun (map #(println %) (range 10)))
09:42edwDoes that answer your question, markoman?
09:43markomanwell for simple println version yes, and thats what i asked, lol. thanks. i need to see, if it applies to inside my function
09:44TimMcmarkoman: (doseq [i (range 10)] (println i))
09:44markomani get confuced because there is a map and i cant access i variable
09:45edwDo you have a paste/gist?
09:45markomansure
09:46markomani should include other design problem on same paste
09:46edwTimMc: Oh, I need to rummage through those built-ins more.
09:48edwIt sounds like you're trying to write C--or worse, PHP--in Clojure, which is sort of beyond the scope of my available time, aside from pointing you to Manning's "The Joy of Clojure."
09:50ejacksonmarkoman: TimMc is on the money
09:52markomanjust a moment, i have a bin prepared if you want to check. yes, i have coded more half of my life with php, so thats where i start, but i know, its different here. i hope to learn alternative and better ways to do things
09:53manutter heh, I'm sitting here coding in PHP for my day job, wishing I could re-write our app in Clojure...
09:54markomanhttp://pastebin.com/gywqw67f
09:54ejacksoncommon wish
09:54markomanmanutter: i know what you talk about
09:54markomanand thats what im partly prototyping on my spare time, heh
09:55manutterSo, in your code, first thing is to use (doseq) not (for)
09:55markomanyes, i think doseq is right thing and easy to put there
09:55manutter(for) is a list comprehension, it returns a seq
09:55TimMcmanutter: Why's that?
09:56TimMcmarkoman: Is form-generate supposed to return something or print something?
09:56markomanreturn a hiccup form
09:56TimMcfor is fine if there are no side effects
09:56markomanill print that later on browser
09:57TimMcdoseq, dorun, and doall are for side effects
09:57markomanhmh, i havent decided if i will use same function not just for :show but also :save form values to db
09:58markomanis that considered side effect?
09:58manutterhmm, spoke too soon--you're right about for vs doseq
09:59manuttersorry, was still thinking in terms of the original question about for i=1 to 10 print i
09:59TimMcmarkoman: A side effect is I/O operations or something.
09:59markomanejackson: "member:TimMc is on the money" ?
09:59ejacksonhis initial comment on using for
10:00markomanit was far too reduced version of my problem
10:00markomansorry about that
10:00manutterSince the function is returning a seq based on a seq, for is the correct choice.
10:00ejacksondoseq, rather
10:03mecmarkoman: https://gist.github.com/919528
10:06markomanmec: oh, good point
10:07markomanyou can use :let inside for especially?
10:08mec,(for [a (range 20) :while (< a 10) :when (odd? a)] a)
10:08clojurebot(1 3 5 7 9)
10:09mec,(for [a (range 20) :while (< a 10) :when (odd? a) :let [b (/ a 2)]] b)
10:09clojurebot(1/2 3/2 5/2 7/2 9/2)
10:09markomanheh, cool
10:10TimMcOh man, I always forget about Lwhile and :when in for.
10:11mecequivalent to much much clearer than: ##(map #(/ % 2) (filter odd? (take-while #(< % 10) (range 20))))
10:11sexpbot⟹ (1/2 3/2 5/2 7/2 9/2)
10:12markomantwisted must be a mind understanding those
10:14mecalso ##(->> (range 20) (take-while #(< % 10)) (filter odd?) (map #(/ % 2))
10:14mec,(->> (range 20) (take-while #(< % 10)) (filter odd?) (map #(/ % 2)))
10:14clojurebot(1/2 3/2 5/2 7/2 9/2)
10:16markoman:) ok, im trying for in this case
10:17Raynesmefesto: Ping me whenever you're around.
10:17leafwhi all. I've just seen the commit on "get rid of checked exceptions". I am curious: what is there to gain by having or not having the "throw Exception" tag on all those java methods?
10:20edwThis `for' macro, it seems, I don't know... Does `for' make heavily-nested higher order function invocations significantly cleaner?
10:21mecbasically
10:21mecbut only when dealing with sequences
10:22AWizzArdedw: list comprehension is what for does. List comprehension can do mapping and filtering.
10:22raeki often find 'for' easier to read when compared to 'map' with an anonymous function
10:23cemerickleafw: then you don't have to bury yourself in mostly-useless try/catch blocks when calling clojure fns from Java.
10:23edwThat's a resounding recommendation! I guess I need to take some of my code that has five or so nested `reduce', `map', and `filter' invocations and re-write it and see if the weird syntactic sugar improves them.
10:24meccemerick: doesnt that also mean clojure fns cant call anything that might throw an exception
10:24cemerickmec: no
10:24mecedw: only thing for cant do is reduce
10:25cemerickmec: checked exceptions are another delusion of javac
10:26mecso how is clojure going to get away with not having them? isnt it compiled through javac?
10:26cemerickgoodness no
10:27cemerickjavac compiles java source, nothing else
10:27edwmec: This reminds me, I wrote a macro that basically lets you chain all those together and not have to read them inside out. I should dig it up; it was pretty useful. Oh, wait, it was basically `>>`.
10:27mecedw: different from -> or ->> ?
10:28leafwcemerick: ok, but that alone doesn't sounds like it would justify such a long and thorough commit.
10:28edwD'oh, typo. s/>>/->>/
10:29cemerickleafw: He had to rip out every unnecessary throws declaration, and every corresponding wrapping of checked exceptions with a RuntimeException for consumption by Clojure fns.
10:29cemerickAs a side effect, stack traces ended up getting a lot lighter, especially for exceptions that occur within lazy seq realizations.
10:30meci've got a >> which basically turns (>> %10 (+ % %) (* 5 %) inc) into (let [% 10 % (+ % %) % (* 5 %)] (inc %))
10:41edwmec: and why?
10:42edwmec: It's interesting, but at some point I feel like we should just go create a Forth compiler for the JVM.
10:43mec,(->> 10 (#(+ % %)) (* 5) inc) ;otherwise you need that nasty anon function syntax somtimes
10:43clojurebot101
10:44markomani got this more complicated now: (for [:let [r (:repeat {:repeat 2} 0)] i (range (if (< 1 r) 0 r) (inc r))] i)
10:45markomanmy purpose is to get (range 0 1) or (range 1 i)
10:46mecmarkoman: can you give an example output
10:47markomanwhen repeat exists and is bigger than 0 then range is 1 to n+1
10:48markomanwhen repeat non exists, then i is 0 and there is only one iteration on loop. so is one iteration only, if repeat = 1, but with range 1 2
10:50markomanoutput is: 0 or 1 or 1, 2 or 1, 2, 3 and so forth
10:51mec,(let [r (:repeat {:repeat 2} 0] (if (< r 2) r (range 1 (inc r)))
10:51clojurebotUnmatched delimiter: ]
10:52mec,(let [r (:repeat {:repeat 2} 0)] (if (< r 2) r (range 1 (inc r)))
10:52clojurebotEOF while reading
10:52markomani dont know how to explain clearly, basically id like to initialize i depending :repeat value and then get (range 0 1) or (range 1 i)
10:53mec,(let [r (:repeat {:repeat 1} 0)] (if (< r 2) [r] (range 1 (inc r))))
10:53clojurebot[1]
10:53mec,(let [r (:repeat {:repeat 5} 0)] (if (< r 2) [r] (range 1 (inc r))))
10:53clojurebot(1 2 3 4 5)
10:53markoman,(let [r (:repeat {:repeat 0} 0)] (if (< r 2) [r] (range 1 (inc r))))
10:53clojurebot[0]
10:54markoman,(let [r (:repeat {} 0)] (if (< r 2) [r] (range 1 (inc r))))
10:54clojurebot[0]
10:54markomanyes, thats what im after
10:55choffsteincemerick: You around? In your rummage library (which I love, by the way), you use ::sdb/id (where sdb is the name for cemerick.rummage), which resolves to :cemerick.rummage/id. I am a bit confused about the double colons and how they work. Mind explaining for a beginner?
10:55cemerickchoffstein: :cemerick.rummage/id is a namespaced keyword, where `cemerick.rummage` is the namespace
10:56cemerickDual colons in front of an otherwise unqualified keyword specify a keyword with a namespace of *ns*
10:56cemericke.g. ##::foo
10:56cemerickhrm
10:56cemerick,::foo
10:56clojurebot:sandbox/foo
10:56choffsteincemerick: Ahhh, I see.
10:57choffsteinIt's messing up my marginalia docs :D
10:57choffsteinThanks for explaining!
10:57cemerickIn ::<foo>/some-keyword, <foo> is taken to be a namespace aliased within the current namespace.
10:58cemerickso, you could (require '[cemerick.rummage :as rummage]) in your lib, and then use ::rummage/id to identify item names, etc.
10:58cemerick::sdb/id seems cleaner, tho :-)
10:58cemerickchoffstein: glad you're liking it, BTW. Any movement on that dependency craziness?
10:59meccemerick: so now clojure wraps all exceptions in runtime exceptions so they dont need to be checked?
10:59markomanmec: works great. huh, it takes time to make functions ready, but I like the result!
10:59choffsteincemerick: Nope. All seems to be on this one network ...
10:59cemerickmec: IIRC, no – 1.3.0-alpha6 (I think?) doesn't do any more wrapping
11:00meccemerick: oh maybe im still understanding it wrong. It looks like if its not a runtime exception it wraps it in one, and just passes that along
11:01raekmec: that's how it was done before the patch, iirc
11:01raekthis "checked exceptions" business is not enforced on the JVM level
11:02mecthrow Util.runtimeException(e.getCause()); was added all over the place
11:57carstenmoin
12:05matthias__hmm, isnt it supposed to be possible to change my program while it runs with slime?
12:05matthias__i've tried recompiling a function that is being called over and over in the program, but nothing changed in the running program
12:05Chousukehm
12:05ChousukeWhy am I on this channel twice?
12:06mecmatthias__: its not with recursion is it?
12:07matthias__no
12:07matthias__why?
12:07clojurebotwhy not?
12:08matthias__how do i change a function in a running program?
12:08matthias__i tried C- C-c
12:08matthias__i mean C-c C-c
12:09meci dont know the whys but if you put #' before the call then redefining it should work fine
12:11raekmatthias__: reevaluating it shoud be sufficient (e.g. C-x C-e or C-M-x for thhe current form or C-c C-k for the current file)
12:11mecHow could I simplify (if a (if b (if c d e) e) e)
12:11matthias__i tried C-M-x
12:12raekare you storing the function in a datastruture, or did you pass it as an argument to a function?
12:12matthias__but the cuntion isn't called by me. im trying to use penumbra, and it gets passed a map with a bunch of functions that are defined in my program
12:12matthias__im trying to change display
12:12matthias__yes
12:12matthias__(im just playing with one of the penumbra example programs
12:12raekmec: (if (and a b c) d e)
12:13raekmatthias__: then you actually store the current value of the var in the datastructure. you can put the var there instead: {:foo #'foo-function}
12:14raekcalling a var will cal the function it points to
12:14raekso when you change the var to point to a new function object (by reevaluating its defn form), penumbra will use the new one
12:14mecraek: what if they were nested if-let?
12:15matthias__ah, now it works. thanks
12:16raekmec: then a simple and would not do :)
12:16mechmm i think I want the maybe monad ;p
12:16raekI've been thinking about making a macro for that
12:17choffsteinIf I am using a jetty server and serve a page that references a js file that is located in "/js/file.js" -- where should file.js be located in my code tree? Should it be in /public/js directory? Just /js?
12:17mecraek: ya I made a when-lets so I figured if-lets would be easy enough, but where do you put the else branch :x
12:17raekmec: brehaut has done some stuff related to this: http://brehaut.net/
12:19raekthis in particular http://brehaut.net/blog/2011/error_monads
12:22mecin order to do it this way I'd have to wrap all of the test exprs in functions would I?
12:24choffsteinanyone having trouble using hiccup 0.3.4? I keep getting an error: Unable to resolve symbol: resolve-uri in this context
12:24choffstein0.3.0 works for me
12:29choffsteini've lean cleaned everything and even wiped my local repo. what da eff.
12:33choffsteinOhhhhhh! Marginalia requires hiccup 0.3.0, and I want 0.3.4 in my project. THAT explains a LOT.
12:34choffsteinIs there any way to qualify which version to use when using in a namespace
12:38choffsteinBecause these two seem to be clashing like a mother-bitch
12:40mecis there a way to tell if maybe-m returned nil from the bindings or if the expression resulted in nil?
12:40technomancywhichever is on the classpath first wins
12:40technomancychoffstein: you can use :exclusions to leave out the version you don't like, though that should happen automatically
12:41technomancysee lein help sample
12:41choffsteintechnomancy, alright, thanks.
12:43choffsteinheyyyyy, it worked!
12:47matthias__what would be the point of running lein compile before lein repl? doesnt repl have to compile everything too?
12:49technomancymatthias__: if you've changed a gen-class or something you might need to
12:50matthias__what's a gen-class?
12:51mecpainful
12:55carllercheI'm trying to understand lazy seqs. Let's say I want to write a function that takes a lazy seq of random numbers and returns a seq of those numbers reduced until they were over five. So (1 4 3 8 5 ...) -> (5 11 5 ...), what would that look like?
12:55tufflaxmatthias__ i think it's when you implement a java class in clojure
13:02meccarllerche: https://gist.github.com/919923
13:03carllerchemec: thanks.. that's better than what I was trying to come up with :P
13:06meccarllerche: i think i can actually use this for something i was working on earlier :D
13:06carllercheheh, nice :)
13:13mechow do i exit the customize screen in emacs? hitting exit and then switching buffers just keeps bringing it back
13:21devnC-x k
13:21mecdevn: thanks
13:21devnAnyone want to work on the SICP in Clojure? Have a regular book club?
13:51mecis there anyway to simplify this, seems like im checking too many edge cases https://gist.github.com/919923
13:55amalloymec: turn if..if into cond, for one
13:57carllerchemec: still updating the function?
13:57mectrying to simplify it, i fixed the problem with it before
13:58amalloybut understanding your algorithm well enough to improve it non-cosmetically is beyond my interests at the moment :P
13:58meccarllerche: you want the bottom one: https://gist.github.com/919923
13:59carllerchewhat's the difference?
13:59carllerchebesides the lazy-loop / lazy-recur?
13:59meclazy-recur is a macro from amalloy's utils
13:59carllercheah
13:59mecerr rather lazy-loop is
14:04mecspeaking of which, amalloy: whats the benefit if implementing lazy-loop with fn instead of just loop?
14:04amalloymec: the whole point is it's not tail-recursive
14:04amalloyyou couldn't do it with a loop
14:05mecwell duh
14:14SaturnationJust checking my understaning... alter takes a reference, a function and optional arguments for the function?
14:15mecyes and it because a call like (apply function @ref args)
14:15mecs/because/becomes/
14:15sexpbot<mec> yes and it becomes a call like (apply function @ref args)
14:16SaturnationOK, not understanding why I'm getting an error along the lines of wrong number of arguments :(
14:16meccopypasta?
14:16Saturnationyeah, I always forget the url :)
14:17Saturnation(alter square-size #(Math/min width height)) where width and height are defined in the enclosing let form
14:17opqdonut_the #()-thing is of arity 0
14:17opqdonut_since it doesn't have a % inside it
14:18opqdonut_but it's getting called with one argument because that's what alter does
14:18Saturnationyes, am I passing any arguments???
14:18SaturnationAh
14:18Saturnationso make a function that calls min an ignores the argument???
14:18opqdonut_yeah, using fn
14:18Saturnationcool, got it, thanks!
14:19amalloywut. you guys are crazy
14:19opqdonut_amalloy: ?
14:19mecif you're doing that you should just (ref-set! square-size (Math/min width height))
14:19amalloyindeed, mec
14:19Saturnationeven better, thanks
14:19opqdonut_yeah, true
14:20amalloybut you should also strongly consider not doing it that way. why is this a ref to begin with? it has various states that are not interrelated at all
14:20amalloyrefs, atoms, and the STM are intended to group several changing states under one constant identity; you seem to be using it to add mutability
14:21Saturnationsee previous comment, just dealing with it for the moment, will eliminate it later
14:21amalloyopqdonut_: by the way, it's also silly to write (fn [_] some-constant-value); see ##(doc constantly)
14:21sexpbot⟹ "([x]); Returns a function that takes any number of arguments and returns x."
14:21opqdonut_sure
14:23Saturnationamalloy, should really deal with it now, thanks for keeping me honest :)
14:23Saturnationand will deal with it now
14:23amalloy:)
14:23SaturnationWhat's the clojure job market like?
14:24amalloySaturnation: we're happy to help with higher-level things: if you want to post the code you have that's doing (i allege) non-idiomatic things someone will take a look and suggest a better approach
14:25Saturnationthanks, trying to learn the language, read "Joy of Clojure" and produce a product all at the same time...
14:25hiredmanclojurebot: mutability |brings| virapinama-dukkha
14:25clojurebotAlles klar
14:26leafwaway Fiu!
14:29Saturnationcrap, Lisp-1 :)
14:29amalloyhiredman: google tells me you misspelled viparinama
14:30amalloySaturnation: lisp-1 is great. i hated having to call (funcall foo)
14:30amalloyand #'bar when i just want the function named bar
14:31Saturnationjust remember that I'm in a Lisp-1 :)
14:31hiredmanamalloy: as it is a transliteration from a non-ascii language spellings are ambiguous
14:31SaturnationI can't really put a let in a proxy, now can I?
14:32dsophas someone encountered NoSuchMethod error org.apache.tools.ant.util.FileUtils.getFileUtils()Lorg/apache/tools/ant/util/FileUtils; ? running leiningen 1.5.1?
14:37SaturnationThank god for JVM first class functions!!!
14:38manutterdsop: I'm not sure if it's the same error, but leiningen 1.5.2 just came out to fix a couple bugs, you might want to try that
14:39dsopmanutter: I have the most recent leiningen
14:39dsopmanutter: in fact it worked with 1.4.1
14:39dsopmanutter: but now I have this strange error. I hva eant 1.8.0
14:40markomanso what is list 1 and lisp 2?
14:41mecclojure is lisp 1, lisp 2 means functions and vars have different namespace so you could do (let [inc 5] (inc inc)) and it would work fine
14:43mecbut you have to do crap like (map #'inc (range 10)) to pass a function or (map #(funcall % 1) [inc dec]) to call a pass function
14:51Saturnationos Clojure's let like Lisp's let or let*?
14:52opqdonut_let*
14:52opqdonut_serial plus you can shadow previous bindings from the same let
14:52Saturnationthat eliminates that explanation :)
14:52opqdonut_yep
14:53mecCL's let is just a function call so its fairly pointless
14:53opqdonut_(let [x (f x) x (g x) x (h x)] x) is a nice idiom ;)
14:54mecI think in that case you're better of just ((comp h g f) x)
14:54opqdonut_mec: I was joking
14:56Saturnationprefix even
14:57meconce you get used to it you'll start screwing up order of precedence in infix math
14:59SaturnationNah, the problem was that I was reading infix as prefix :)
15:02technomancydsop: any plugins that could be interfering? IIRC autodoc bundled a version of ant at one point that was breaking things.
15:03dsoptechnomancy: yes I already commented autodoc
15:03dsopit broked it in the first place. technomancy nosuchmethod on ant seems strange
15:03dsopon an ant method
15:03technomancyif you haven't re-run lein deps it'll still be in lib/dev
15:05dsoptechnomancy: it happen during lein deps
15:05dsoptechnomancy: I removed lib/ and retry, tsill the same
15:06dsopclojure 1.2
15:06dsophttp://pastebin.ca/2046502 << technomancy
15:07technomancyhow about project.clj?
15:14dsoptechnomancy: sec..
15:15dsophttp://pastebin.ca/2046505 < technomancy
15:38technomancydsop: works fine here; maybe a user-level plugin or something
15:47dsoptechnomancy: okay I'll try, thanks
15:51SaturnationIs there any way to develop in the REPL and save the state of the REPL as an application a la Lisp?
15:51Saturnationimage even
15:53technomancySaturnation: no, there are no CL-style images
15:54Saturnationjust finding the develop cycle a bit sluggish compared to Lisp
15:54SaturnationMaybe I need to compile into the REPL?!?
16:18fliebeldnolen: Have you seen this? Constraint solving collision detection. http://altdevblogaday.org/2011/04/11/unexpected-speculative-stability/
16:19dnolenfliebel: yes really cool :)
16:19markomanmec: ok, i think ive seen #'notation on scheme or somewhere earlier
16:22mecmarkoman: probably, in clojure i believe its a reader form for (var something)
16:28amalloy#' is common in common lisp, but means something different than it does in clojure. not sure what it is in scheme, but if it exists i doubt it's the same as either CL or clojure
17:01matthias__what would be your libraries of choice for making a 3d game in clojure?
17:01chouserpenumbra
17:02matthias__im thinking maybe penumbra is too low level. maybe i could use a 3d engine that doenst have clojure bindings. or maybe i'll just stick with penumbra :>
17:02chouserof course I've never made a 3d game in clojure, nor used penumbra, so it would probably be best to ignore me.
17:02matthias__heh
17:02chousermatthias__: LauJensen did something with "monkeyengine" or some such.
17:03LauJensenJMonkeyEngine is so sweet. However I recall a news on disclojure recently where I saw that somebody had outdone me
17:03matthias__someone made something called clj3d. dont think the name was jaujensen though
17:03matthias__what did you make with jmonkeyengine?
17:04LauJensenI had a beautiful island sitting in a troubled see, with clouds floating above and a giant sphere which you could control :)
17:04Apage43I've used straight JOGL for a game before
17:04Apage43not with clojure though
17:05Apage43my game wasn't 3d either.
17:05matthias__oh, you're the bestinclass guy
17:09LauJensenright
17:09amalloyhey, haven't seen LauJensen around recently
17:10devnheya lau
17:10znutar_does JOGL give much abstraction beyond just a binding for opengl calls?
17:10LauJensenHi guys
17:10matthias__penumbra is that much more than a wrapper for opengl either i think. well it can also draw text and open a window and get input and stuff
17:11matthias__why did you call your website "bestinclass"? :|
17:12LauJensenmatthias__: You're the first guy to ask me :) A decade ago I was working with the backoffice for a dell support team in Copenhagen. We grouped the individuel agents into Worst of Breed, Middle and Best In Class. I liked that predicate so much that I figured I wanted an email with that name. 6 years later I wanted to boot up a company to make some fast money and since I already had the domain, it seemed simple just to run with it... and
17:12LauJensenhere we are :)
17:13matthias__makes you sounds a bit arrogant :p
17:13LauJensenmatthias__: Only arrogant people read it like that actually :)
17:14matthias__no u r >:(
17:14matthias__:p
17:14devnmatthias__: are you matt g?
17:14matthias__no
17:14matthias__i'm matt l
17:14devnnevermind! :)
17:14matthias__who's matt g?
17:14devnanother cool guy, like yourself
17:19matthias__i've been looking at clj3d, but im not even sure if you can make games with it. seems like all it does is cisplay some shapes
17:20LauJensenJust hook into JMonkeyEngine directly then. Its fairly straightforward
17:21matthias__i'll look into it
17:21LauJensenI said HOOK
17:22matthias__:D
17:29amalloymatthias__: good news: complex shapes are built out of simple shapes
17:31matthias__it does draw complex shapes. im not sure if it does anything else though
17:31amalloywhat more do you want from a 3d graphics engine? graphics engines draw shapes
17:32LauJensenmatthias__: I get the sense that you're looking for something like "(defn game [] (portal2/createFromScratch))" amirite? You should check out Visual Studio Gamers Edition :)
17:33meci would settle form a portal2/GiveMeAKeyRightNow
17:34matthias__well why would i switch to something that does less than what im using now (which is penumbra)?
17:34matthias__im not sure if clj3d is suitable for games even. i just dont really get what it can do or not
17:35matthias__im not even sure that i want something that does more than penumbra. just checking out all the options
17:41devnthe reason to switch or not is revealed by attempting to switch :)
17:43LauJensenGood night all
17:44matthias__night
17:52leedaThis is hard to search for, what does #() do?
17:55amalloyleeda: #(inc %) is (fn [x] (inc x))
17:55leedaamalloy: ah, thanks
17:55matthias__http://clojure.org/cheatsheet
17:55leedacool
17:55hiredman#(inc %) is inc
17:55amalloyhiredman: yes, obviously
17:56amalloybut it's an easy way to explain the syntax
17:56amalloyleeda: you can even try macroexpanding it: ##(macroexpand '#(+ (dec %1) (* 3 %2)))
17:56sexpbot⟹ (fn* [p1__19724# p2__19725#] (+ (dec p1__19724#) (* 3 p2__19725#)))
17:57dnolenleeda: note that you can't nest #()
17:57leedacool
17:58raek,(read-string "#(+ (dec %1) (* 3 %2))")
17:58clojurebot(fn* [p1__279# p2__280#] (+ (dec p1__279#) (* 3 p2__280#)))
17:59raekactually, it's done at read-time
17:59raek,'#(+ (dec %1) (* 3 %2))
17:59clojurebot(fn* [p1__281# p2__282#] (+ (dec p1__281#) (* 3 p2__282#)))
20:36TimMc$findfn \f "oo" "bar" "foobar"
20:36sexpbot[clojure.core/str clojure.contrib.string/as-str]
20:51kephale00Is there a parallel juxt?
21:20amalloykephale00: juxt is a special case of map. write pjuxt with pmap, if you want
21:20kephale00sure, thats what i do
21:21kephale00it just struck me as amusing
21:21kephale00: P
21:22kephale00err… i dont have it written as pjuxt though. i may have to poke around at that
21:30kephale00amalloy_: interestingly enough juxt isn't written with a map though
21:42mecmainly for performance: (defn mjuxt [& fs] (fn [& args] (map #(apply % args fs))))
21:43kephale00mec: aha
21:48mecs/args fs)/args) fs/
21:49mecaw sexybot fail
21:55amalloymec: i don't think either of us has sufficient knowledge to assert that juxt isn't written with map for performance, although i agree it's likely
21:56amalloyit might be because someone wanted to make sure that juxt wasn't lazy
21:56mecif all of those werent written out by hand for performance, than someone just likes to type a lot
21:57amalloymec: oh, the variadic unrolling is for performance, sure
21:57mecya
21:59amalloymec: incidentally, if that bugs you, rich would love for someone to figure out a way to write a macro generalizing the unrolling of comp, juxt, and family
21:59mecchallenge accepted
22:00amalloyi spent a while working at it but couldn't find a way to make the use of the macro less complicated than the expansion :P
22:00kephale00heh
22:00amalloymec: sweet. you'd win my heart
22:06amalloyhas anyone been reading the "lock-free algorithms" series raymond chen is running over at the old new thing? seeing all that pain invested in inventing (atom nil) makes me love my language
22:06mecim thinking something that looks like (unroll num-args1 num-args2 gen-case-expr)
22:07amalloymec: really? seems cleaner to me to only have num-args, and make juxt/comp use unroll twice
22:08mecso (def juxt (unroll [1 2 3] [0 1 2 3] (reduce #(conj %1 (apply %2 x y z args)) [] fs))
22:08mecamalloy: true, they do both have the same args pattern
22:09amalloybut see eg (source map), which unrolls only one thing
22:12mechuh i wonder why doseq and for dont have helper functions
22:13amalloy$source for
22:13sexpbotfor is http://is.gd/7z5P5L
22:15amalloyor just write (defmacro doseq [& args] `(dorun (for ~@args))) :P
22:15mecya pretty much
22:31mecis there a way to remove with clojure.walk/postwalk
22:37hiredmanyou want zippers
22:37hiredmanclojure.zip
22:52mechmm i got partial but unroll is already a nasty beast
23:10dnolenerg how do you get symbols in a macro macro?
23:11hiredmandnolen: what do you mean?
23:13dnolenhiredman: https://gist.github.com/921056
23:14hiredmanuh
23:14hiredmanyou only need a single level of `
23:14dnolenhiredman: the internal macro doesn't need the syntax quote?
23:15hiredmansyntax quote expansion happens at read time, the reader can't tell the difference
23:15hiredmanyou only have multiple levels of syntax quote when you have levals of unquote between
23:15hiredman`~`
23:15dnolenhiredman: so I just need to return a list from the macro?
23:16hiredman(list ...)
23:17hiredmanwell, actually
23:17hiredmanyou are better off doing `~`
23:19hiredmanbut you will need to manage gensyms your self
23:20hiredmanyou could also pull the inner macro out in to a function
23:26livingstonkinda stupid question: in ns bar I have (fn [foo] `(baz ~foo)) when I run that I get bar/baz as the first symbol I really want just baz with no ns... how do I do that?
23:27mec(list 'baz foo)
23:28pdk,'baz
23:28clojurebotbaz
23:28pdk,`baz
23:28clojurebotsandbox/baz
23:28livingstonno way to do it with the backquote because that's really convenient for building up big lists etc.
23:29pdk,`'baz
23:29clojurebot(quote sandbox/baz)
23:29pdkwelp
23:29mec,`(~'baz ~foo)
23:29clojurebotjava.lang.Exception: Unable to resolve symbol: foo in this context
23:29mecgotta be careful of symbol capture when you do that tho
23:30livingstonwhat would it capture?
23:31livingstonI actually want just plain old baz in there not it's value or anything, just the symbol
23:31mec~'baz will give you the symbol in a syntax-quote
23:31clojurebothttp://clojure.org/data_structures#toc10
23:33livingstonthat seems like all I want then.
23:34livingstona little extra hackery that I don't really like though kinda defeats the advantage of the backquote (in my case) if I then have to tilde quote a "plain" symbol
23:38amalloylivingston: why would you want baz there if you don't know what function it refers to?
23:39livingstonamalloy: symbols are the data in my case
23:39livingstonI just want lists of symbols
23:39amalloylivingston: then i'd write foo as (partial list 'baz)
23:40livingstonamalloy: in this case foo is a gross over-simplification of what's actually going on
23:40amalloyheh
23:42livingstonI do symbolic AI, so my data is things like (livingston programs-in-language clojure) or (Colorado has-capital Denver)
23:42livingstonsymbols as data is a fairly natural fit here, or at least they were when I programmed in common lisp, I'm assuming the same thing will work well here
23:44amalloylivingston: sure. less common but viable
23:44livingstonso the inventors of lisp were all AI hackers, they did this all the time ;)
23:46cemericklivingston: why not use keywords and vectors -- if it's data you're working with, that strikes me as much more clojure-idiomatic…
23:46mec^^
23:46cemerickI obviously don't know what you're up to :-)
23:46amalloylivingston: i was going to suggest vectors too, or perhaps maps
23:47livingstonvectors / lists - I don't see that that matters much?
23:47amalloyi don't see any particular reason to use keywords though. maybe '(colorado :has-capital denver) - like a keyword for the structural data, symbols for the meaningful data
23:47amalloylivingston: vectors are easier to build data out of
23:48amalloybecause they have literal syntax
23:48cemericklivingston: vectors evaluate to themselves, lists require quoting. Similar to how keywords evaluate to themselves, while syntax-quoted symbols interpolate *ns* as you've seen.
23:48livingstonas far as keywords most things do actually have a ns, at least all the data it would be things like (gene/EG_182 ro/isIndirectTemplate uniprot/A23P56) ...
23:49cemerickkeywords may be namespaced as well
23:49amalloycemerick: good point about syntax-quoting symbols
23:49cemerick,:gene/EG_182
23:49clojurebot:gene/EG_182
23:49livingstonin RDF (semantic web representation) things have namespaces and names (sounds like symbols) ... so I'm just bringing them in that way
23:49cemericker
23:49cemerick,(namespace :gene/EG_182)
23:49clojurebot"gene"
23:50livingston,(name :gene/EG_182)
23:50clojurebot"EG_182"
23:50amalloy&[`[a :a] (list 'a :a))
23:50sexpbot⟹ [[clojure.core/a :a] (a :a)] ; Adjusted to [(clojure.core/apply clojure.core/vector (clojure.core/seq (clojure.core/concat (clojure.core/list (quote clojure.core/a)) (clojure.core/list :a)))) (list (quote a) :a)]
23:50livingstonoh
23:50cemerickSymbols are fundamentally intended to refer to things, usually vars. Keywords are "just data".
23:50livingstonI thought it would write with a ":" somewhere in there?
23:50cemerick(not really, but in the scope of this conversation…)
23:50amalloycemerick: "usually vars" seems like an overbid to me
23:50cemerick":" is just reader syntax
23:51cemerickamalloy:
23:51cemerickfeh
23:51cemerickamalloy: "overbid"?
23:51amalloy*laugh*
23:51amalloycemerick: i'm a bridge player :P
23:51cemerickah
23:51cemerick"a bridge too far" perhaps :-P
23:51amalloycemerick: i'll tell all your friends you write all your code with global vars, no local bindings
23:52cemerickha
23:52cemerickactually, that's true :-P
23:52livingstonI guess I could use vectors... actually there's nothing about my code currently that would disallow it - it all uses sequences (I think?)
23:53cemerickamalloy: I view let-bindings as something less than interned vars. Because the name is entirely local, it's largely irrelevant.
23:53livingstonis there any advantage to keywords? other than the non-quoting ?
23:53cemerick"less than" re: a lesser variety of "reference"
23:53amalloylivingston: people will be able to read your code
23:53amalloy(har har)
23:54livingston'(far bar baz) is no less readable than [:foo :bar :baz] and arguably more so
23:54cemerickI find the quote character really distracting, actually.
23:54cemerickSitting haughtily so far above the baseline.
23:55livingstonit's a very clear flag that we're talking data. I find the absence of one but no evaluation disturbing ;)
23:55amalloynot like the trusty colon, propping up the data it represents
23:56amalloylivingston: but you're not really talking data. you're trying to interleave data with operations using syntax-quote
23:56cemerickYeah, you can rely on the colon, salt of the earth as it is. It's even got built-in redundancy, so you know it'll scale.
23:56livingstonis there anything fundamentally extra effecient for keywords vs. symbols (I'm assuming a keyword is just a symbol with more crap on it, right?)
23:57amalloykeywords evaluate faster and look themselves up in maps faster
23:57amalloybecause they're interned, they use identity to mean equality
23:58amalloy&(identical? :a :a)
23:58sexpbot⟹ true
23:58amalloy&(identical? 'a 'a)
23:58sexpbot⟹ false
23:58livingstonthe reason I was using the syntax quote is things like this: `((~ice iao/IAO_0000219 ~gene) (~gene rdfs/subClassOf so/SO_0000704)) to create a list of rdf triples quickly, using a template that I have some of the values for and some come in from a function call or something
23:59amalloylivingston: so? [[ice :ioawhatever gene] [gene :rdfswhatever :sowhatever]]
23:59livingstonso a quoted symbol is never interned?
23:59chewbran1atechnomancy: ping