2010-12-27
| 00:00 | qbg | And also for the fact that they queue up actions |
| 00:00 | Guest32627 | qbg: i guess combined with an error handler on your agent to make sure errors get logged to, that works pretty well |
| 00:01 | Guest32627 | qbg: sure, the queueing is a necessary part of the asynchronous processing. just like an MDB :) |
| 00:01 | Guest32627 | well... one attached to a queue anyway, not a topic :D |
| 00:03 | qbg | Hmm... Not sure if I'll be able to add some basic syntax-class support to my syntax-rules/syntax-parse mashup tonight |
| 00:08 | qbg | Binding *ns* in a test feels nasty |
| 02:17 | killy971 | Hello, 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:17 | killy971 | (defn static-fact [digit] (let [x 'x] `(case ~x ~@(mapcat (juxt identity fact) (range (inc digit)))))) |
| 02:17 | killy971 | (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:17 | killy971 | What I would like then is to make a function/macro from this result. |
| 02:18 | killy971 | (given that I have already defined the fact function) |
| 02:20 | tomoj | killy971: the reason is that you will be calling static-fact ofter with low values? |
| 02:20 | tomoj | s/ofter/often |
| 02:20 | sexpbot | <tomoj> killy971: the reason is that you will be calling static-fact often with low values? |
| 02:20 | killy971 | yes |
| 02:20 | killy971 | actually just digits |
| 02:20 | tomoj | have you considered memoize? |
| 02:21 | killy971 | but I was wondering how to write some clever static code, instead of memoized or verbose long case |
| 02:21 | tomoj | oh, just to try it out? |
| 02:21 | killy971 | yes, I have never really used macros until now, so I thought it could be a good occasion |
| 02:25 | killy971 | I 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:29 | tomoj | I think you're right that this is a nice simple experiment |
| 02:29 | tomoj | but my brain isn't working right now |
| 02:29 | tomoj | have you ever used defmacro before? |
| 02:30 | tomoj | I mean, successfully, at all? |
| 02:30 | Scriptor | macros are fun |
| 02:31 | Scriptor | killy971: what exactly are you trying to do? |
| 02:31 | killy971 | tomoj: I mean, successfully, at all?> just read stuart holloway book |
| 02:32 | killy971 | Scriptor> writing a succinct factorial function with pre-computed results (for digits) |
| 02:33 | killy971 | so I would like to use the macro facility to generate the part (case 1 1 2 2 3 6 4 24 ...) |
| 02:33 | killy971 | I already have the following piece of code : (defn static-fact [digit] (let [x 'x] `(case ~x ~@(mapcat (juxt identity fact) (range (inc digit)))))) |
| 02:34 | killy971 | it yields the case part if I execute it in the repl like this (static-fact 10) |
| 02:34 | tomoj | clojurebot: hygiene? |
| 02:34 | clojurebot | Cool story bro. |
| 02:40 | tomoj | huh |
| 02:40 | tomoj | wow |
| 02:43 | killy971 | any idea of how to do this? |
| 02:43 | tomoj | well |
| 02:43 | tomoj | I have a gist with a shitty answer |
| 02:44 | tomoj | https://gist.github.com/f04db48b5f33d4810de2 |
| 02:44 | tomoj | sticking (range n) and (resolve f) in there seems wrong to me |
| 02:46 | killy971 | I'm looking at the code |
| 02:48 | killy971 | great, it works as expected. but why do you say (range n) and (resolve f) seems wrong? |
| 02:49 | tomoj | just seems odd |
| 02:49 | tomoj | also, suppose I want to caseify not with a range from 0 but with some other seq of input vals |
| 02:49 | amalloy | tomoj: resolve definitely seems like it shouldn't be necessary; i agree about range |
| 02:49 | tomoj | I tried that originally, but you'd have to eval the form they pass in or something.. ugly |
| 02:50 | amalloy | instead of n, accept a seq |
| 02:50 | killy971 | oh if you mean this |
| 02:50 | killy971 | ok |
| 02:50 | tomoj | amalloy: yeah.. and do what with it? it's a macro |
| 02:50 | amalloy | oh, hm |
| 02:51 | tomoj | if 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:51 | tomoj | list or symbol, I guess.. |
| 02:55 | killy971 | thank you for the gist, at least it solves my prob |
| 04:03 | zvrba | hmm, how does equality work in clojure? what semantics does = have, when compared to CL? eq? eql? equal? |
| 04:03 | zvrba | ah, found it in the docs: it's value comparison. |
| 04:04 | zvrba | but given that data structures are immutable, is "value" comparison in this case implemented as identity comparison? |
| 08:03 | mrSpec | Hello! 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:14 | Chousuke | mrSpec: eval can't access locals. what is it that you're actually evaling? |
| 08:14 | mrSpec | it is global hashmap |
| 08:15 | mrSpec | (def hash (new java.util.LinkedHashMap)) |
| 08:15 | Chousuke | also, what is the error? |
| 08:16 | mrSpec | here is the problem... I cant see the error, Jslider is just not working |
| 08:16 | Chousuke | hmh |
| 08:16 | Chousuke | your problem is probably using eval in the first place :P |
| 08:16 | mrSpec | ok I've used (if ...) instead of eval... |
| 08:17 | Chousuke | but I can't really suggest anything better since I don't know what you're trying to do. |
| 08:17 | mrSpec | ok |
| 08:17 | mrSpec | unfortunately i'm in rush. so I'll ask about this later, and tell more :) |
| 10:43 | chouser | ugh. maven fail. http://tinyurl.com/2b6azmz |
| 11:51 | drewolson | hey 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:52 | qbg | It will be executed |
| 11:52 | qbg | But .nextInt has side effects, so you shouldn't use it in a dosync |
| 11:53 | qbg | Why do you want to use dosync here? |
| 11:53 | drewolson | qbg: i want to ensure multiple threads can generate distinct random numbers. i may be completely off here. |
| 11:54 | qbg | Isn't .nextInt already synchronized? |
| 11:54 | drewolson | qbg: it may well be, i'm not sure. |
| 11:54 | qbg | No |
| 11:55 | qbg | Doesn't appear to be |
| 11:55 | drewolson | qbg: so i'd like to access it sychronously, but i'm not sure how to do that using alter/commute. |
| 11:56 | qbg | Sounds like (locking @*rand* (.nextInt @*rand*)) should work |
| 11:56 | drewolson | qbg: i'll look into locking, thanks for the help |
| 11:56 | qbg | But there is little reason to have a Random in a ref |
| 11:57 | qbg | Another thought: why share the one random object between multiple threads? |
| 11:58 | drewolson | qbg: i probably won't eventually, i just became curious about accessing a java instance concurrently with methods with side effects. |
| 11:58 | qbg | The STM only works on refs, not java objects |
| 11:59 | drewolson | qbg: great, thanks for the help |
| 12:19 | amalloy | drewolson: 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:32 | LauJensen | ,(str (java.util.UUID/randomUUID)) |
| 12:32 | clojurebot | "fee8a2e9-b286-40fb-a9be-bac7c8ba3fb3" |
| 12:32 | LauJensen | drewolson: 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:33 | LauJensen | No locks, no nothing |
| 12:38 | LauJensen | amalloy: Did you catch that? :) |
| 12:39 | amalloy | LauJensen: heh. that's an amusing use of uuids |
| 12:39 | LauJensen | amalloy: its called: creative |
| 12:39 | amalloy | ah, of course. that's what i meant. creative |
| 12:55 | drewolson | amalloy, LauJensen: thanks for your help |
| 12:56 | LauJensen | np |
| 13:49 | dnolen | qbg: yeah *file* + &form is enough I think. Now I'm excited :D |
| 13:50 | dnolen | syntax-rulez! |
| 13:51 | dnolen | cemerick: 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:51 | qbg | They only look hard :) |
| 13:52 | cemerick | dnolen: Perhaps that's it -- the last time I used scheme in earnest, it was before I had properly grokked CL-style macros. |
| 13:55 | dnolen | the thing I like about syntax-rules is that it eliminates common cases that require splicing. You can specify patterns. |
| 13:55 | qbg | Just pushed out the line number stuff |
| 13:55 | dnolen | qbg: sweet |
| 13:56 | dnolen | qbg: the moment you push a stable release to clojars, I'm going to replace my ugly logos.minikanren macros with syntax-rules :) |
| 13:57 | qbg | I also mailed my CA form today |
| 13:59 | qbg | The 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:59 | qbg | I wonder if I could make that be correct instead... |
| 14:01 | qbg | Now I just need to implement guards and add a form for defining syntax classes |
| 14:01 | qbg | (and define a ton of built in syntax classes) |
| 14:03 | qbg | Is there a function that is equivalent to (first (filter ...))? |
| 14:09 | amalloy | qbg: i don't think so. there's (some), but that gets you (f x) instead of x |
| 14:10 | qbg | It seems like it could be a useful function to have (for communicating a concept) |
| 14:11 | amalloy | qbg: i agree. i've written (first (filter ..)) enough times that it ought to be abstracted out |
| 14:12 | qbg | What would it be called? some is already taken |
| 14:26 | dnolen | qbg: pick? |
| 14:27 | amalloy | qbg: (only even? (range))? |
| 14:28 | qbg | It should make sense in context of (if (<name> ...) <stuff to do if there is at least one such element>) |
| 14:28 | aqclj | hello |
| 14:28 | qbg | amalloy: only implies filter to me, not (first (filter ...)) |
| 14:29 | qbg | pick might work, but I feel it is a bit lacking |
| 14:30 | qbg | find? |
| 14:30 | qbg | I think that is what it is called in CL |
| 14:30 | stuartsierra | `find` is taken |
| 14:30 | qbg | Oh, yes |
| 14:31 | qbg | It is called find-if in CL |
| 14:31 | Obvious | find-if |
| 14:31 | Obvious | yep |
| 14:32 | qbg | Maybe find-pred? |
| 14:32 | qbg | Not as nice as a single word though... |
| 14:32 | amalloy | stuartsierra: since you mention it, why does find exist? it looks like get is a perfect drop-in substitute |
| 14:33 | stuartsierra | `find` returns the actual Map.Entry, not just the value. |
| 14:36 | aqclj | Hi, 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:36 | LauJensen | Any brilliant webdesigners in here, who would like to contribute either a design or a mock for clojureql.org ? |
| 14:37 | qbg | aqclj: Could you give sample input and output? |
| 14:37 | aqclj | yes |
| 14:38 | aqclj | the input would be the above sequence, and the LazySeqs are sequences of numbers |
| 14:38 | aqclj | and as output I would like to have the number of times "x" got the bigger number, and so on |
| 14:39 | aqclj | I 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:41 | qbg | I think I see what you want |
| 14:42 | stuartsierra | Use `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:45 | aqclj | thanks, I'm trying that now (I'm slow) |
| 14:45 | qbg | https://gist.github.com/756469 maybe? |
| 14:45 | qbg | (could be better) |
| 14:47 | qbg | Actually, that is going to be smallest... |
| 14:47 | qbg | Fixed |
| 14:49 | aqclj | the code got stuck, like in a infinite loop |
| 14:49 | aqclj | maybe it's because my lazyseq has no ending :S |
| 14:50 | qbg | It does it for all values, not only the first n |
| 14:50 | qbg | fixed |
| 14:51 | qbg | That code could be much better |
| 14:53 | aqclj | thanks, I'm trying to understand it now. It seems that something goes wrong, but now it doesn't get stuck |
| 14:53 | qbg | It could be that I'm misunderstanding what exactly you want |
| 14:55 | aqclj | at each loop, the bigger value within all the lazyseqs should be replaced by the next in the sequence |
| 14:55 | Berengal | Does putting anything inside a do at the toplevel make a difference? |
| 14:56 | qbg | Berengal: I don't think so |
| 14:56 | qbg | aqclj: Is this for sorting or something? |
| 14:57 | qbg | (like a merge sort) |
| 14:57 | aqclj | more or less |
| 14:57 | aqclj | for example |
| 14:57 | Berengal | qbg: Thanks |
| 14:58 | Berengal | Also, what's the prefered idiom for updating a single value in a map/struct? |
| 14:58 | qbg | assoc |
| 14:58 | amalloy | Berengal: update-in |
| 14:58 | amalloy | or assoc, depending |
| 14:58 | Berengal | amalloy: assoc makes a new entry, doesn't it? |
| 14:58 | amalloy | Berengal: overwriting any previous entry that was there |
| 14:58 | qbg | Yes, maps/structs are immutable |
| 14:58 | aqclj | if 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:59 | qbg | aqclj: 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:00 | amalloy | so 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:00 | Berengal | qbg: 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:00 | Berengal | amalloy: Thanks, that looks like it |
| 15:00 | qbg | ,(assoc {:a 1, :b 2} :a 5) |
| 15:00 | clojurebot | {:a 5, :b 2} |
| 15:00 | amalloy | &(update-in {:a 1, :b 2} [:a] inc) |
| 15:00 | sexpbot | ⟹ {:a 2, :b 2} |
| 15:01 | aqclj | qbg: 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:02 | aqclj | or I am wrong? :S |
| 15:02 | qbg | aqclj: Define that function to use lazy-seq |
| 15:02 | qbg | And use recursion |
| 15:03 | aqclj | ok thanks, I will try that |
| 15:05 | qbg | aqclj: Updated the gist to have that function instead |
| 15:05 | qbg | (assumes the input is a map) |
| 15:08 | aqclj | thanks again, I'm trying it |
| 16:04 | DanielGlauser | /msg NickServ identify 1l2gbOGH |
| 16:05 | dakrone | DanielGlauser: time to change that password :) |
| 16:05 | DanielGlauser | Oh crap |
| 16:05 | DanielGlauser | I guess it is :) |
| 16:05 | qbg | What? I only see ******** |
| 16:05 | qbg | ;) |
| 16:08 | qbg | Eww, I just used eval... |
| 16:27 | ngw | what libs are available for s3 and aws in general ? |
| 16:28 | cemerick | ngw: jclouds has the deepest support for aws AFAIK (and provides clojure wrappers for much of it) |
| 16:29 | cemerick | disclaimer: I'm a contributor there |
| 16:30 | ngw | thanks |
| 16:35 | DanielGlauser | Phew, I changed my password |
| 16:36 | DanielGlauser | /msg NickServ identify abc123 |
| 16:40 | qbg | lolz |
| 16:42 | qbg | Almost 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:42 | qbg | *namespaced |
| 16:45 | qbg | Hmm... Maybe binding *ns* around eval would be good enough |
| 16:53 | ngw | any suggestion about how to structure a project in clojure ? |
| 16:53 | ngw | I'm messing (and I mean it) with leinigen but coming from ruby/python it's kind of confusing |
| 16:54 | amalloy | ngw: cake is similar to leiningen but uses a little ruby underneath; not sure if that's helpful |
| 16:54 | ngw | for example I just discovered there's a -main function, something that none of the books I've read about clojure mentions it |
| 16:55 | amalloy | ngw: -main isn't special, per se. -foo is how to create a MyClass.foo() method when AOT compiling |
| 16:56 | pdk | yknow i should get around to installing cake or lein |
| 16:56 | pdk | though how is the installation process on windows |
| 16:56 | amalloy | but 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:58 | aqclj | I 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:59 | amalloy | &(apply into {} [{:a 1} {:b 2, :c 3}]) |
| 16:59 | sexpbot | java.lang.IllegalArgumentException: Wrong number of args (3) passed to: core$into |
| 17:00 | amalloy | &(apply merge-with + [{:a 1} {:b 2, :a 3}]) |
| 17:00 | sexpbot | ⟹ {:b 2, :a 4} |
| 17:00 | amalloy | aqclj: ^^ |
| 17:01 | aqclj | amalloy: thanks a lot! |
| 17:01 | aqclj | what the & do? |
| 17:01 | amalloy | aqclj: asks sexpbot to evaluate for me |
| 17:02 | aqclj | ah ok |
| 17:02 | Luyt_ | is it possible to have clojurebot do a deathmatch with sexpbot? |
| 17:05 | Luyt_ | &(println ",(doc doc)") |
| 17:05 | sexpbot | ⟹ ,(doc doc) nil |
| 17:05 | qbg | ,(println "&(println \"Foo\")") |
| 17:05 | clojurebot | &(println "Foo") |
| 17:05 | sexpbot | ⟹ Foo nil |
| 17:06 | qbg | Now to quine it... |
| 17:06 | Luyt_ | qbg - Luyt: 1-0 ! |
| 17:06 | Luyt_ | I tried to fool sexpbot into luring clojurebot out, that failed, you tried it the other way, that worked. |
| 17:07 | qbg | Yeah, sexpbot is going to make this hard... |
| 17:07 | Luyt_ | sexpbot's output always starts with ⟹ and as such can never get an answer out of clojurebot. |
| 17:07 | qbg | &(println "\n,(doc doc)") |
| 17:07 | sexpbot | ⟹ ,(doc doc) nil |
| 17:07 | Raynes | I've done my part. Any exploitation will be on clojurebot. Thus, I void all responsibility. ;) |
| 17:07 | amalloy | Luyt_: sexpbot was carefully designed to prevent this :P |
| 17:07 | Luyt_ | Good thing ;-) |
| 17:08 | qbg | &@(future (println ",(doc doc)")) |
| 17:08 | sexpbot | ⟹ nil |
| 17:08 | Luyt_ | Now, what if clojurebot responded to ",(...)" and sexpbot to ",,(...)" (note two comma's instead of one) |
| 17:08 | Raynes | amalloy: Haha "carefully designed". More like horribly designed until _ato broke it in every which way imaginable and forced me to fix it... carefully. :> |
| 17:09 | amalloy | Raynes: carefully designed /eventually/ |
| 17:09 | Raynes | That |
| 17:09 | qbg | &(let [i *in*] @(future (binding [*in* i] (println ",(doc doc)")))) |
| 17:09 | sexpbot | ⟹ nil |
| 17:09 | Raynes | is better. |
| 17:09 | qbg | &(let [i *out*] @(future (binding [*out* i] (println ",(doc doc)")))) |
| 17:09 | sexpbot | ⟹ ,(doc doc) nil |
| 17:09 | Raynes | qbg: You can also experiment with sexpbot in PM or in #sexpbot |
| 17:09 | Raynes | In case it gets too floody for #clojure. |
| 17:11 | Luyt_ | 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:11 | qbg | sexpbot wins this round... |
| 17:12 | qbg | Lets not quine clojurebot... |
| 17:21 | jlaskowski | hi |
| 17:21 | jlaskowski | I'm having troubles with java.lang.IllegalArgumentException: No matching method found: createInjector |
| 17:22 | jlaskowski | CLASSPATH=`pwd`/guice/guice-3.0-rc1.jar:`pwd`/guice/javax.inject.jar:`pwd`/guice/aopalliance.jar clj -13 |
| 17:22 | jlaskowski | CLOJURE_DIR: /Users/jacek/apps/clojure |
| 17:22 | jlaskowski | CLOJURE_CONTRIB_JAR: /Users/jacek/apps/clojure-contrib-1.3.0-alpha3.jar |
| 17:22 | jlaskowski | Clojure 1.3.0-alpha4 |
| 17:22 | jlaskowski | (def mm (proxy [AbstractModule] [] (configure [] (println "configure called")))) |
| 17:22 | jlaskowski | (bean mm) |
| 17:22 | jlaskowski | {:class user.proxy$com.google.inject.AbstractModule$0} |
| 17:22 | jlaskowski | and when I call (Guice/createInjector mm) |
| 17:22 | jlaskowski | it spits out the exception |
| 17:23 | jlaskowski | http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/AbstractModule.html |
| 17:23 | jlaskowski | how can I find out what is wrong exactly? |
| 17:24 | jlaskowski | how do I find out what Clojure can call upon a class? |
| 17:24 | jlaskowski | any helpful reflection methods to use? |
| 17:25 | amalloy | jlaskowski: createInjector takes an array of Modules, not a single module |
| 17:25 | amalloy | java's Foo.bar(Whatever...) is sugar for arrays |
| 17:25 | jlaskowski | right |
| 17:26 | jlaskowski | but have a look at the full stack trace |
| 17:26 | jlaskowski | user=> (.printStackTrace *e) |
| 17:26 | jlaskowski | java.lang.IllegalArgumentException: No matching method found: createInjector |
| 17:26 | jlaskowski | at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:77) |
| 17:26 | jlaskowski | at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:202) |
| 17:26 | jlaskowski | at user$eval17.invoke(NO_SOURCE_FILE:4) |
| 17:26 | jlaskowski | at clojure.lang.Compiler.eval(Compiler.java:6201) |
| 17:26 | jlaskowski | at clojure.lang.Compiler.eval(Compiler.java:6168) |
| 17:26 | jlaskowski | at clojure.core$eval.invoke(core.clj:2680) |
| 17:26 | jlaskowski | at clojure.main$repl$read_eval_print__5619.invoke(main.clj:179) |
| 17:26 | jlaskowski | at clojure.main$repl$fn__5624.invoke(main.clj:200) |
| 17:26 | jlaskowski | at clojure.main$repl.doInvoke(main.clj:200) |
| 17:26 | jlaskowski | at clojure.lang.RestFn.invoke(RestFn.java:422) |
| 17:26 | jlaskowski | at clojure.main$repl_opt.invoke(main.clj:266) |
| 17:26 | jlaskowski | at clojure.main$main.doInvoke(main.clj:361) |
| 17:26 | amalloy | augh do not do that |
| 17:26 | amalloy | http://gist.github.com |
| 17:26 | jlaskowski | amalloy: ok, will use it |
| 17:27 | amalloy | anyway, yes. it can't find a method with that name whose parameters are (Foo), only one whose parameters are (Foo[]) |
| 17:28 | jlaskowski | you're right! |
| 17:28 | lancepantz | does 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:28 | jlaskowski | so how can I call a method that accepts an array? |
| 17:28 | amalloy | you can find this out for yourself with clojure.contrib.repl-utils/show |
| 17:28 | amalloy | jlaskowski: ##(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:28 | sexpbot | ⟹ "([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:28 | Luyt_ | The topic could say 'Don't paste into the channel, use a pastebin like http://paste.pocoo.org/' |
| 17:29 | jlaskowski | Luyt_: nice of you :) |
| 17:29 | Luyt_ | well, #python has it, and many other channels too. |
| 17:30 | jlaskowski | HURRAYY - you saved my day, amalloy |
| 17:30 | jlaskowski | it works fine now |
| 17:30 | Luyt_ | Freenode's channels are a great resource, because of all the friendly and knowledgeable people on it! |
| 17:30 | jlaskowski | it's awesome how quickly it's sorted out! |
| 17:31 | Luyt_ | ...and some communities are really great. |
| 17:31 | lancepantz | we just have a great community :) |
| 17:31 | jlaskowski | it's not the first time I just enter the channel |
| 17:31 | jlaskowski | and get an answer in secs |
| 17:31 | jlaskowski | unbelievable |
| 17:32 | jlaskowski | thanks again |
| 17:32 | Luyt_ | as long as you don't become a Help Vampire (http://slash7.com/2006/12/22/vampires/) it's allright ;-) |
| 17:33 | Luyt_ | 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:36 | amalloy | Luyt_: thanks for the Help Vampire link. it's cute |
| 17:39 | Luyt_ | amalloy: Cute, yes, but there's also a very warning in there... |
| 17:39 | Luyt_ | very real* |
| 17:39 | amalloy | Luyt_: yes, i'm familiar with the problem |
| 17:40 | Luyt_ | 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:41 | Luyt_ | ...and also on the python mailing list, at least a few housework-assignment like questions (formulated as demands) come passing by every week. |
| 17:46 | TakeV | If 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:47 | pdk | what would be an equivalent to letfn that supports mutual recursion |
| 17:48 | dnolen | pdk: you can use trampoline /w your letfns |
| 17:48 | pdk | whew boy |
| 17:48 | pdk | (doc trampoline) |
| 17:48 | clojurebot | "([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:49 | amalloy | TakeV: it should work. maybe post a simple gist that demonstrates your problem? |
| 17:49 | qbg | The bindings in letfn are recursive, so there should be no problem |
| 17:50 | TakeV | amalloy: A what? |
| 17:50 | amalloy | TakeV: http://gist.github.com |
| 17:53 | TakeV | Ah, nevermind. It seems that I was calling the wrong atom. Oops. |
| 17:53 | rata_ | hi |
| 18:04 | qbg | I love the foo example that I just added to the readme at https://github.com/qbg/syntax-rules |
| 18:08 | rata_ | qbg: nice work =) |
| 18:09 | dnolen | qbg: 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:09 | qbg | I just need to write some code to define syntax classes, and define a bunch of them now |
| 18:10 | qbg | (and add syntax-case support also, but that should be rather trivial) |
| 18:10 | qbg | The power of this library is far beyond syntax-rules at this point |
| 18:11 | qbg | I need to come up with a better name (and one that isn't too cheesy) |
| 18:28 | benreesman | hi 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:29 | qbg | From what I've seen, you provide an implementation of the print-method multimethod |
| 18:29 | qbg | (or whatever it is called) |
| 18:29 | qbg | In addition to toString |
| 18:30 | benreesman | specified on the name of the defrecord? |
| 18:30 | qbg | You shouldn't need to do any of that for defrecord, only deftype |
| 18:30 | qbg | If you think you do, you are probably doing it wrong |
| 18:31 | qbg | What are you trying to implement? |
| 18:32 | benreesman | i 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:32 | qbg | You use records as a typed map for the protocol system, and types for implementing data structures |
| 18:33 | benreesman | types/protocols and multimethods seem to have some overlap in their purpose |
| 18:33 | benreesman | to the untrained eye, that is |
| 18:33 | benreesman | i think i understand the difference between a type and a record |
| 18:33 | qbg | Use multimethods if you need hierarchies or multiple dispatch |
| 18:34 | qbg | Use the protocol system if you need polymorphism on groups of functions |
| 18:34 | qbg | Use functions if you don't need any of that |
| 18:34 | benreesman | is it idiomatic to use multiple dispatch with types/records? |
| 18:34 | qbg | types/records only provide single dispatch |
| 18:35 | benreesman | so if i want multiple dispatch i should continue to use defstruct? |
| 18:35 | qbg | *well, the protocol system |
| 18:35 | benreesman | really appreciate your time by the way |
| 18:36 | qbg | If you don't need to use the protocol system, you could use just maps instead |
| 18:37 | rata_ | qbg: what about records vs maps performance? |
| 18:38 | qbg | records have potential performance advantages |
| 18:38 | dnolen | benreesman: 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:38 | dnolen | when you know you're interested in performance (some essential data structure) reach for protocols deftype/record |
| 18:39 | benreesman | right, 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:40 | qbg | defrecord/deftypes creates classes, so they have a type |
| 18:42 | benreesman | maybe 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:43 | dnolen | qbg: 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:43 | qbg | For full-blown stuff, there is the gvec stuff in core |
| 18:43 | benreesman | wonderful i'll have a look |
| 18:43 | qbg | dnolan: +& is technically redundant at this point (+head and ...) |
| 18:44 | benreesman | much obliged |
| 18:46 | dnolen | qbg: sure, mostly critique about +sym convention. why not keywords? |
| 18:48 | joshua__ | How do I save a file using duck streams to a folder other than the working directory? |
| 18:51 | amalloy | did 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:53 | mrBliss | The 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:56 | lazy1 | joshua__: Something like https://gist.github.com/756712 ? |
| 19:05 | qbg | Sorry, got disconnected |
| 19:05 | qbg | dnolan: I used +syms because they are commonly used in source code |
| 19:05 | qbg | And so they are unambiguous |
| 19:06 | qbg | Also, because syntax-parse has ~syms for additional directives |
| 19:07 | joshua__ | lazy1: thanks. |
| 19:08 | joshua__ | lazy1: I got confused because I tried \\temp\\blah instead /temp/blah |
| 19:08 | joshua__ | lazyl: and that faile |
| 19:12 | lazy1 | joshua__: To be OS agnostic, you probably want to join part on File/separator |
| 19:14 | lazy1 | Though Java might do the / to \ conversion for you, I don't know |
| 19:17 | amalloy | lazy1, joshua__: i think it does the conversion *sometimes*, as if that were helpful |
| 19:19 | Guest10433 | http://pastebin.com/z5P2n9vM is one of these preferable to the other in clojure? |
| 19:20 | lancepantz | Guest10433: i like a better |
| 19:21 | Guest10433 | lancepantz: thanks. i was just wondering if one way was considered better style |
| 19:21 | amalloy | Guest10433: 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:22 | Guest10433 | thanks amalloy. |
| 19:24 | joshua__ | Hmm. How do I create a folder that doesn't exist? |
| 19:25 | lazy1 | joshua__: Most of FS functionality is in java.io.File (see http://download.oracle.com/javase/6/docs/api/java/io/File.html) |
| 19:25 | amalloy | $google java io file create |
| 19:25 | sexpbot | First out of 127000 results is: Creating a File | Example Depot |
| 19:25 | sexpbot | http://www.exampledepot.com/egs/java.io/createfile.html |
| 19:26 | amalloy | hm. not what i was hoping google would turn up, but quite useful anyway |
| 19:28 | joshua__ | 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:31 | joshua__ | So something like (duck/make-parents (java.io.File. "path/to/file.txt")) would work =) |
| 19:31 | joshua__ | amalloy, thanks that led me in the right direction. |
| 19:35 | joshua__ | Yep worked like a charm. Thank you everyone! |
| 19:42 | joshua__ | How would I got about declaring a dependency to one of my own projects with lein? |
| 19:43 | joshua__ | Like :dependency [[my-other-lein-project "1.0.0-SNAPSHOT"]] |
| 19:43 | tomoj | look in your project's project.clj to determine |
| 19:43 | amalloy | joshua__: 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:44 | lazy1 | lein has install as well |
| 19:44 | ninjudd | amalloy: 'lein install' works too |
| 19:44 | tomoj | if you are hacking on both projects at once, symlink checkouts/my-other-project to the root of my-other-project |
| 19:44 | joshua__ | lein install sounds like the right route than =) |
| 19:44 | tomoj | and also include the dep |
| 19:45 | tomoj | then when your symlink is in place, the code there will take precedence over a jar in your local repo |
| 19:46 | joshua__ | This seems to have been surprisingly easy. |
| 19:46 | joshua__ | lein install.. 2 seconds later.. lein deps in other project |
| 19:46 | joshua__ | no errors ? |
| 19:46 | joshua__ | =) very nice |
| 20:27 | bendlas | hey |
| 20:28 | bendlas | Can somebody tell me what's going on here |
| 20:28 | bendlas | ,(deftype Vec2 [^double x |
| 20:28 | bendlas | ^double y] |
| 20:28 | bendlas | Object |
| 20:28 | bendlas | (equals [this other] |
| 20:28 | clojurebot | EOF while reading |
| 20:29 | bendlas | (println :other-type (type other) \newline |
| 20:29 | bendlas | :this-type Vec2 \newline |
| 20:29 | bendlas | :instance? (instance? Vec2 other)\newline |
| 20:29 | bendlas | :=type? (= (type other) Vec2)) |
| 20:29 | bendlas | (and (instance? Vec2 other) |
| 20:29 | technomancy | bendlas: step one: pastebin |
| 20:29 | bendlas | (== (.x this) (.x other)) |
| 20:29 | bendlas | (== (.y this) (.y other))))) |
| 20:29 | bendlas | right |
| 20:31 | bendlas | http://pastebin.com/AgNVKFhW |
| 20:31 | bendlas | anyway, when i do (= (Vec2. 5 6) (Vec2. 5 6)) |
| 20:32 | bendlas | (instance? Vec2 other) in the overridden equals gives false |
| 20:32 | bendlas | while (= (type other) Vec2) gives true |
| 20:32 | bendlas | wtf? |
| 21:13 | qbg | Finally done with implementation of syntax class definition for https://github.com/qbg/syntax-rules |
| 21:13 | qbg | Now to document and do a commit |
| 21:18 | joshua__ | Is there a simple way to pass a string to enlive as an html resource? |
| 21:19 | joshua__ | Instead of a file/url that is. |
| 21:23 | joshua__ | I guess I'll just wip out a regular expression.. seems like it will be faster |
| 21:26 | bendlas | joshua__: html-snippet, I think |
| 21:28 | joshua__ | Didn't work ;p |
| 21:28 | joshua__ | ouch |
| 21:30 | joshua__ | Apparently that is how its suppose to be done though. |
| 21:31 | joshua__ | I think it was just my string being malformed. |
| 21:31 | joshua__ | Thanks bendlas! |
| 21:33 | bendlas | np |
| 21:41 | joshua__ | $findfn ["\n\ntest"] "test" |
| 21:41 | sexpbot | [] |
| 21:41 | joshua__ | $findfn "\n\ntest" "test" |
| 21:41 | sexpbot | [clojure.string/trim clojure.string/triml clojure.contrib.string/trim clojure.contrib.string/ltrim] |
| 21:41 | joshua__ | omg omg |
| 21:41 | joshua__ | The function.. it works =) |
| 21:48 | tomoj | technomancy: thanks! I went to check sample.project.clj for the syntax for exclusions, and found exactly the log4q exclusions I needed :D |
| 21:48 | tomoj | er, log4j |
| 22:00 | dnolen | so for contrib 1.3.0 how do I include a contrib library in a project.clj? |
| 22:10 | qbg | Finally, syntax class definitions |
| 22:10 | qbg | And an improved plet example |
| 22:11 | qbg | Awesome error messages FTW |
| 22:13 | qbg | Needs syntax sugar for pattern variables with a parameterless syntax classes though |
| 22:13 | qbg | *class |
| 22:30 | Berengal | Is it possible to connect a repl to a running clojure process somehow? |
| 22:34 | tomoj | there is at least one way |
| 22:34 | Berengal | How? |
| 22:34 | clojurebot | with style and grace |
| 22:34 | tomoj | emacs user? if not, there may be a way, but I don't know it |
| 22:34 | Berengal | Yeah, I'm an emacs user |
| 22:34 | tomoj | do you use leiningen? |
| 22:35 | Berengal | Both that and maven |
| 22:36 | tomoj | you know about `lein swank` and `mvn clojure:swank` (or whatever the maven goal is..) |
| 22:36 | Berengal | But maven is probably more relevant to the projects I want to do this with |
| 22:36 | Berengal | Yeah, I do |
| 22:36 | tomoj | there is a bit of clojure code you can use to kick off the swank server from your clojure code |
| 22:36 | Berengal | Ah, nifty |
| 22:37 | tomoj | (swank.swank/start-repl) |
| 22:37 | tomoj | can pass port and host I think |
| 22:38 | tomoj | [port & opts] |
| 22:40 | Berengal | That way I can start poking around my objects and whatnot while it's live. Why doesn't every language let you do that? |
| 22:45 | wooby | Berengal, https://github.com/relevance/mycroft is a web-based jvm explorer that may also interest you |
| 22:47 | Berengal | wooby: So that's kind of a browser-based repl, right? |
| 22:48 | wooby | of sorts |
| 22:48 | Berengal | Neat |
| 22:49 | technomancy | Berengal: 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:50 | Berengal | technomancy: It's not the lack of a repl as much as the lack of a disecting a running program I'm lamenting |
| 23:03 | amalloy | technomancy: it's kinda hard to imagine what a java repl would look like, with everything having to live in classes and methods |
| 23:04 | gregh | public static void main> |
| 23:04 | amalloy | gregh: and imports? or using the repl to write more than one function? |
| 23:05 | gregh | yeah, it's not really practical. But it could be useful in a limited sense |
| 23:05 | qbg | My mashup is now a syntax-rules/syntax-case/syntax-parse mashup. |
| 23:07 | gregh | related: http://stackoverflow.com/questions/2636044/java-repl-shell |
| 23:07 | gregh | wide variety of alternatives here: http://stackoverflow.com/questions/397488/is-there-something-like-pythons-interactive-repl-mode-but-for-java |
| 23:43 | hippiehunter | when consuming java types am i supposed to access public fields using (.someField instance set-value) ? |
| 23:43 | hippiehunter | or is that just for methods |
| 23:43 | Gigaroby | i think there was somethink like (set! |
| 23:44 | Gigaroby | (set! (. instance-expr instanceFieldName-symbol) expr) |
| 23:44 | Gigaroby | all here : http://clojure.org/java_interop |
| 23:46 | hippiehunter | thanks |
| 23:48 | wooby | i knew lots of people who pre-clojure used groovy or beanshell for a repl |
| 23:50 | hippiehunter | is there a way to make set! play nice with doto? |
| 23:54 | amalloy | hippiehunter: i don't use set! for interop; can you show me what a set! form for that looks like? |
| 23:54 | hippiehunter | (set! (. instance field) value) |
| 23:55 | hippiehunter | is there something i can use instead of set!? |
| 23:55 | hippiehunter | or are you just lucky enough not to deal with public fields |
| 23:55 | amalloy | the latter, i'm afraid |
| 23:56 | Gigaroby | guys I need somethink to remove a element from a seq in a determinate position |
| 23:56 | Gigaroby | example : (remove 2 '(1 2 3 4)) |
| 23:56 | Gigaroby | =>(1 2 4) |
| 23:58 | amalloy | hippiehunter: (doto instance (-> (. field) (set! 10))) maybe? |
| 23:58 | joshua__ | $findfn 2 [1 2 3 4] [1 2 4] |
| 23:58 | amalloy | ,(macroexpand '(doto instance (-> (. field) (set! 10)))) |
| 23:58 | sexpbot | [] |
| 23:58 | clojurebot | (let* [G__870 instance] (-> G__870 (. field) (set! 10)) G__870) |
| 23:58 | joshua__ | $findfn 2 [1 2 3 4] `(1 2 4) |
| 23:58 | sexpbot | [] |
| 23:58 | joshua__ | $findfn [1 2 3 4] 2 `(1 2 4) |
| 23:58 | sexpbot | [] |
| 23:59 | amalloy | joshua__, Gigaroby: no single function does it; you have to chain one or two together |
| 23:59 | hippiehunter | -> is one of those things Ive not gotten around to understanding, might you point me in the direction of a noob friendly explaination |