#clojure logs

2010-12-27

00:00qbgAnd also for the fact that they queue up actions
00:00Guest32627qbg: i guess combined with an error handler on your agent to make sure errors get logged to, that works pretty well
00:01Guest32627qbg: sure, the queueing is a necessary part of the asynchronous processing. just like an MDB :)
00:01Guest32627well... one attached to a queue anyway, not a topic :D
00:03qbgHmm... Not sure if I'll be able to add some basic syntax-class support to my syntax-rules/syntax-parse mashup tonight
00:08qbgBinding *ns* in a test feels nasty
02:17killy971Hello, I'm looking for some help on macros. I would like to make a factorial function with pre-calculated results (for just a few values). I got some help a while back, and have the following piece of code:
02:17killy971(defn static-fact [digit] (let [x 'x] `(case ~x ~@(mapcat (juxt identity fact) (range (inc digit))))))
02:17killy971(static-fact 10) yields the following result in the repl: (clojure.core/case x 0 1 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320 9 362880 10 3628800)
02:17killy971What I would like then is to make a function/macro from this result.
02:18killy971(given that I have already defined the fact function)
02:20tomojkilly971: the reason is that you will be calling static-fact ofter with low values?
02:20tomojs/ofter/often
02:20sexpbot<tomoj> killy971: the reason is that you will be calling static-fact often with low values?
02:20killy971yes
02:20killy971actually just digits
02:20tomojhave you considered memoize?
02:21killy971but I was wondering how to write some clever static code, instead of memoized or verbose long case
02:21tomojoh, just to try it out?
02:21killy971yes, I have never really used macros until now, so I thought it could be a good occasion
02:25killy971I don't really understand how to stick my code in the definition of a function "digit-fact", which could be used like this: (digit-fact 3)
02:29tomojI think you're right that this is a nice simple experiment
02:29tomojbut my brain isn't working right now
02:29tomojhave you ever used defmacro before?
02:30tomojI mean, successfully, at all?
02:30Scriptormacros are fun
02:31Scriptorkilly971: what exactly are you trying to do?
02:31killy971tomoj: I mean, successfully, at all?> just read stuart holloway book
02:32killy971Scriptor> writing a succinct factorial function with pre-computed results (for digits)
02:33killy971so I would like to use the macro facility to generate the part (case 1 1 2 2 3 6 4 24 ...)
02:33killy971I already have the following piece of code : (defn static-fact [digit] (let [x 'x] `(case ~x ~@(mapcat (juxt identity fact) (range (inc digit))))))
02:34killy971it yields the case part if I execute it in the repl like this (static-fact 10)
02:34tomojclojurebot: hygiene?
02:34clojurebotCool story bro.
02:40tomojhuh
02:40tomojwow
02:43killy971any idea of how to do this?
02:43tomojwell
02:43tomojI have a gist with a shitty answer
02:44tomojhttps://gist.github.com/f04db48b5f33d4810de2
02:44tomojsticking (range n) and (resolve f) in there seems wrong to me
02:46killy971I'm looking at the code
02:48killy971great, it works as expected. but why do you say (range n) and (resolve f) seems wrong?
02:49tomojjust seems odd
02:49tomojalso, suppose I want to caseify not with a range from 0 but with some other seq of input vals
02:49amalloytomoj: resolve definitely seems like it shouldn't be necessary; i agree about range
02:49tomojI tried that originally, but you'd have to eval the form they pass in or something.. ugly
02:50amalloyinstead of n, accept a seq
02:50killy971oh if you mean this
02:50killy971ok
02:50tomojamalloy: yeah.. and do what with it? it's a macro
02:50amalloyoh, hm
02:51tomojif it's a vector, you'd want to just go with those vals. if a list, eval would get you the right answer, but..
02:51tomojlist or symbol, I guess..
02:55killy971thank you for the gist, at least it solves my prob
04:03zvrbahmm, how does equality work in clojure? what semantics does = have, when compared to CL? eq? eql? equal?
04:03zvrbaah, found it in the docs: it's value comparison.
04:04zvrbabut given that data structures are immutable, is "value" comparison in this case implemented as identity comparison?
08:03mrSpecHello! Could you tell me why (let [h my-hashmap] ...) is working, but (let [h (eval (read-from-string "my-hashmap"))]...) is not? this eval seems to work in REPL but not in the function :(
08:14ChousukemrSpec: eval can't access locals. what is it that you're actually evaling?
08:14mrSpecit is global hashmap
08:15mrSpec(def hash (new java.util.LinkedHashMap))
08:15Chousukealso, what is the error?
08:16mrSpechere is the problem... I cant see the error, Jslider is just not working
08:16Chousukehmh
08:16Chousukeyour problem is probably using eval in the first place :P
08:16mrSpecok I've used (if ...) instead of eval...
08:17Chousukebut I can't really suggest anything better since I don't know what you're trying to do.
08:17mrSpecok
08:17mrSpecunfortunately i'm in rush. so I'll ask about this later, and tell more :)
10:43chouserugh. maven fail. http://tinyurl.com/2b6azmz
11:51drewolsonhey all. suppose i wanted to store a java.util.Random in a ref and call the .nextInt function on it inside a dosync. I'm assuming simply calling (dosync (.nextInt @*rand*)) will not actually be synchronous because i'm not using alter or commute. is this correct?
11:52qbgIt will be executed
11:52qbgBut .nextInt has side effects, so you shouldn't use it in a dosync
11:53qbgWhy do you want to use dosync here?
11:53drewolsonqbg: i want to ensure multiple threads can generate distinct random numbers. i may be completely off here.
11:54qbgIsn't .nextInt already synchronized?
11:54drewolsonqbg: it may well be, i'm not sure.
11:54qbgNo
11:55qbgDoesn't appear to be
11:55drewolsonqbg: so i'd like to access it sychronously, but i'm not sure how to do that using alter/commute.
11:56qbgSounds like (locking @*rand* (.nextInt @*rand*)) should work
11:56drewolsonqbg: i'll look into locking, thanks for the help
11:56qbgBut there is little reason to have a Random in a ref
11:57qbgAnother thought: why share the one random object between multiple threads?
11:58drewolsonqbg: i probably won't eventually, i just became curious about accessing a java instance concurrently with methods with side effects.
11:58qbgThe STM only works on refs, not java objects
11:59drewolsonqbg: great, thanks for the help
12:19amalloydrewolson: i agree with qbg that locking is probably the best choice here, but you might be interested in java.lang.ThreadLocal for other, similar things
12:32LauJensen,(str (java.util.UUID/randomUUID))
12:32clojurebot"fee8a2e9-b286-40fb-a9be-bac7c8ba3fb3"
12:32LauJensendrewolson: If you dont specifically need an int, the above will guarantee a unique return on each call. If you need an int, call hash on the result
12:33LauJensenNo locks, no nothing
12:38LauJensenamalloy: Did you catch that? :)
12:39amalloyLauJensen: heh. that's an amusing use of uuids
12:39LauJensenamalloy: its called: creative
12:39amalloyah, of course. that's what i meant. creative
12:55drewolsonamalloy, LauJensen: thanks for your help
12:56LauJensennp
13:49dnolenqbg: yeah *file* + &form is enough I think. Now I'm excited :D
13:50dnolensyntax-rulez!
13:51dnolencemerick: I did as well. But once you've internalized CL style macros. syntax-rules sounds like heaven. It's much less noisy and covers the common cases.
13:51qbgThey only look hard :)
13:52cemerickdnolen: Perhaps that's it -- the last time I used scheme in earnest, it was before I had properly grokked CL-style macros.
13:55dnolenthe thing I like about syntax-rules is that it eliminates common cases that require splicing. You can specify patterns.
13:55qbgJust pushed out the line number stuff
13:55dnolenqbg: sweet
13:56dnolenqbg: the moment you push a stable release to clojars, I'm going to replace my ugly logos.minikanren macros with syntax-rules :)
13:57qbgI also mailed my CA form today
13:59qbgThe downside of the current error messages is that the filename and line number are part of the message, so you also have the filename and line number provided by the JVM which is separate...
13:59qbgI wonder if I could make that be correct instead...
14:01qbgNow I just need to implement guards and add a form for defining syntax classes
14:01qbg(and define a ton of built in syntax classes)
14:03qbgIs there a function that is equivalent to (first (filter ...))?
14:09amalloyqbg: i don't think so. there's (some), but that gets you (f x) instead of x
14:10qbgIt seems like it could be a useful function to have (for communicating a concept)
14:11amalloyqbg: i agree. i've written (first (filter ..)) enough times that it ought to be abstracted out
14:12qbgWhat would it be called? some is already taken
14:26dnolenqbg: pick?
14:27amalloyqbg: (only even? (range))?
14:28qbgIt should make sense in context of (if (<name> ...) <stuff to do if there is at least one such element>)
14:28aqcljhello
14:28qbgamalloy: only implies filter to me, not (first (filter ...))
14:29qbgpick might work, but I feel it is a bit lacking
14:30qbgfind?
14:30qbgI think that is what it is called in CL
14:30stuartsierra`find` is taken
14:30qbgOh, yes
14:31qbgIt is called find-if in CL
14:31Obviousfind-if
14:31Obviousyep
14:32qbgMaybe find-pred?
14:32qbgNot as nice as a single word though...
14:32amalloystuartsierra: since you mention it, why does find exist? it looks like get is a perfect drop-in substitute
14:33stuartsierra`find` returns the actual Map.Entry, not just the value.
14:36aqcljHi, I have something like: (["x" LazySeq] ["x2" LazySeq] ...). I would like to get the first n bigger values from all the LazySeq. Any ideas?
14:36LauJensenAny brilliant webdesigners in here, who would like to contribute either a design or a mock for clojureql.org ?
14:37qbgaqclj: Could you give sample input and output?
14:37aqcljyes
14:38aqcljthe input would be the above sequence, and the LazySeqs are sequences of numbers
14:38aqcljand as output I would like to have the number of times "x" got the bigger number, and so on
14:39aqcljI know how to get the bigger value each time, but I don't know how to make the loop, and to select the next value in the LazySeq
14:41qbgI think I see what you want
14:42stuartsierraUse `map` to return a sequence of "x"s or "x2"s representing who had the bigger number each time. Then call `frequencies` on that result.
14:45aqcljthanks, I'm trying that now (I'm slow)
14:45qbghttps://gist.github.com/756469 maybe?
14:45qbg(could be better)
14:47qbgActually, that is going to be smallest...
14:47qbgFixed
14:49aqcljthe code got stuck, like in a infinite loop
14:49aqcljmaybe it's because my lazyseq has no ending :S
14:50qbgIt does it for all values, not only the first n
14:50qbgfixed
14:51qbgThat code could be much better
14:53aqcljthanks, I'm trying to understand it now. It seems that something goes wrong, but now it doesn't get stuck
14:53qbgIt could be that I'm misunderstanding what exactly you want
14:55aqcljat each loop, the bigger value within all the lazyseqs should be replaced by the next in the sequence
14:55BerengalDoes putting anything inside a do at the toplevel make a difference?
14:56qbgBerengal: I don't think so
14:56qbgaqclj: Is this for sorting or something?
14:57qbg(like a merge sort)
14:57aqcljmore or less
14:57aqcljfor example
14:57Berengalqbg: Thanks
14:58BerengalAlso, what's the prefered idiom for updating a single value in a map/struct?
14:58qbgassoc
14:58amalloyBerengal: update-in
14:58amalloyor assoc, depending
14:58Berengalamalloy: assoc makes a new entry, doesn't it?
14:58amalloyBerengal: overwriting any previous entry that was there
14:58qbgYes, maps/structs are immutable
14:58aqcljif the lazyseq for "x1" is (10 8 4 2) and the lazyseq for "x2" is (33 9 2 1), and I ask for 3, I should get "x1" 1 and "x2" 2
14:59qbgaqclj: I would first write a function that returns a sequence of "x1"/"x2"/etc., then take n of them, and then pass that to frequencies
15:00amalloyso if you want to "update" the value to, say, 4, you should just (assoc m k 4); if you want to change the value based on its current value, you want (update-in m [k] function-of-value)
15:00Berengalqbg: That's okay. I don't want to mutate, I just want a slightly modified value, based on the previous value at an entry
15:00Berengalamalloy: Thanks, that looks like it
15:00qbg,(assoc {:a 1, :b 2} :a 5)
15:00clojurebot{:a 5, :b 2}
15:00amalloy&(update-in {:a 1, :b 2} [:a] inc)
15:00sexpbot⟹ {:a 2, :b 2}
15:01aqcljqbg: but that it wouldn't be lazy, would it? At each loop I should only ask for the next value in the lazyseq that got the max value
15:02aqcljor I am wrong? :S
15:02qbgaqclj: Define that function to use lazy-seq
15:02qbgAnd use recursion
15:03aqcljok thanks, I will try that
15:05qbgaqclj: Updated the gist to have that function instead
15:05qbg(assumes the input is a map)
15:08aqcljthanks again, I'm trying it
16:04DanielGlauser /msg NickServ identify 1l2gbOGH
16:05dakroneDanielGlauser: time to change that password :)
16:05DanielGlauserOh crap
16:05DanielGlauserI guess it is :)
16:05qbgWhat? I only see ********
16:05qbg;)
16:08qbgEww, I just used eval...
16:27ngwwhat libs are available for s3 and aws in general ?
16:28cemerickngw: jclouds has the deepest support for aws AFAIK (and provides clojure wrappers for much of it)
16:29cemerickdisclaimer: I'm a contributor there
16:30ngwthanks
16:35DanielGlauserPhew, I changed my password
16:36DanielGlauser /msg NickServ identify abc123
16:40qbglolz
16:42qbgAlmost got guards ready for my syntax-rules/syntax-parse mashup. I just need to make sure that the code in the guards will be namespace properly
16:42qbg*namespaced
16:45qbgHmm... Maybe binding *ns* around eval would be good enough
16:53ngwany suggestion about how to structure a project in clojure ?
16:53ngwI'm messing (and I mean it) with leinigen but coming from ruby/python it's kind of confusing
16:54amalloyngw: cake is similar to leiningen but uses a little ruby underneath; not sure if that's helpful
16:54ngwfor example I just discovered there's a -main function, something that none of the books I've read about clojure mentions it
16:55amalloyngw: -main isn't special, per se. -foo is how to create a MyClass.foo() method when AOT compiling
16:56pdkyknow i should get around to installing cake or lein
16:56pdkthough how is the installation process on windows
16:56amalloybut both of them have a project.clj file in the project root to do configuration and management, and you can find a reasonable reference to that file format at http://is.gd/jAFJV
16:58aqcljI have a sequence of maps called m, when use (into {} m) it only returns one of the maps. How could I get all the maps outside the sequence so I can use the merge-with function?
16:59amalloy&(apply into {} [{:a 1} {:b 2, :c 3}])
16:59sexpbotjava.lang.IllegalArgumentException: Wrong number of args (3) passed to: core$into
17:00amalloy&(apply merge-with + [{:a 1} {:b 2, :a 3}])
17:00sexpbot⟹ {:b 2, :a 4}
17:00amalloyaqclj: ^^
17:01aqcljamalloy: thanks a lot!
17:01aqcljwhat the & do?
17:01amalloyaqclj: asks sexpbot to evaluate for me
17:02aqcljah ok
17:02Luyt_is it possible to have clojurebot do a deathmatch with sexpbot?
17:05Luyt_&(println ",(doc doc)")
17:05sexpbot⟹ ,(doc doc) nil
17:05qbg,(println "&(println \"Foo\")")
17:05clojurebot&(println "Foo")
17:05sexpbot⟹ Foo nil
17:06qbgNow to quine it...
17:06Luyt_qbg - Luyt: 1-0 !
17:06Luyt_I tried to fool sexpbot into luring clojurebot out, that failed, you tried it the other way, that worked.
17:07qbgYeah, sexpbot is going to make this hard...
17:07Luyt_sexpbot's output always starts with ⟹ and as such can never get an answer out of clojurebot.
17:07qbg&(println "\n,(doc doc)")
17:07sexpbot⟹ ,(doc doc) nil
17:07RaynesI've done my part. Any exploitation will be on clojurebot. Thus, I void all responsibility. ;)
17:07amalloyLuyt_: sexpbot was carefully designed to prevent this :P
17:07Luyt_Good thing ;-)
17:08qbg&@(future (println ",(doc doc)"))
17:08sexpbot⟹ nil
17:08Luyt_Now, what if clojurebot responded to ",(...)" and sexpbot to ",,(...)" (note two comma's instead of one)
17:08Raynesamalloy: Haha "carefully designed". More like horribly designed until _ato broke it in every which way imaginable and forced me to fix it... carefully. :>
17:09amalloyRaynes: carefully designed /eventually/
17:09RaynesThat
17:09qbg&(let [i *in*] @(future (binding [*in* i] (println ",(doc doc)"))))
17:09sexpbot⟹ nil
17:09Raynesis better.
17:09qbg&(let [i *out*] @(future (binding [*out* i] (println ",(doc doc)"))))
17:09sexpbot⟹ ,(doc doc) nil
17:09Raynesqbg: You can also experiment with sexpbot in PM or in #sexpbot
17:09RaynesIn case it gets too floody for #clojure.
17:11Luyt_First versions of my programs always look a bit clumsy. Only after reshaping them they become a bit elegant. Like a clump of clay you have to sculpt and refine.
17:11qbgsexpbot wins this round...
17:12qbgLets not quine clojurebot...
17:21jlaskowskihi
17:21jlaskowskiI'm having troubles with java.lang.IllegalArgumentException: No matching method found: createInjector
17:22jlaskowskiCLASSPATH=`pwd`/guice/guice-3.0-rc1.jar:`pwd`/guice/javax.inject.jar:`pwd`/guice/aopalliance.jar clj -13
17:22jlaskowskiCLOJURE_DIR: /Users/jacek/apps/clojure
17:22jlaskowskiCLOJURE_CONTRIB_JAR: /Users/jacek/apps/clojure-contrib-1.3.0-alpha3.jar
17:22jlaskowskiClojure 1.3.0-alpha4
17:22jlaskowski(def mm (proxy [AbstractModule] [] (configure [] (println "configure called"))))
17:22jlaskowski(bean mm)
17:22jlaskowski{:class user.proxy$com.google.inject.AbstractModule$0}
17:22jlaskowskiand when I call (Guice/createInjector mm)
17:22jlaskowskiit spits out the exception
17:23jlaskowskihttp://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/AbstractModule.html
17:23jlaskowskihow can I find out what is wrong exactly?
17:24jlaskowskihow do I find out what Clojure can call upon a class?
17:24jlaskowskiany helpful reflection methods to use?
17:25amalloyjlaskowski: createInjector takes an array of Modules, not a single module
17:25amalloyjava's Foo.bar(Whatever...) is sugar for arrays
17:25jlaskowskiright
17:26jlaskowskibut have a look at the full stack trace
17:26jlaskowskiuser=> (.printStackTrace *e)
17:26jlaskowskijava.lang.IllegalArgumentException: No matching method found: createInjector
17:26jlaskowski at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:77)
17:26jlaskowski at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:202)
17:26jlaskowski at user$eval17.invoke(NO_SOURCE_FILE:4)
17:26jlaskowski at clojure.lang.Compiler.eval(Compiler.java:6201)
17:26jlaskowski at clojure.lang.Compiler.eval(Compiler.java:6168)
17:26jlaskowski at clojure.core$eval.invoke(core.clj:2680)
17:26jlaskowski at clojure.main$repl$read_eval_print__5619.invoke(main.clj:179)
17:26jlaskowski at clojure.main$repl$fn__5624.invoke(main.clj:200)
17:26jlaskowski at clojure.main$repl.doInvoke(main.clj:200)
17:26jlaskowski at clojure.lang.RestFn.invoke(RestFn.java:422)
17:26jlaskowski at clojure.main$repl_opt.invoke(main.clj:266)
17:26jlaskowski at clojure.main$main.doInvoke(main.clj:361)
17:26amalloyaugh do not do that
17:26amalloyhttp://gist.github.com
17:26jlaskowskiamalloy: ok, will use it
17:27amalloyanyway, yes. it can't find a method with that name whose parameters are (Foo), only one whose parameters are (Foo[])
17:28jlaskowskiyou're right!
17:28lancepantzdoes anyone have any experience with the :exposes-methods option to genclass? I'm trying to hook into the servlet init method: https://gist.github.com/756639
17:28jlaskowskiso how can I call a method that accepts an array?
17:28amalloyyou can find this out for yourself with clojure.contrib.repl-utils/show
17:28amalloyjlaskowski: ##(doc into-array) is one way; in this case it looks like Guice will also accept an Iterable, so you can just pass it a clojure vector
17:28sexpbot⟹ "([aseq] [type aseq]); Returns an array with components set to the values in aseq. The array's component type is type if provided, or the type of the first value in aseq if present, or Object. All values in aseq must be compatible with the component type. Class objec... http://gist.github.com/756642
17:28Luyt_The topic could say 'Don't paste into the channel, use a pastebin like http://paste.pocoo.org/'
17:29jlaskowskiLuyt_: nice of you :)
17:29Luyt_well, #python has it, and many other channels too.
17:30jlaskowskiHURRAYY - you saved my day, amalloy
17:30jlaskowskiit works fine now
17:30Luyt_Freenode's channels are a great resource, because of all the friendly and knowledgeable people on it!
17:30jlaskowskiit's awesome how quickly it's sorted out!
17:31Luyt_...and some communities are really great.
17:31lancepantzwe just have a great community :)
17:31jlaskowskiit's not the first time I just enter the channel
17:31jlaskowskiand get an answer in secs
17:31jlaskowskiunbelievable
17:32jlaskowskithanks again
17:32Luyt_as long as you don't become a Help Vampire (http://slash7.com/2006/12/22/vampires/) it's allright ;-)
17:33Luyt_and you can always give back to the community, of course. Like lurking and answering questions from noobs, which are too tedious for the advanced clojurists in here. (Same works in #python)
17:36amalloyLuyt_: thanks for the Help Vampire link. it's cute
17:39Luyt_amalloy: Cute, yes, but there's also a very warning in there...
17:39Luyt_very real*
17:39amalloyLuyt_: yes, i'm familiar with the problem
17:40Luyt_Now, luckily I haven't seen it happening here yet, since clojure is quite esoteric and only intelligent (?) people are attracted to it, but it happened at #php if I remember correctly.
17:41Luyt_...and also on the python mailing list, at least a few housework-assignment like questions (formulated as demands) come passing by every week.
17:46TakeVIf I define an atom in one namespace, and have functions that manipulate it in the same namespace, then why is the atom not changing when I call those functions in another namespace?
17:47pdkwhat would be an equivalent to letfn that supports mutual recursion
17:48dnolenpdk: you can use trampoline /w your letfns
17:48pdkwhew boy
17:48pdk(doc trampoline)
17:48clojurebot"([f] [f & args]); trampoline can be used to convert algorithms requiring mutual recursion without stack consumption. Calls f with supplied args, if any. If f returns a fn, calls that fn with no arguments, and continues to repeat, until the return value is not a fn, then returns that non-fn value. Note that if you want to return a fn as a final value, you must wrap it in some data structure and unpack it after trampoline r
17:49amalloyTakeV: it should work. maybe post a simple gist that demonstrates your problem?
17:49qbgThe bindings in letfn are recursive, so there should be no problem
17:50TakeVamalloy: A what?
17:50amalloyTakeV: http://gist.github.com
17:53TakeVAh, nevermind. It seems that I was calling the wrong atom. Oops.
17:53rata_hi
18:04qbgI love the foo example that I just added to the readme at https://github.com/qbg/syntax-rules
18:08rata_qbg: nice work =)
18:09dnolenqbg: when you got time. you should make a simple github tutorial page comparing common use of CL style macros w/ steps to convert to syntax-rules. The Ring tutorial are a great example IMO, http://mmcgrana.github.com/2010/03/clojure-web-development-ring.html
18:09qbgI just need to write some code to define syntax classes, and define a bunch of them now
18:10qbg(and add syntax-case support also, but that should be rather trivial)
18:10qbgThe power of this library is far beyond syntax-rules at this point
18:11qbgI need to come up with a better name (and one that isn't too cheesy)
18:28benreesmanhi quick question: is there some literature that explains the clojure philosophy around when to use types/records/protocols and the multimethod/hierarchy system? what's the idiomatic way of creating types that e.g. know how to print themselves?
18:29qbgFrom what I've seen, you provide an implementation of the print-method multimethod
18:29qbg(or whatever it is called)
18:29qbgIn addition to toString
18:30benreesmanspecified on the name of the defrecord?
18:30qbgYou shouldn't need to do any of that for defrecord, only deftype
18:30qbgIf you think you do, you are probably doing it wrong
18:31qbgWhat are you trying to implement?
18:32benreesmani need a servlet that takes a streaming http endpoint and splits it into multiple streams. i'm just trying to get my head around the new clojure abstractions as i haven't used the language in over a year
18:32qbgYou use records as a typed map for the protocol system, and types for implementing data structures
18:33benreesmantypes/protocols and multimethods seem to have some overlap in their purpose
18:33benreesmanto the untrained eye, that is
18:33benreesmani think i understand the difference between a type and a record
18:33qbgUse multimethods if you need hierarchies or multiple dispatch
18:34qbgUse the protocol system if you need polymorphism on groups of functions
18:34qbgUse functions if you don't need any of that
18:34benreesmanis it idiomatic to use multiple dispatch with types/records?
18:34qbgtypes/records only provide single dispatch
18:35benreesmanso if i want multiple dispatch i should continue to use defstruct?
18:35qbg*well, the protocol system
18:35benreesmanreally appreciate your time by the way
18:36qbgIf you don't need to use the protocol system, you could use just maps instead
18:37rata_qbg: what about records vs maps performance?
18:38qbgrecords have potential performance advantages
18:38dnolenbenreesman: multimethods are more general. I've come to the conclusion they are most useful for the "scripting" layer of an application, where you need the most generality and/or where performance is mostly a wash (triggering IO related things).
18:38dnolenwhen you know you're interested in performance (some essential data structure) reach for protocols deftype/record
18:39benreesmanright, i'm not bothered about performance at the moment, i just want to use the most idiomatic type and dispatch abstraction. i like multiple dispatch better in general but was always bothered by the lack of a canonical type field for the types. i was wondering if defrecord solved that.
18:40qbgdefrecord/deftypes creates classes, so they have a type
18:42benreesmanmaybe what i need to do is read some code? any pointers to a non-trivial open source project written in a modern and idiomatic clojure style?
18:43dnolenqbg: about syntax-rules. +& is a bit weird, considering what it does - it's a grouping operator. also +sym's are kinda ugly. why not just use keywords? and let the user specify which keywords they want to allow as part of the macro.
18:43qbgFor full-blown stuff, there is the gvec stuff in core
18:43benreesmanwonderful i'll have a look
18:43qbgdnolan: +& is technically redundant at this point (+head and ...)
18:44benreesmanmuch obliged
18:46dnolenqbg: sure, mostly critique about +sym convention. why not keywords?
18:48joshua__How do I save a file using duck streams to a folder other than the working directory?
18:51amalloydid someone improve clojure-mode's eldoc or something recently? i've just noticed that when point is over a var, the minibuffer echoes the current value of that var
18:53mrBlissThe slides in the recently released Conj video about zippers are ahead of the speaker vid by 20s, which makes it very hard to follow, certainly when he's working in the REPL. (Too bad XBMC only allows an audio offset of maximum 10s). How come the uploaders didn't notice this?
18:56lazy1joshua__: Something like https://gist.github.com/756712 ?
19:05qbgSorry, got disconnected
19:05qbgdnolan: I used +syms because they are commonly used in source code
19:05qbgAnd so they are unambiguous
19:06qbgAlso, because syntax-parse has ~syms for additional directives
19:07joshua__lazy1: thanks.
19:08joshua__lazy1: I got confused because I tried \\temp\\blah instead /temp/blah
19:08joshua__lazyl: and that faile
19:12lazy1joshua__: To be OS agnostic, you probably want to join part on File/separator
19:14lazy1Though Java might do the / to \ conversion for you, I don't know
19:17amalloylazy1, joshua__: i think it does the conversion *sometimes*, as if that were helpful
19:19Guest10433http://pastebin.com/z5P2n9vM is one of these preferable to the other in clojure?
19:20lancepantzGuest10433: i like a better
19:21Guest10433lancepantz: thanks. i was just wondering if one way was considered better style
19:21amalloyGuest10433: a for sure. the (thingN)s should all line up; i prefer a, but if you indented lines 9 and 10 to match line 8 i think that would be acceptable
19:22Guest10433thanks amalloy.
19:24joshua__Hmm. How do I create a folder that doesn't exist?
19:25lazy1joshua__: Most of FS functionality is in java.io.File (see http://download.oracle.com/javase/6/docs/api/java/io/File.html)
19:25amalloy$google java io file create
19:25sexpbotFirst out of 127000 results is: Creating a File | Example Depot
19:25sexpbothttp://www.exampledepot.com/egs/java.io/createfile.html
19:26amalloyhm. not what i was hoping google would turn up, but quite useful anyway
19:28joshua__duck-streams in contrib turns out to have a make-parents command. I just need to create a file that has a path there.
19:31joshua__So something like (duck/make-parents (java.io.File. "path/to/file.txt")) would work =)
19:31joshua__amalloy, thanks that led me in the right direction.
19:35joshua__Yep worked like a charm. Thank you everyone!
19:42joshua__How would I got about declaring a dependency to one of my own projects with lein?
19:43joshua__Like :dependency [[my-other-lein-project "1.0.0-SNAPSHOT"]]
19:43tomojlook in your project's project.clj to determine
19:43amalloyjoshua__: i'm not sure about lein, but in cake you can $ cake install in my-other-lein-project to deploy it to your local repo
19:44lazy1lein has install as well
19:44ninjuddamalloy: 'lein install' works too
19:44tomojif you are hacking on both projects at once, symlink checkouts/my-other-project to the root of my-other-project
19:44joshua__lein install sounds like the right route than =)
19:44tomojand also include the dep
19:45tomojthen when your symlink is in place, the code there will take precedence over a jar in your local repo
19:46joshua__This seems to have been surprisingly easy.
19:46joshua__lein install.. 2 seconds later.. lein deps in other project
19:46joshua__no errors ?
19:46joshua__=) very nice
20:27bendlashey
20:28bendlasCan somebody tell me what's going on here
20:28bendlas,(deftype Vec2 [^double x
20:28bendlas ^double y]
20:28bendlas Object
20:28bendlas (equals [this other]
20:28clojurebotEOF while reading
20:29bendlas (println :other-type (type other) \newline
20:29bendlas :this-type Vec2 \newline
20:29bendlas :instance? (instance? Vec2 other)\newline
20:29bendlas :=type? (= (type other) Vec2))
20:29bendlas (and (instance? Vec2 other)
20:29technomancybendlas: step one: pastebin
20:29bendlas (== (.x this) (.x other))
20:29bendlas (== (.y this) (.y other)))))
20:29bendlasright
20:31bendlashttp://pastebin.com/AgNVKFhW
20:31bendlasanyway, when i do (= (Vec2. 5 6) (Vec2. 5 6))
20:32bendlas(instance? Vec2 other) in the overridden equals gives false
20:32bendlaswhile (= (type other) Vec2) gives true
20:32bendlaswtf?
21:13qbgFinally done with implementation of syntax class definition for https://github.com/qbg/syntax-rules
21:13qbgNow to document and do a commit
21:18joshua__Is there a simple way to pass a string to enlive as an html resource?
21:19joshua__Instead of a file/url that is.
21:23joshua__I guess I'll just wip out a regular expression.. seems like it will be faster
21:26bendlasjoshua__: html-snippet, I think
21:28joshua__Didn't work ;p
21:28joshua__ouch
21:30joshua__Apparently that is how its suppose to be done though.
21:31joshua__I think it was just my string being malformed.
21:31joshua__Thanks bendlas!
21:33bendlasnp
21:41joshua__$findfn ["\n\ntest"] "test"
21:41sexpbot[]
21:41joshua__$findfn "\n\ntest" "test"
21:41sexpbot[clojure.string/trim clojure.string/triml clojure.contrib.string/trim clojure.contrib.string/ltrim]
21:41joshua__omg omg
21:41joshua__The function.. it works =)
21:48tomojtechnomancy: thanks! I went to check sample.project.clj for the syntax for exclusions, and found exactly the log4q exclusions I needed :D
21:48tomojer, log4j
22:00dnolenso for contrib 1.3.0 how do I include a contrib library in a project.clj?
22:10qbgFinally, syntax class definitions
22:10qbgAnd an improved plet example
22:11qbgAwesome error messages FTW
22:13qbgNeeds syntax sugar for pattern variables with a parameterless syntax classes though
22:13qbg*class
22:30BerengalIs it possible to connect a repl to a running clojure process somehow?
22:34tomojthere is at least one way
22:34BerengalHow?
22:34clojurebotwith style and grace
22:34tomojemacs user? if not, there may be a way, but I don't know it
22:34BerengalYeah, I'm an emacs user
22:34tomojdo you use leiningen?
22:35BerengalBoth that and maven
22:36tomojyou know about `lein swank` and `mvn clojure:swank` (or whatever the maven goal is..)
22:36BerengalBut maven is probably more relevant to the projects I want to do this with
22:36BerengalYeah, I do
22:36tomojthere is a bit of clojure code you can use to kick off the swank server from your clojure code
22:36BerengalAh, nifty
22:37tomoj(swank.swank/start-repl)
22:37tomojcan pass port and host I think
22:38tomoj[port & opts]
22:40BerengalThat way I can start poking around my objects and whatnot while it's live. Why doesn't every language let you do that?
22:45woobyBerengal, https://github.com/relevance/mycroft is a web-based jvm explorer that may also interest you
22:47Berengalwooby: So that's kind of a browser-based repl, right?
22:48woobyof sorts
22:48BerengalNeat
22:49technomancyBerengal: the only reason I can imagine other languages lack a repl is that their designers have never used a language with one... but I know that's not true.
22:50Berengaltechnomancy: It's not the lack of a repl as much as the lack of a disecting a running program I'm lamenting
23:03amalloytechnomancy: it's kinda hard to imagine what a java repl would look like, with everything having to live in classes and methods
23:04greghpublic static void main>
23:04amalloygregh: and imports? or using the repl to write more than one function?
23:05greghyeah, it's not really practical. But it could be useful in a limited sense
23:05qbgMy mashup is now a syntax-rules/syntax-case/syntax-parse mashup.
23:07greghrelated: http://stackoverflow.com/questions/2636044/java-repl-shell
23:07greghwide variety of alternatives here: http://stackoverflow.com/questions/397488/is-there-something-like-pythons-interactive-repl-mode-but-for-java
23:43hippiehunterwhen consuming java types am i supposed to access public fields using (.someField instance set-value) ?
23:43hippiehunteror is that just for methods
23:43Gigaroby i think there was somethink like (set!
23:44Gigaroby(set! (. instance-expr instanceFieldName-symbol) expr)
23:44Gigarobyall here : http://clojure.org/java_interop
23:46hippiehunterthanks
23:48woobyi knew lots of people who pre-clojure used groovy or beanshell for a repl
23:50hippiehunteris there a way to make set! play nice with doto?
23:54amalloyhippiehunter: i don't use set! for interop; can you show me what a set! form for that looks like?
23:54hippiehunter(set! (. instance field) value)
23:55hippiehunteris there something i can use instead of set!?
23:55hippiehunteror are you just lucky enough not to deal with public fields
23:55amalloythe latter, i'm afraid
23:56Gigarobyguys I need somethink to remove a element from a seq in a determinate position
23:56Gigarobyexample : (remove 2 '(1 2 3 4))
23:56Gigaroby=>(1 2 4)
23:58amalloyhippiehunter: (doto instance (-> (. field) (set! 10))) maybe?
23:58joshua__$findfn 2 [1 2 3 4] [1 2 4]
23:58amalloy,(macroexpand '(doto instance (-> (. field) (set! 10))))
23:58sexpbot[]
23:58clojurebot(let* [G__870 instance] (-> G__870 (. field) (set! 10)) G__870)
23:58joshua__$findfn 2 [1 2 3 4] `(1 2 4)
23:58sexpbot[]
23:58joshua__$findfn [1 2 3 4] 2 `(1 2 4)
23:58sexpbot[]
23:59amalloyjoshua__, Gigaroby: no single function does it; you have to chain one or two together
23:59hippiehunter-> is one of those things Ive not gotten around to understanding, might you point me in the direction of a noob friendly explaination