2009-04-06
| 01:48 | jsankey | (java.io.File. "a\\b") |
| 01:49 | jsankey | ,(java.io.File. "a\\b") |
| 01:49 | clojurebot | #<File a\b> |
| 01:50 | jsankey | ,(.parentFile (java.io.File. "a\\b")) |
| 01:50 | clojurebot | java.lang.IllegalArgumentException: No matching field found: parentFile for class java.io.File |
| 04:43 | kefka | I've noticed that ArrayList access seems to be slow in a Clojure REPL. Am I doing something wrong? |
| 04:44 | AWizzArd | more info please |
| 04:44 | AWizzArd | you are using the default JVM methods, so it should not be any slower |
| 04:44 | kefka | ,(time (let [a (new ArrayList (range 10))] (doall (for [i (range 100000)] (.get a 5))))) |
| 04:44 | clojurebot | java.lang.IllegalArgumentException: Unable to resolve classname: ArrayList |
| 04:44 | kefka | ,(time (let [a (new java.util.ArrayList (range 10))] (doall (for [i (range 100000)] (.get a 5))))) |
| 04:45 | kefka | It takes about 1.3 microseconds per access on my machine. |
| 04:45 | cconstantine | I've got a crazy idea; Would it make sense to read files as a lazy-seq? Each element in the sequence would be an item from the file (Something like a line, or other defined chunk). This would make reading a file in a (dosync ...) easy/fast and would allow you to use all the nice drop, drop-while, filter, etc. lazy-seq functions. Am I crazy? |
| 04:46 | kefka | I'm on a 2.6 GHz machine, so this is thousands of clock cycles |
| 04:46 | kefka | per .get |
| 04:47 | kefka | ,(time (let [a (new java.util.ArrayList (range 10))] (dorun (for [i (range 100000)] (.get a 5))))) |
| 04:47 | kefka | dorun, not doall... I think my doall might have hurt the Clojurebot |
| 04:47 | cconstantine | kefka: that returns a long list |
| 04:47 | kefka | ,(+ 3 4) |
| 04:48 | kefka | Yes, I should have been using dorun. dorun doesn't return. |
| 04:48 | Cark | ,(doc line-seq) |
| 04:48 | kefka | doall returns a huge seq |
| 04:48 | Cark | did you guys kill poor clojurebot ? |
| 04:48 | kefka | Clojurebot seems to have been killed by my huge doall. Sorry. :( |
| 04:48 | kefka | How does one get it back? |
| 04:48 | cconstantine | I get "Elapsed time: 66.048 msecs" |
| 04:49 | cconstantine | talk to hiredguy? |
| 04:49 | Cark | anyways constantine : have a look to line-seq |
| 04:50 | kefka | cconstantine: It takes me about 100 msec, but that seems a lot longer than it should be, for 100k ArrayList accesses. |
| 04:50 | kefka | On a 2.6 GHz machine, that's 2600 clock cycles per access |
| 04:50 | cconstantine | Cark: that is pretty close to what I was thinking of :) |
| 04:51 | Cark | yes though i'm not sure the file gets closed if you never go to the end of it |
| 04:51 | Cark | at least it should be upon GC |
| 04:51 | cconstantine | Cark: right, it would have to be wrapped in either a generator func or macro |
| 04:51 | cconstantine | for the file open/close |
| 04:52 | Cark | i don't know ... i think rhickey was working on something for this ... |
| 04:52 | cconstantine | kefka: no idea what's up.... I've had disapointing results timing simple counting loops (last (range 1 100000)) compared to C |
| 04:53 | Cark | you're not comparing the same thing |
| 04:53 | Cark | use loop/recur |
| 04:53 | cconstantine | I got similar timings with loop/recur |
| 04:53 | Cark | on server jvm |
| 04:53 | cconstantine | yup |
| 04:53 | Cark | did you take "warm up " into account ? |
| 04:54 | cconstantine | I'm inclined to think clojure isn't 100 times slower than C, and that I'm doing it wrong |
| 04:54 | Cark | and used unsafe maths ? |
| 04:54 | cconstantine | unsafe maths (unchecked-inc ...) didn't seem to effect speed |
| 04:54 | Chousuke | did you make sure there is no reflection? |
| 04:54 | Cark | you coerced the counter to integers ? |
| 04:55 | cconstantine | no reflection? |
| 04:55 | cconstantine | I started with raw numbers at the reader, and used unchecked-inc |
| 04:56 | Chousuke | well, (.get foo 5) would cause reflection without a type hint. |
| 04:56 | Chousuke | bind *warn-on-reflection* to true :/ |
| 04:56 | cconstantine | ah, and the time-to-run was linear with the number of increments, so the there was no "warm-up" factor |
| 04:56 | cconstantine | ah, I've done that. I wasn't getting reflection |
| 04:57 | cconstantine | poor clojurebot |
| 04:58 | cconstantine | I dunno, the only reason I cared even a little was that a friend doing project clojure was getting answers 10/100 times faster in C than I was in clojure using the same basic algorithms |
| 04:58 | cconstantine | I'm not too worried; another friend is using haskell and getting similar timings to me |
| 04:59 | cconstantine | s/project clojure/project euler/ |
| 05:00 | cconstantine | and our runtimes are on the order of 1-5 seconds |
| 05:01 | gnuvince | For simple problems like that, Clojure doesn't have much of a problem with performance. |
| 05:02 | cconstantine | it's ok, I beat him on code simplicity, code length, and generality of solution (his won't work for N too large) |
| 05:03 | gnuvince | He's probably not using Integer |
| 05:04 | cconstantine | He's using C, so his types are like 'int' |
| 05:04 | Cark | hum testing this i just discovered that i can't run the server jvm on my 64bit computer =/ |
| 05:04 | gnuvince | cconstantine: oh, I thought he was using Haskell |
| 05:05 | cconstantine | gnuvince: ah, yes the haskell guy is using Integer |
| 05:09 | Cark | i have a deamatic increase in speed when using server jvm, and running the test several times |
| 05:09 | Cark | dramatic |
| 05:09 | Cark | lisppaste8: url? |
| 05:09 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 05:10 | lisppaste8 | cark pasted "untitled" at http://paste.lisp.org/display/78102 |
| 05:13 | hiredman | ~ticker JAVA |
| 05:13 | clojurebot | No entiendo |
| 05:13 | hiredman | useless |
| 05:14 | AWizzArd | ,(doc for) |
| 05:14 | clojurebot | "([seq-exprs body-expr]); List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], :while test, :when test. (take 100 (for [x (range 100000 |
| 05:15 | AWizzArd | kefka: You use dorun and not dotimes? |
| 05:16 | AWizzArd | On my machine your (time (let [a (new java.util.ArrayList (range 10))] (dorun (for [i (range 100000)] (.get a 5))))) ==> "Elapsed time: 55.393632 msecs" |
| 05:16 | AWizzArd | kefka: but (time (let [a (new java.util.ArrayList (range 10))] (dotimes [i 100000] (.get a 5)))) ==> "Elapsed time: 7.141131 msecs" |
| 05:17 | AWizzArd | '(/ 100000 7.141131) |
| 05:17 | AWizzArd | ,(/ 100000 7.141131) |
| 05:17 | clojurebot | 14003.384057791407 |
| 05:17 | AWizzArd | 14000 reads per millisecond |
| 05:17 | jgracin | Hi! Could someone please help me resolving a "not releasing the head" problem. I'll paste it in a sec. |
| 05:17 | lisppaste8 | jgracin pasted "Out of heap space" at http://paste.lisp.org/display/78104 |
| 05:17 | AWizzArd | No wait, nonsense of course. That is lazy and was not run. |
| 05:19 | Cark | i think it gets optimized out |
| 05:21 | jgracin | is it because "lines" is a parameter which stays bound until the function exits? I guess that's it, isn't it? |
| 05:22 | mihand | hey guys! is (int (/ a b)) the idiomatic way to do truncating division ? |
| 05:22 | Chouser | mihand: quot |
| 05:24 | Cark | jgracin : when you call find-save-debug the lines parameter points to the head of the lines sequence |
| 05:24 | Cark | so you're retaining the head |
| 05:25 | jgracin | Cark: thanks! Is there any way I can deal with this? Is this what streams are for? Where are the streams? |
| 05:26 | Cark | you could change entire-log-line-seq to return a function that will return the sequence |
| 05:26 | Chouser | streams are experimental, not in trunk |
| 05:26 | Cark | and pass that as a parameter to find-saved-debug |
| 05:26 | Cark | hey hello chouser |
| 05:27 | Raynes | Hey hello hi Chouser. |
| 05:27 | Raynes | Cark: I win. |
| 05:27 | Chouser | hi guys |
| 05:27 | cemerick | hey, Chouser's back, all's right with the world again! :-D |
| 05:27 | jgracin | So I can't pass infinite lazy sequences into functions because that will necessarily blow up the heap. |
| 05:28 | jgracin | I mean, if they decide to make a long search through the seq. |
| 05:28 | lisppaste8 | cark annotated #78104 "untitled" at http://paste.lisp.org/display/78104#1 |
| 05:28 | Chouser | hm, that can't be quite right, since you can pass infinite lazy seqs to 'filter' without a problem. |
| 05:28 | Cark | try this untested change |
| 05:28 | Cark | chouser : filter probably uses recur |
| 05:29 | Chouser | no, it's lazy. uses lazy-seq |
| 05:29 | Cark | ~def filter |
| 05:29 | Cark | well then it returns immediately |
| 05:29 | jgracin | my entire-log-lines-seq uses concat which I counted on using lazy-seq internally. |
| 05:31 | Chouser | that should be ok (though mapcat would be more succinct) |
| 05:32 | Cark | jgracin : try my solution and tell us how it goes ! |
| 05:35 | jgracin | Cark: yup, it works. Thanks! I do understand how and why. It's just that it doesn't seem quite elegant. Does the streams address this kind of problem or are they for different purposes? |
| 05:35 | Cark | yes they do |
| 05:35 | Cark | hum there is another way |
| 05:35 | Cark | you could build your own filtered lazy sequence |
| 05:35 | Cark | ~def filter |
| 05:36 | Chouser | are locals cleared out before tail calls? |
| 05:38 | lisppaste8 | cark annotated #78104 "untitled" at http://paste.lisp.org/display/78104#2 |
| 05:39 | Cark | not sure if that will do it |
| 05:41 | Cark | chouser : my guess would be that the pointers are overwritten |
| 05:41 | Cark | so no more reference, so garbage collectable |
| 05:48 | Chouser | yes, that appears to be the case. if so, then just moving the call to 'first' out of find-saved-debug might do it |
| 05:48 | Chouser | oh |
| 05:48 | Chouser | like Cark's second annotation. |
| 05:48 | Chouser | :-) |
| 05:48 | Cark | =) |
| 05:49 | jgracin | thanks! |
| 05:49 | Chouser | except saved-debugs is still a fn that needs to be called with the right args, but that's the gist I was headed for. |
| 05:49 | Chouser | oh, nm. |
| 06:06 | Mec | is there an opposite of slurp that writes a string to a file? |
| 06:07 | dliebke | ,(doc clojure.contrib.duck-streams/spit) |
| 06:07 | clojurebot | java.lang.Exception: Unable to resolve var: clojure.contrib.duck-streams/spit in this context |
| 06:08 | dliebke | clojure.contrib.duck-streams/spit writes a string to a file |
| 06:09 | Mec | thanks |
| 06:10 | Mec | hmm class not found exception |
| 06:10 | Cark | ,(use 'clojure.contrib.duck-streams) |
| 06:10 | clojurebot | java.io.FileNotFoundException: Could not locate clojure/contrib/duck_streams__init.class or clojure/contrib/duck_streams.clj on classpath: |
| 06:10 | Cark | works on my machine ! |
| 06:11 | Mec | yup i got it now |
| 06:11 | Mec | will spit overwrite the file? |
| 06:13 | dliebke | yes, it appears to overwrite the file |
| 06:14 | Mec | excellent, thanks |
| 06:24 | hiredman | ~ticker JAVA |
| 06:24 | clojurebot | Pardon? |
| 06:24 | hiredman | clojurebot: are you for real? |
| 06:24 | clojurebot | for is not a loop |
| 06:26 | cconstantine | ok, so it turns out I'm not using a java server |
| 06:26 | cconstantine | is there a place that talks about how to do that? |
| 06:28 | cconstantine | nm, I needed to ask the question for me to answer it myself |
| 06:31 | hiredman | ~ticker JAVA |
| 06:31 | clojurebot | JAVA; -1.98 |
| 06:38 | cemerick | is it true that there's no way to determine how many arguments a fn can accept? |
| 06:39 | Chouser | you can call it with n args, and if you get an exception then it doesn't except that many. |
| 06:39 | Chouser | or of those types. |
| 06:39 | Chouser | or something else is wrong. |
| 06:39 | hiredman | cemerick: it is true |
| 06:39 | cemerick | so if I pull a fish out of a random hole, I get to keep the fish? ;-) |
| 06:40 | Chouser | you can look at the :arglists metadata of a var |
| 06:40 | Chouser | but that can be overwritten by the user, so ... *shrug* |
| 06:40 | hiredman | Chouser is trying to sugar coat it for you |
| 06:41 | Chouser | you can do what the 'source' macro does to find the clojure source for the fn, use 'read' and 'macroexpand' and analyze the results... |
| 06:42 | cemerick | I think I'd just make a macro that attaches arity metadata :-) |
| 06:43 | cemerick | but wow, dropping to the source macro is imaginative... |
| 06:43 | Chouser | but so very very wrong |
| 06:44 | hiredman | Fn objects don't let you attach metadata |
| 06:44 | cemerick | ah, damn |
| 06:44 | hiredman | Yeah |
| 06:44 | Chouser | well, they don't let you *change* metadata. You can use proxy to provide unalterable metadata when you creating the instance. |
| 06:45 | hiredman | well, I guess there is that |
| 06:45 | Chouser | which actually sounds about perfect for arity |
| 06:46 | cemerick | ah, AFn has metadata. I'd think IFn would extend IObj. |
| 06:46 | Chouser | what would this metadata look like? a set of the accepted arities? |
| 06:46 | Chouser | but then what about variadics? |
| 06:46 | cemerick | I'm not sure yet. We need a little more than just arity (type info, aaack!), but it'd always be immutable. |
| 06:47 | cemerick | I don't think we have any variadic fns in this particular corner of things. |
| 06:48 | cemerick | eh, maybe we should just pass around maps with a :fn key where the actual function lives. I'll bet we'll want to assoc some amount of stuff into a fn's 'metadata' eventually. |
| 07:17 | Chouser | recur is a bit of a problem |
| 07:18 | Chouser | it refers to it's own kind of scope -- not dynamic, not lexical of the sort that can be closed over. |
| 07:21 | cemerick | that's the tradeoff for constant-space stack usage, right? The "real" solution is TCO or trampolining. |
| 07:23 | Chouser | It seems it might be theoretically possible to recur to a named loop in your lexical scope... |
| 07:23 | Chouser | hm, maybe not -- if you close over that name, then call the closure from outside that lexical scope, where does the recur go? |
| 07:23 | cemerick | oh, so you could choose to recur to the next loop up, or optionally to an outer loop or the fn you're in? |
| 07:24 | cmvkk | what are you trying to do? |
| 07:24 | Chouser | cemerick: yeah, that's what I was thinking, but I specifically wanted to be able to close over that name, so that I could 'recur' to a named loop instead of having to recurse to a named fn. |
| 07:25 | Chouser | cmvkk: fix error-kit |
| 07:25 | Chouser | ugh, sounds like I might be asking for continuations without knowing it. |
| 07:25 | cemerick | you inch towards a reified environment at that point, I think. |
| 07:25 | cemerick | indeed |
| 07:26 | cemerick | that's not entirely horrible in the scope of error-kit, though, right? |
| 07:27 | Chouser | what's not horrible, continuations? |
| 07:28 | cemerick | within the scope of using error-kit facilities, requiring people to work with a separate, reified environment |
| 07:28 | cemerick | penalty there, certainly |
| 07:29 | Cark | i'm trying to use clojure.contrib.pprint/pprint it works ok in the repl, but i can't seem to make it work from an executable jar file, any idea on how i could make it work ? |
| 07:29 | Chouser | oh, I see. But building that kind of reified env is more than I'd like to do. So far I've avoided any real code-walking. |
| 07:30 | Chouser | my problem is that the body of a 'handle' form is a closure, so that it can use names from the 'with-handler' scope. But since the handler can do 'continue-with' which requires it be executed in the dynamic and call-stack scope of the 'raise' |
| 07:31 | Chouser | that's all fine until someone tries to 'recur' from inside a 'handle' form, excepting it to jump back to a 'loop' outside of the 'with-handler' |
| 07:31 | cemerick | ah, I get it |
| 07:31 | cemerick | well, how does CL do it in the face of goto? |
| 07:32 | Chouser | no idea. But since it has neither 'continue-with' (as far as I can tell) nor 'recur', it may just not have that problem. |
| 07:33 | cemerick | well, recur is just a special case of goto |
| 07:34 | cemerick | continue-with (if I understand the semantics) is the trickier problem, it seems. That's a big jump from an error providing a set of fixed restart options. |
| 07:35 | cemerick | Cark: what error/problem are you seeing? |
| 07:35 | Cark | nothing, it just does not output a thing |
| 07:35 | Chouser | I already toss bits of extra data up the call stack -- I suppose I could provide a 'kit/recur' that causes the recur to happen at the right scope. |
| 07:36 | Chouser | I could even code-walk and try to replace 'recur' with 'kit/recur' where appropriate |
| 07:36 | cmvkk | that seems like the only option, if you're trying to remove a point of recurrance |
| 07:38 | Chouser | but I'm sure it's another strike against ever getting this into core (if there was any chance left anyway) |
| 07:38 | cmvkk | would it be possible for a no-recurring-fn special form to exist, out of curiosity? |
| 07:38 | cmvkk | an fn that doesn't affect recur, i mean |
| 07:39 | cemerick | Cark: I'm afraid I've never used it myself. In general, it sounds like *out* isn't being bound properly, or something similar. |
| 07:40 | cemerick | Chouser: seems like two separate issues: implementing delimited continuations, and secondly building error-kit on top of them |
| 07:40 | Cark | could be that, thanks cemerick |
| 07:43 | cgrand | Chouser: mutable state + ugly macroing can help you intercept a recur without code walking |
| 07:44 | cgrand | hmmm, no it won't work without knowing the number of args to recur which require code walking :-( |
| 07:45 | cemerick | hrm, more ammo for my decorate-fns-with-arity-info suggestion ;-) |
| 07:46 | Drakeson | how can I memoize a lazy Var? imagine (def fibs (lazy-cat (list 1 2) (map + fibs (drop 1 fibs)))) |
| 07:47 | Chouser | cgrand: how would I prevent 'recur' from just doing it's normal special-form thing? no macro or fn is going to get in the way, is it? |
| 07:48 | cgrand | I was thinking of introducing a... hmm wait, must check something |
| 07:53 | Cark | cemerick : output wasn't flushed before my program exited |
| 07:53 | Cark | thanks |
| 07:53 | cemerick | Cark: ah-ha! :-) |
| 07:53 | cemerick | heh, I didn't no anything |
| 07:56 | lisppaste8 | cgrand pasted "bad idea" at http://paste.lisp.org/display/78118 |
| 07:57 | kotarak | hiredman: a problem? |
| 07:57 | Chouser | ah! very nice. |
| 07:58 | Chouser | cgrand: where "nice" == "twisted and evil" |
| 08:01 | Chouser | cgrand: did you try using a variadic fn instead of loop? |
| 08:02 | Chouser | doesn't work, because recur wants you to pass the variadic part as a seq |
| 08:04 | Chouser | huh, you can't 'recur' from a catch or finally either. maybe not supporting 'recur' in a 'handle' isn't so bad. |
| 08:06 | triddell | Does anyone know of a change (in the last month or so) which would cause "Wrong number of args passed" error on gen-classed code that was working just fine before? |
| 08:08 | triddell | From Java I'm calling a function which then calls another Clojure function and I get this error now. The method which is called from Java includes "this" are the first argument but the inner call doesn't (and didn't need to before.) |
| 08:10 | triddell | Probably doesn't make much sense, but I'm calling a function with four arguments (which takes four arguments) and now I'm getting this error. |
| 08:15 | lisppaste8 | slashus2 pasted "stm test" at http://paste.lisp.org/display/78119 |
| 08:15 | slashus3 | Why doesn't await-for stop the agents after the timeout in this case? |
| 08:16 | slashus3 | oh... wait, I need to add print-agt to the await-for |
| 08:17 | slashus3 | I don't think that worked either. |
| 08:17 | slashus3 | And I am curious to why the print agent isn't printing anything. |
| 08:18 | slashus3 | Beware. Be sure to kill this process asap, it will eat up your memory. |
| 08:19 | cmvkk | well nothing gets sent to print-agt until after the other agents have finished |
| 08:20 | slashus3 | cmvkk: Why don't they timeout? |
| 08:20 | cmvkk | anyway, when i run that it returns for me |
| 08:21 | slashus3 | Does it return false? |
| 08:21 | cmvkk | yes. |
| 08:21 | cmvkk | after about 5 seconds, as expected. |
| 08:21 | slashus3 | You better kill the process. They are still running. |
| 08:21 | cmvkk | yeah. they are. |
| 08:21 | slashus3 | It will return nil if it returned because of a timeout, but it returns false? |
| 08:22 | cmvkk | yeah that's weird, because it's supposed to be nil or non-nil. |
| 08:22 | slashus3 | right |
| 08:22 | cmvkk | but if you wanted to test against it, why would you return false? |
| 08:22 | cmvkk | and being able to test against it is the point of returning nil or non-nil |
| 08:23 | slashus3 | I would think that it should kill all of the agents after the timout, but it just kills my computer slowly after returning. |
| 08:23 | slashus3 | That is why I am using await-for there. |
| 08:24 | slashus3 | I wanted it to print out the results of the two agents for 5 seconds and stop. |
| 08:24 | cmvkk | it's an infinite loop, and all it does is sen-off and commute. |
| 08:24 | cmvkk | assuming those things are waiting until after the original fn returns |
| 08:24 | cmvkk | then they just build up a huge queue, then when await-for stops them, they do all the send-offs at once? |
| 08:24 | cmvkk | maybe? |
| 08:25 | slashus3 | Well with each transaction, I would think there should be a send-off. |
| 08:25 | slashus3 | I would think that those prints would be interleaved with the other agents. |
| 08:25 | slashus3 | I know it is bad practice, but even if you use (println) it won't kill them after 5 seconds. |
| 08:29 | slashus3 | If await-for doesn't work in this case, how would you handle this situation? |
| 08:31 | slashus3 | :-( |
| 08:34 | slashus3 | There is no way to control agents with infinite loops? |
| 08:34 | kotarak | slashus3: you have to probably rewrite them to send to themselves. |
| 08:35 | slashus3 | kotarak: I guess that is the solution. await-for won't stop agents that have infinite loops. |
| 08:36 | kotarak | I think await only waits for them to finish. But maybe I'm mistaken... |
| 08:36 | kotarak | (doc await-for) |
| 08:36 | clojurebot | Blocks the current thread until all actions dispatched thus far (from this thread or agent) to the agents have occurred, or the timeout (in milliseconds) has elapsed. Returns nil if returning due to timeout, non-nil otherwise.; arglists ([timeout-ms & agents]) |
| 08:36 | slashus3 | apparently it returns false if the agent is still going after the timeout. |
| 08:43 | lisppaste8 | slashus2 annotated #78119 "stm test again" at http://paste.lisp.org/display/78119#1 |
| 08:43 | slashus3 | kotarak: This still doesn't stop when await-for is called. |
| 08:44 | kotarak | slashus3: I don't think, that await-for stops something. |
| 08:46 | kotarak | You'll have to use some flag: (send *agent* (fn this-fn [_] (when @*running* (send *agent* this-fn)))), when you want to stop the agent loop, you have to do a (reset! *running* false) (assuming that *running* is an atom) |
| 08:46 | Lau_of_DK | Good evening all |
| 08:46 | kotarak | Hi Lau |
| 09:09 | cgrand | Chouser: varidic support in recur was what I checked just before pasting :-) |
| 09:22 | twansit | Hello all! |
| 09:22 | Lau_of_DK | Yo dude |
| 09:22 | twansit | question what is the most effecient way to turn a json object to a clojure object with the keys as keywords? |
| 09:23 | twansit | or is it just not advisable |
| 09:23 | danlarkin | (json/decode-from-str string) of course! |
| 09:23 | twansit | ah..is that in clojure-contrib? |
| 09:24 | danlarkin | there is a json lib in contrib yes, but there's also clojure-json |
| 09:24 | twansit | yeah the contrib version doesn't do this |
| 09:25 | kotarak | o.O sheesh I really got out of sync with contrib... |
| 09:25 | twansit | danlarkin : i see you are plugging yourself :) |
| 09:25 | danlarkin | somebody's gotta :) |
| 09:27 | hiredman | ~google clojure-json |
| 09:27 | clojurebot | First, out of 1880 results is: |
| 09:27 | clojurebot | danlarkin's clojure-json at master - GitHub |
| 09:27 | clojurebot | http://github.com/danlarkin/clojure-json/tree/master |
| 09:27 | twansit | gittin |
| 09:27 | twansit | gittin' it |
| 09:28 | kotarak | hiredman: why do you hit my poor vc? |
| 09:28 | hiredman | clojurebot uses clojure-json for google search results |
| 09:28 | hiredman | kotarak: I retract my hitting |
| 09:29 | kotarak | hiredman: oh ok, thought there was a problem ... |
| 09:30 | hiredman | I am getting weird indentation, but it is on a scrap file, so maybe I have a unbalanced paran somewhere |
| 09:30 | kotarak | ok, hopefully. There are some corner cases. But they should happen rarely. |
| 09:31 | twansit | danlarkin: thanks! |
| 09:33 | danlarkin | twansit: my pleasure |
| 09:38 | erohtar_ | is there a way to pass a dynamically constructed vector to the binding form? |
| 09:39 | kotarak | erohtar_: (try (clojure.lang.Var/pushThreadBindings {varA valA varB valB}) ..... (finally (clojure.lang.Var/popThreadBindings))) |
| 09:52 | pjstadig | clojurebot: what is our mascot? |
| 09:52 | clojurebot | the official mascot of clojure is a futuristic ninja robot |
| 09:54 | Lau_of_DK | pjstadig, I was under the impression that danlarkin was our mascot? |
| 09:54 | danlarkin | oh jeez |
| 09:55 | pjstadig | Lau_of_DK: danlarkin is a futuristic ninja robot??!!! |
| 09:55 | opqdonut | wow! |
| 09:55 | Chouser | that's so much better than any of the historical ninja robots |
| 09:55 | Lau_of_DK | Thats certainly true |
| 09:56 | pjstadig | historical ninja robots are so 1999 |
| 09:56 | Lau_of_DK | ~at least the were so 1999, when suddenly... |
| 09:56 | clojurebot | CLABANGO! |
| 09:56 | pjstadig | clojurebot: historical ninja robots is <reply>historical ninja robots are so 1999... |
| 09:56 | clojurebot | In Ordnung |
| 09:56 | pjstadig | ~historical ninja robots |
| 09:56 | clojurebot | historical ninja robots are so 1999... |
| 09:57 | pjstadig | clojurebot: futuristic ninja robots is <reply>sooo much better than historical ninja robots |
| 09:57 | clojurebot | c'est bon! |
| 09:57 | pjstadig | ~futuristic ninja robots |
| 09:57 | clojurebot | sooo much better than historical ninja robots |
| 09:58 | pjstadig | hiredman: these are facts that should have been programmed into clojurebot from the beginning....I'm astonished! |
| 09:59 | erohtar__ | kotarak: sorry - having network problems today |
| 11:08 | taggart | Can anyone see where I'm ging wrong with this port of an SICP example? |
| 11:08 | taggart | (def fibs (lazy-seq (cons 0 (cons 1 (map + (next fibs) fibs))))) |
| 11:09 | taggart | getting a stack overflow so it's not as lazy as I had hoped |
| 11:12 | Chouser | the problem is that cons is not itself lazy |
| 11:13 | Chouser | so as soon as you try to take one value from fibs, it computes 0 and 1 and (map ...) |
| 11:13 | taggart | I thought that was dealt with by the lazy-seq |
| 11:13 | Chouser | lazy-seq only makes one level lazy |
| 11:13 | taggart | ahh |
| 11:14 | Chouser | without it, you'd get the overflow as soon as you def, instead of only after you try to take something from it |
| 11:14 | taggart | map is lazy though, so wouldn't I just the 0 and 1 be resolved immediately? |
| 11:15 | Chouser | map is lazy, but cons is not. the second cons forces map to do one step |
| 11:16 | taggart | ah, and then the cycle starts |
| 11:16 | taggart | got it, thx |
| 11:16 | Chouser | ...which in turn forces fibs itself, which does the cons's, ... right. |
| 11:16 | Chouser | so find the one expression that you need to delay, and put lazy-seq around that instead. |
| 11:17 | taggart | (def fibs (lazy-seq (cons 0 (lazy-seq (cons 1 (lazy-seq (map + (next fibs) fibs))))))) |
| 11:17 | Chouser | I keep forgetting to try a more Socratic method. |
| 11:17 | kotarak | Why so many lazy-seqs? |
| 11:17 | taggart | I guess I really only need one around map? |
| 11:18 | Chouser | "so where would you put lazy-seq to avoid the recursion?" |
| 11:18 | Chouser | "what is the value of delaying the evaluation of the constants 0 and 1?" |
| 11:18 | Chouser | :-) |
| 11:18 | taggart | nada |
| 11:19 | taggart | (def fibs (cons 0 (cons 1 (lazy-seq (map + (next fibs) fibs))))) |
| 11:19 | taggart | woot |
| 11:19 | opqdonut | :) |
| 11:21 | Chouser | How would the 'fibs' definition look if it were written by scgilardi and put in clojure.contrib.lazy-seqs? |
| 11:22 | pjstadig | what is the air speed of a swallo? |
| 11:22 | pjstadig | *swallow |
| 11:22 | Chouser | ~google what is the air speed of a swallow? |
| 11:22 | clojurebot | First, out of 227000 results is: |
| 11:22 | clojurebot | What is the air-speed velocity of an unladen swallow |
| 11:22 | clojurebot | http://indianajones.arystoteles.pl/swallow.htm |
| 11:43 | lisppaste8 | slashus2 pasted "stm test again" at http://paste.lisp.org/display/78128 |
| 11:45 | slashus3 | What is causing the strange print results? Since running was set to false and I await all of the agents, should the function only return when all of the agents are finished? |
| 11:46 | Chouser | await only waits for actions dispatched from the current thread or agent. |
| 11:48 | stuhood | its probably implemented as some kind of sentinel value in the queue that the agent acts on to call back to the awaiting thread |
| 11:48 | stuhood | ~def await |
| 11:49 | stuhood | yea |
| 11:50 | slashus3 | How would I go about keeping the function from returning until all of the agents have finished their business? |
| 11:51 | Chouser | you could use CountDownLatch yourself. |
| 11:51 | slashus3 | Is there any other way? |
| 11:52 | Chouser | genearlly if you need specific blocking behavior for task management, you'll need to use something from java.util.concurrent |
| 11:53 | slashus3 | I think I found the solution. |
| 11:53 | Chouser | One exception is 'future', but I doubt that would help you here. |
| 11:54 | lisppaste8 | slashus2 annotated #78128 "fixed?" at http://paste.lisp.org/display/78128#1 |
| 11:54 | slashus3 | Chouser: I made the send-off the last thing in the agent. |
| 11:54 | slashus3 | I guess it sort of fixes the problem? |
| 11:55 | kotarak | Where do the file and line information in the exceptions come from? I set Compiler/LINE and Compiler/SOURCE, but get only Unknown Source... |
| 11:56 | stuhood | slashus3: you'd still have a race |
| 11:56 | Chouser | slashus3: not really. I'm still seeing extra prints after the fn returns |
| 11:56 | Chouser | slashus3: and I don't think await is doing you any good there. |
| 11:57 | stuhood | anything generated by the last action sent to the agent will go into the queue after the Latch sent in by (await) |
| 11:57 | slashus3 | Mine counts to 49 every time. I suppose I may get that result if I run it enough times. |
| 11:58 | Chouser | kotarak: (binding [*source-path* "foo"] (eval '(asdf))) |
| 11:58 | Chouser | that works for me. |
| 11:58 | slashus3 | Would it make the difference than I am on a single core computer? |
| 11:59 | stuhood | slashus3: that might hide the race condition, yea |
| 11:59 | kotarak | Chouser: Hmm.. *source-path*. Is this handled in the Reader? The compiler seems to use Compiler/SOURCE.... |
| 11:59 | Chouser | kotarak: those are the same Var |
| 12:00 | slashus3 | ugh... I didn't think this would be so hard. |
| 12:00 | Chouser | ,clojure.lang.Compiler/SOURCE |
| 12:00 | clojurebot | #'clojure.core/*source-path* |
| 12:00 | kotarak | hmmmm..... |
| 12:01 | Chouser | slashus3: why don't you want to use CountDownLatch? make one that starts at 2, then have each agent action countdown when they quit running. |
| 12:01 | Chouser | then you can await on the latch, and it'll block until they're done. |
| 12:02 | slashus3 | Chouser: I need to figure out how to use it. |
| 12:02 | Chouser | slashus3: or perhaps stop having the agents send to themselves -- do a regular loop that terminates if @running is false. Then await should do what you want. |
| 12:02 | clojurebot | we can't stop here! this is bat country! |
| 12:02 | stuhood | i think rhickey chose to call them Agents instead of 'Actors' for a reason: the mainloop case isn't what he was going for |
| 12:03 | Chouser | though that's how he uses them in the ant demo |
| 12:03 | stuhood | hmm. |
| 12:04 | stuhood | so its a single agent call then, with a function containing an infinite loop?" |
| 12:04 | slashus3 | It sends-off itself |
| 12:04 | Chouser | oh, no, I meant the send-to-self loop |
| 12:04 | Chouser | right |
| 12:05 | stuhood | weird. |
| 12:05 | kotarak | Chouser: sorry, I have to ask again. I want to set the file and line numbering and the eval some def. I would expect, that then the source info is set correctly. But in the stack trace only "Unkown Source" shows up.... |
| 12:05 | Chouser | the main reason I've heard for using send-to-self rather than a loop/recur is so that you can redef the action and get new behavior without restarting anything. |
| 12:06 | kotarak | Is there a remedy? |
| 12:06 | Chouser | kotarak: the example I posted above gives me this error: java.lang.Exception: Unable to resolve symbol: asdf in this context (foo:39) |
| 12:06 | stuhood | Chouser: that's true, but implementation wise your loop would be moving between threads and cores on your cpu, which would suck for performance |
| 12:06 | hiredman | Chouser: also so sends get released |
| 12:06 | Chouser | so it looks like it's getting the source name ok. I'm not sure about the line number. |
| 12:07 | kotarak | -.- |
| 12:07 | kotarak | Ok. Will try again. |
| 12:07 | Chouser | stuhood: hm could be, though moving between threads doesn't necessarily mean moving between cores, right? |
| 12:08 | kotarak | For the line number, I have this by the way: (proxy [LineNumberingPushbackReader] [reader] |
| 12:08 | kotarak | (getLineNumber [] (+ offset (proxy-super getLineNumber))))) |
| 12:08 | kotarak | Proxy is cool. :) |
| 12:08 | stuhood | perhaps the agent could simple loop calling a defn'd fun, and then you could redefine the fun |
| 12:08 | erohtar_ | i have to ask again (having network problems) - |
| 12:08 | slashus3 | Should I be using regular java threads with this, or is this the right way to model the problem? |
| 12:08 | clojurebot | ? |
| 12:08 | erohtar_ | is there a way to use the binding form meta-programmatically |
| 12:09 | kotarak | erohtar_: you have to use Var/push(pop)ThreadBindings directly. |
| 12:10 | erohtar_ | kotarak: those methods accept a map? the vars are passed as keys? |
| 12:10 | kotarak | erohtar_: yes, what binding uses underneath. |
| 12:11 | erohtar_ | where can i find the documentation? |
| 12:11 | slashus3 | I have no idea how to use CountDownLatch here. |
| 12:11 | slashus3 | Do I send the latch to the agent? |
| 12:11 | erohtar_ | kotarak: where can i find the documentation? is there javadoc? |
| 12:11 | stuhood | slashus3: it would be in a var, like 'running' |
| 12:11 | kotarak | erohtar_: no, but you can look at the definition of binding |
| 12:12 | erohtar_ | ok |
| 12:12 | kotarak | ~def binding |
| 12:12 | stuhood | slashus3: when the agents are done running, have them .countDown on the latch |
| 12:12 | slashus3 | (.countDown agt alatch) |
| 12:12 | erohtar_ | kotarak: will do, thanks! |
| 12:13 | Chouser | (defmacro nil-binding [n & body] (apply @#'binding [n nil] body)) |
| 12:13 | Chouser | kotarak: how about that? |
| 12:14 | Chouser | hm |
| 12:15 | Chouser | wait, what's wrong again with: (defmacro nil-binding [n & body] `(binding [~n nil] ~@body)) |
| 12:15 | stuhood | slashus3: (.countDown alatch) |
| 12:16 | stuhood | Chouser: perhaps what is missing is some kind of agent shutdown functionality that prevents new items in the queue for the agent |
| 12:16 | clojurebot | Chouser might make night |
| 12:17 | kotarak | Chouser: I'm not sure what's the nil about, but I want a driver for binding that takes a map (programmatically created at runtime) and a thunk being invoked as the body. A macro won't help here. |
| 12:17 | Chouser | stuhood: well, there is shutdown-agents, but that's rather a large hammer |
| 12:17 | Chouser | kotarak: ah, right of course. Sorry, took my eye off the ball there. |
| 12:17 | slashus3 | (shutdown-agents) messes up everything after that. Maybe something a little lighter wait. |
| 12:17 | slashus3 | weight* |
| 12:18 | stuhood | slashus3: yea |
| 12:19 | slashus3 | I am looking at the source code for await, and I don't see what I would do that would be different than what await does with CountDownLatch. |
| 12:19 | Chouser | so right, you have to use the static methods of Var directly. |
| 12:20 | stuhood | slashus3: await adds the latch to the end of the agent queue, but the agent is running in a separate thread, and it can add an item after the latch |
| 12:22 | stuhood | so immediately after await returns, it will run the queued action |
| 12:23 | stuhood | actually, i guess you could await it twice? |
| 12:24 | stuhood | ah, no. |
| 12:25 | Chouser | you need to make sure the countDown is done after the agent has noticed that @running is false |
| 12:25 | Chouser | I think the only way to do that is in the agent action itself -- when it sees @running false, countDown. |
| 12:26 | slashus3 | Chouser: I tried running the agent's body in a (while @running , but the output just bursts out at the end, and I still get some weird output. |
| 12:26 | stuhood | slashus3: actually, i think running await twice will work |
| 12:27 | Chouser | hm, that's an interesting point -- you might need to (flush) too, to prevent output coming after the prompt. |
| 12:27 | slashus3 | stuhood: It seems like it should. |
| 12:28 | stuhood | because the first time guarantees that the @running has been seen, and the second time makes sure that the final action queued from within the agent is cleared |
| 12:28 | slashus3 | That isn't a very elegant solution though. |
| 12:28 | slashus3 | If that is the case, in the await function, could you just (send agent count-down) twice? |
| 12:29 | stuhood | no, you have to wait for the first (await) to return |
| 12:29 | slashus3 | okay |
| 12:29 | stuhood | because when it returns there may-or-may-not be one last action sitting in the queue, which you need to wait for |
| 12:30 | slashus3 | I think await would be more useful if it had the wait until all queued agents were finished. |
| 12:31 | stuhood | agreed. |
| 12:32 | stuhood | maybe (await-shutdown) that would prevent new actions for an agent |
| 12:32 | slashus3 | (await-shutdown agt1 agt2 print-agt) |
| 12:37 | slashus3 | maybe (await-shutdown can be implemented by just calling await twice on the agents sent in? |
| 12:37 | stuhood | the only problem would be the agent api changes: (send) would need a 'agent is shut down' failure case |
| 12:37 | stuhood | slashus3: that works here because you only have two threads adding to the agent queue |
| 12:37 | slashus3 | Wait, that only works because I am using *running* |
| 12:37 | slashus3 | Okay, yeah |
| 12:39 | stuhood | slashus3: maybe you could bring this use case up on the list? |
| 12:39 | stuhood | you shouldn't have to resort to java code to accomplish this |
| 12:39 | slashus3 | I wonder what would be the best way to present it? With this example? |
| 12:40 | stuhood | you only need 1 agent to demonstrate it |
| 12:43 | stuhood | oh... (send) already has an error case if (shutdown-agents) has been run |
| 12:44 | stuhood | so there would be good symmetry with a (shutdown-agent) function |
| 12:45 | kotarak | Chouser: just for the records: the Vars to modify are SOURCE and SOURCE_PATH. I'm not sure, but it seems, that one has to set both... Now it works. :D |
| 12:46 | slashus3 | stuhood: Would we have to use that exception when we determine if there are no agents in the agent queue? |
| 12:46 | slashus3 | Can't we just loop through the agents and (.getQueueCount a) |
| 12:47 | slashus3 | When all of the agent's (.getQueueCount a) is zero, we are finished? |
| 12:51 | slashus3 | Hmm this seems to work. |
| 12:53 | lisppaste8 | slashus2 annotated #78128 "fixed??!" at http://paste.lisp.org/display/78128#2 |
| 12:53 | slashus3 | stuhood: Check this out. |
| 12:55 | slashus3 | Maybe I should await before the while in that function. |
| 12:57 | slashus3 | stuhood: Because not-every is not atomic, I want to be sure that there are no further agents being emitted. |
| 12:57 | slashus3 | sent |
| 12:57 | slashus3 | Then I would wait until the queue was empty. |
| 13:01 | lisppaste8 | slashus2 annotated #78128 "added await to the await-shutdown" at http://paste.lisp.org/display/78128#3 |
| 13:02 | slashus3 | Chouser: Would this be an acceptable solution? |
| 13:08 | rosejn | Should any object implementing Associative be usable both like (obj :foo) and like (:foo obj)? |
| 13:08 | rosejn | I'm implementing it in a proxy for a storage layer, and it only works with the key first. |
| 13:08 | slashus3 | That seems to be the case. |
| 13:10 | rosejn | It seems that this error shouldn't be feasible then: |
| 13:10 | rosejn | actual: java.lang.ClassCastException: clojure.proxy.java.lang.Object$Associative cannot be cast to clojure.lang.IFn |
| 13:11 | slashus3 | hmm |
| 13:11 | slashus3 | Maybe not then. |
| 13:11 | rosejn | Yeah, strange... |
| 13:13 | kotarak | rosejn: It probably has to implement clojure.lang.IFn to be used in the functions position. |
| 13:13 | rosejn | hmmmm, ok. I'll give it a try. |
| 13:13 | rosejn | kotarak: thanks |
| 13:14 | kotarak | rosejn: invoke with one and two arguments is probably enough. (thing key) and (thing key default-if-not-found). This is the usual behaviour of maps, IIRC. You can have look at their implementation. |
| 13:17 | slashus3 | kotarak: Looks like AFn takes in IPersistentMap |
| 13:19 | slashus3 | rosejn: APersistentMap extends AFn, which takes in an IPersistentMap. |
| 13:29 | rosejn | awesome! |
| 13:29 | rosejn | kotarak: that worked, thanks |
| 13:29 | rosejn | just had to implement invoke |
| 13:29 | kotarak | rosejn: good to hear :) |
| 13:31 | rosejn | kotarak: Hey, you do vimclojure right? |
| 13:31 | kotarak | rosejn: right |
| 13:31 | rosejn | cool. Quick question. In a number of places it seems to indent more than I want it to. |
| 13:32 | kotarak | rosejn: do you have an example? |
| 13:32 | rosejn | For example: |
| 13:32 | rosejn | (deftest my-test [] |
| 13:32 | rosejn | (test-stuff ...)) |
| 13:32 | rosejn | Where I'd like the (test-stuff ...) to just be two spaces over. |
| 13:33 | kotarak | rosejn: ok. try this: :setlocal lw+=deftest |
| 13:33 | kotarak | Does this work for you? |
| 13:33 | rosejn | great |
| 13:33 | rosejn | yeah, that worked |
| 13:34 | kotarak | rosejn: You can put such clauses in ~/.vim/after/ftplugin/clojure/my-lispwords.vim. I'm working on some heuristic, but it will likely be fragile. |
| 13:35 | rosejn | got it, thanks for all the work you've done for vim |
| 13:35 | kotarak | np |
| 13:35 | rosejn | I'm using it daily now, with the repl and everything |
| 13:35 | rosejn | fairly often I get errors and I have to restart the ng-server though |
| 13:35 | rosejn | it would be nice if it could be started automatically |
| 13:36 | rosejn | also if there were a way to clear the repl state, to load libraries fresh |
| 13:36 | kotarak | Hmmm... I'll look into starting it automatically. However, the next version will be more robust on missing server. |
| 13:36 | rosejn | great |
| 13:36 | kotarak | you can reload libraries via (require :reload-all 'the.library) |
| 13:37 | rosejn | yeah, but weird errors can crop up on redefinition after refactoring things |
| 13:37 | rosejn | like moving a function from one namespace to another, where they were using each other |
| 13:37 | rosejn | it complains of multiple definitions, so you have to unmap the original |
| 13:38 | kotarak | Ah. Ok. That may happen. |
| 13:41 | kotarak | Hmm... Maybe some Repl command like ",nuke the.library". |
| 13:42 | rosejn | yeah, that would be perfect |
| 13:43 | rosejn | maybe it should be a different argument to require... (require :fresh 'my-lib) |
| 13:44 | rosejn | Actually, I guess those are just functions being called by require.... so a new function that nukes then reloads. |
| 13:47 | kotarak | rosejn: Thanks for the feedback. Gotta go to bed now. Bye. |
| 13:48 | rosejn | kotarak: thanks for the tools. Guten abend. |
| 14:11 | replaca | erohtar_: if you want to see an example of binding using runtime discovered maps, look at clojure/contrib/pprint/pprint.clj |
| 15:30 | cp2 | hiredman: kevin.clj for life ! |
| 15:31 | hiredman | kitten: totally |
| 15:31 | hiredman | er |
| 15:31 | hiredman | :( |
| 15:39 | cp2 | why are the clojure shirts on zazzle so expensiv |
| 15:39 | cp2 | e |
| 15:39 | cp2 | i dont want to pay like $60 for 3 shirts |
| 15:54 | Drakeson | how can I pop a certain element (nth) of a vector or list, whichever is easier? |
| 15:56 | cp2 | what would you name a 3 byte integer value? im trying to think of something that doesnt sound lame |
| 15:56 | hiredman | pop? |
| 15:57 | Drakeson | hiredman: I want to remove nth element of a vector/list |
| 15:58 | hiredman | Drakeson: vectors and lists are not designed for that sort of behaviour |
| 15:58 | hiredman | you might look at filter or remove |
| 15:59 | cp2 | hiredman: any suggestions ? :) |
| 15:59 | hiredman | tryte |
| 15:59 | cp2 | ah |
| 15:59 | cp2 | i like that |
| 15:59 | cp2 | thanks |
| 16:03 | Drakeson | hiredman: deleting an element from a linked-list is very cheap, once you can refer to the element. It sounds a bit strange if it is not implemented here. |
| 16:03 | Drakeson | so, I guess I am missing something |
| 16:06 | hiredman | ,(doc pop) |
| 16:06 | clojurebot | "([coll]); For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. If the collection is empty, throws an exception. Note - not the same as next/butlast." |
| 16:07 | hiredman | Drakeson: but clojure's library is based around sequences, not linked lists |
| 16:08 | Cark | it isn't cheap to find the nth element of a list in order to delete it |
| 16:08 | Cark | that's what sets are there for |
| 16:08 | hiredman | (doc rvec) |
| 16:08 | clojurebot | Excuse me? |
| 16:08 | Cark | though i agree that this function is missing |
| 16:11 | Cark | ,(doc ordered-set) |
| 16:12 | clojurebot | java.lang.Exception: Unable to resolve var: ordered-set in this context |
| 16:12 | Cark | ,(doc order-set) |
| 16:12 | clojurebot | java.lang.Exception: Unable to resolve var: order-set in this context |
| 16:12 | Cark | ,(doc sorted-set) |
| 16:12 | clojurebot | "([& keys]); Returns a new sorted set with supplied keys." |
| 16:14 | Drakeson | Cark: thanks |
| 16:14 | Cark | this was for my information, not trying to help you ! |
| 16:15 | Cark | sometimes you need the ordered nature of a list and the add/remove capabilities of a set |
| 16:15 | Cark | that would require an ordered set data structure |
| 16:15 | Cark | but there is none in clojure |
| 16:15 | Drakeson | what I feel is missing (or I cannot find) is a standard way to point to an element (O(n) for finding nth in a list), and then call an imaginary pop-by-ref and get a new list without that element. |
| 16:16 | Cark | well you can use filter |
| 16:16 | Cark | it's "kind of" O(1) as it's lazy |
| 16:21 | cp2 | O(1) (no guarantees!) |
| 16:24 | stuhood | ~def c.l.Agent |
| 17:06 | dysinger | If I call (with-open #^javax.mail.Folder folder forms*) is it going to not work because close takes true/false (expunge) ? |
| 17:06 | dysinger | I can try it just curious |
| 17:06 | dysinger | if there was any magic |
| 17:06 | stuhood | ha, i had the same question and never tried it, because i assumed there wasn't =/ |
| 17:06 | stuhood | magic, that is |
| 17:09 | dysinger | that's what I figured |
| 17:09 | dysinger | you only get so much magic for free |
| 17:10 | stuhood | i love with-open though |
| 17:11 | stuhood | it's more complete in python, with the 'with' statement and context managers |
| 17:11 | dysinger | yeah - ruby has similar with closure blocks |
| 17:14 | stuhood | i guess the java way would be to add an interface that an object could implement to play nicely with 'with-open' |
| 17:14 | stuhood | and otherwise clojure would just attempt to call close() |
| 17:15 | dysinger | or you could wrote an alternate macro |
| 17:15 | stuhood | mm, indeed |
| 17:15 | stuhood | ~def with-open |
| 17:33 | dakrone_hb | is anyone else having trouble building clojure-contrib using the clojure jar from svn? |
| 17:34 | Raynes | dakrone_hb: What do you mean by building? Compiling it? Usually you just jar it or copy the directories. |
| 17:34 | dakrone_hb | Raynes, http://pastie.org/439181 |
| 17:35 | dakrone_hb | I was under the impression that you needed to build it |
| 17:36 | dakrone_hb | given the Getting Started page lists building it with ant |
| 17:36 | Raynes | dakrone_hb: Just cd to the directory of clojure-contirbs build file and "ant build" |
| 17:37 | dakrone_hb | Raynes, Target "build" does not exist in the project "clojure-contrib". |
| 17:37 | dakrone_hb | is the error |
| 17:37 | danlarkin | dakrone_hb: yeah, just "ant" |
| 17:37 | dakrone_hb | danlarkin, yea, I get http://pastie.org/439181 |
| 17:37 | danlarkin | you don't need to specify clojure.jar |
| 17:37 | Raynes | I didn't mean to quote build, just ant. |
| 17:38 | danlarkin | that's only if you want to AOT compile |
| 17:38 | dakrone_hb | danlarkin, even though it warns that I should? |
| 17:38 | dakrone_hb | oh, okay |
| 17:38 | dakrone_hb | it warns things like pretty print won't work |
| 17:38 | Raynes | Enclojure has some neat new REPL features! |
| 17:38 | dakrone_hb | is thhat correct? |
| 17:38 | Raynes | :D |
| 17:38 | danlarkin | is your clojure up to date? |
| 17:39 | danlarkin | make sure you're on the google code SVN and not the sourceforge SVN |
| 17:39 | Raynes | All it does is jar everything, you don't even really have to jar it at all. All the ant script does is jar whats in src. |
| 17:39 | dakrone_hb | danlarkin, Ahhhhhhhhhh |
| 17:39 | dakrone_hb | danlarkin, it's been a while since I checked out ;) |
| 17:39 | dakrone_hb | danlarkin, how long ago did Clojure switch? |
| 17:40 | danlarkin | December? I think? |
| 17:40 | dakrone_hb | that would definitely be some changes |
| 17:41 | dakrone_hb | danlarkin, I'm sure this will fix it, thank you much |
| 17:45 | danlarkin | dakrone_hb: let us know if it doesn't |
| 17:46 | hiredman | ~latest |
| 17:46 | clojurebot | latest is 1338 |
| 17:51 | dakrone_hb | danlarkin, worked great, thanks :) |
| 17:59 | danlarkin | dakrone_hb: fantastic |
| 17:59 | dysinger | whats the best idiom for recur on exception with a finally ? |
| 18:00 | dysinger | it says I cant recur because my recur is not on the tail |
| 18:02 | dysinger | ~(loop [x 1] (try (println "hello") (catch Throwable t (recur x)))) |
| 18:02 | clojurebot | BUENOS DING DONG DIDDLY DIOS, fRaUline dysinger |
| 18:03 | dysinger | seems like retry on exception is common enough for IO stuff |
| 18:03 | dysinger | at least for the computerwebs and tcp/ip |
| 18:04 | dreish_ | The only think I can think of would be a little ugly, so I'd wrap it in a macro, but you could return either a value or the exception, then check outside the try; if it's an exception, recur. |
| 18:05 | danlarkin | you could also possibly use a trampoline |
| 18:05 | dreish_ | (defmacro retry-on-exception [& exprs] ...) |
| 18:11 | dysinger | clojure so totally scratches my lisp itch but with tens of thousands of libs |
| 18:11 | dysinger | yayz |
| 18:28 | replaca | dakrone_hb: I just added the pretty print stuff to contrib and it require AOT, thus the warning |
| 18:28 | replaca | so now it's better to do a "real" compile |
| 18:29 | Chouser | replaca: was requiring AOT necessary or just convenient? |
| 18:30 | replaca | Chouser: necessary, cause I need to make classes that wrap java.io.Writer |
| 18:30 | replaca | *needed |
| 18:30 | Chouser | and proxy was insufficient? |
| 18:30 | replaca | Chouser: remember our discussions from a *looong* time ago |
| 18:31 | Chouser | heh. apparently not. |
| 18:31 | replaca | I tried super-hard to make proxy work but it just didn't have what I needed |
| 18:31 | Chouser | you needed some state and a sane way to get at it from the object itself? |
| 18:31 | replaca | I came up with an idea for a super-proxy, but I haven't done that yet |
| 18:31 | replaca | yeah, there's actually a lot of state in the current application |
| 18:32 | Chouser | I've gotten into the habit recently of deriving a proxy class from something and also implementing IDeref |
| 18:32 | replaca | cause all the info is kept in the writer |
| 18:32 | dakrone_hb | I'm sorry for the dumb question, but what does AOT stand for? |
| 18:32 | clojurebot | for is not used often enough. |
| 18:33 | replaca | Ahead of time compilation |
| 18:33 | dakrone_hb | replaca, ahh, thanks |
| 18:33 | Chouser | then I can implement the deref method, and use @ to get at whatever object state I need. |
| 18:33 | replaca | But really, Chouser :gen-class is not something to be afraid of! |
| 18:34 | Chouser | I don't fear it. I dislike it. |
| 18:34 | replaca | :-) |
| 18:34 | hiredman | not afraid, annoyed by |
| 18:34 | Chouser | "make" is for C++ and Java. |
| 18:35 | replaca | But, more to the point, PrettyWriter has a bunch of methods on the class that make sense as methods |
| 18:35 | slashus2 | Chouser: Sorry to bring this up again, but did you ever see my solution to the agent problem? |
| 18:35 | replaca | Chouser: or Lisp or Haskell - everything but perl, ruby and python |
| 18:36 | replaca | and even python guys use the compiler for stuff they load all the time |
| 18:36 | replaca | thus the plethora of .pyc files |
| 18:37 | Chouser | slashus2: interesting. I assume it works? |
| 18:38 | slashus2 | Chouser: It seems to work on my dual core machine. |
| 18:38 | Chouser | replaca: optional AOT for performance or whatever doesn't bother me, but Clojure is has so much less state than other systems, it's a shame to require the on-disk state of compilation just to accomplish a particular task. |
| 18:38 | replaca | One nice thing about :gen-class is that the implementation can be completely dynamic, only the interface requires loading |
| 18:38 | slashus2 | Chouser: I think the function should probably be called await-finished instead of await-shutdown. |
| 18:38 | Chouser | replaca: yes, it's a pretty impressive compromise, but still not as nice as proxy. |
| 18:38 | replaca | Chouser: yeah, I hear you. Unfortunaltely what I was doing here was really writing a Java class in clojure |
| 18:39 | replaca | Chouser: if proxy worked for the use case, yes :-) |
| 18:39 | slashus2 | Chouser: Maybe I should make a proposal on the list? |
| 18:39 | Chouser | slashus2: two possible issues: you're doing a busy wait after the blocking await, and you're using an implementation detail of agents |
| 18:39 | replaca | the alternative was pretty limiting, where you wouldn't be able to be pretty across calls |
| 18:40 | Chouser | replaca: hm. giving up user features isn't acceptible. |
| 18:40 | replaca | which would be nasty for apps that were reformatting larger chunks of stuff |
| 18:40 | Chouser | slashus2: of the two, the busy wait would bother me more. |
| 18:40 | replaca | but I still like the idea of a super-proxy :-) |
| 18:40 | slashus2 | Chouser: Is there a way to do it without the busy wait? |
| 18:44 | Chouser | slashus2: it's important to be mixing refs and agents like this? |
| 18:46 | slashus2 | huh? |
| 18:46 | Chouser | agt1 and agt2 sotre state that you apprently aren't using |
| 18:47 | Chouser | store |
| 18:47 | slashus2 | Chouser: I could probably do it a different way, but I was testing out refs. |
| 18:47 | Chouser | ok |
| 18:48 | slashus2 | It was only an exercise to learn the behavior of agents, etc. |
| 18:48 | Chouser | sure |
| 18:48 | Chouser | I'm just feeling out the constraints of your exercise. :-) |
| 18:49 | slashus2 | There are probably many situations were you would want to wait until all of the agents finish their queues before returning a function. |
| 18:54 | lisppaste8 | Chouser annotated #78128 "a couple options for slashus2" at http://paste.lisp.org/display/78128#4 |
| 18:54 | hiredman | slashus2: I would uses agents for that |
| 18:54 | hiredman | er |
| 18:54 | hiredman | wouldn't |
| 18:55 | hiredman | for map/reduce you can use pmap/reduce |
| 18:55 | hiredman | pmap uses the agent threadpool via futures |
| 18:56 | replaca | Chouser: do you have some examples of your proxy + Ideref solution - I'll look at that and see if I could use it |
| 18:57 | slashus2 | Chouser: So there is no general solution like my await-shutdown that doesn't use a busy wait? |
| 18:58 | Chouser | slashus2: oh, there may be... perhaps using watchers or something. |
| 18:59 | slashus2 | hiredman: I know this isn't the best way to do this, but I was just wanting to try out the behavior of the STM. |
| 19:00 | Chouser | replaca: this is on a different topic, but includes an example of proxying IDeref to carry some mutable state: http://groups.google.com/group/clojure/msg/79a09fa877cb48d0 |
| 19:01 | replaca | Chouser: thanks, I'll check it out |
| 19:02 | Chouser | ok, g'night all. |
| 19:02 | slashus2 | Chouser: Hmm. Watchers monitor for a change of state... goodnight |
| 19:03 | replaca | goodnight Chouser |
| 19:09 | slashus2 | I wonder why I would want to use a watcher inside of a watch in this case. |
| 19:09 | slashus2 | instead* |
| 19:23 | rlb | Is there already any easy way to treat a large binary file of 64-bit integrers as a (lazy) sequence? |
| 19:24 | rlb | s/integrers/integers/ |
| 19:35 | replaca | rlb: not that I know of, but duck-streams/read-lines does it with strings. Maybe you could adapt it? |
| 20:42 | banisterfiend | what's the name of the clojure repl? |
| 20:43 | rlb | replaca: ok, thanks. One of the things I'm trying to do is keep track of what's effectively a 10 or so million element hash table mapping 128-256 bit values to an integer triple. I may just use sqlite or jdbm, but I was just looking around clojure itself... |
| 20:43 | rlb | banisterfiend: in debian, it's clojure-repl, but otherwise I just invoked it manually. |
| 20:43 | rlb | banisterfiend: If you mean the class, it's clojure.lang.Repl. |
| 20:44 | banisterfiend | thx |
| 20:44 | rlb | and if you want readline-alike: |
| 20:44 | rlb | java -cp /usr/share/java/jline-0.9.94.jar:/usr/share/java/clojure.jar:/usr/share/java/asm3-commons.jar:/usr/share/java/asm3.jar jline.ConsoleRunner clojure.lang.Repl |
| 20:44 | banisterfiend | is tehre another name for the repl? |
| 20:44 | banisterfiend | i think i installed it ages ago, but i cant remember what it's called |
| 20:44 | banisterfiend | clojure-repl doesn't work |
| 20:45 | rlb | Well, the repl class is in clojure.jar. |
| 20:45 | rlb | (normally) |
| 20:47 | banisterfiend | thanks rlb |
| 20:47 | banisterfiend | you have mad skillz |
| 21:20 | cp2 | Microsoft Boasts 96% Netbook Penetration |
| 21:21 | cp2 | how very kinky |
| 22:57 | tsdh | Hi. In my clojure code I want to run a java classes main method. That's no problem, but is it also possible to do that in an own JVM with own JVM args? |
| 23:18 | cgrand | tsdh: if you want to start another JVM then there's no more facility than for starting a random program. See clojure.contrib.shell-out |
| 23:20 | tsdh | cgrand: Basically what I want is something like ant's fork, e.g. the new JVM should use the same classpath, etc. But ok, I'll use shell-out till I find something that suits my needs better. |