2008-03-17
| 04:30 | arbscht | is there anything like CL's return-from in clojure? |
| 04:31 | hoeck | i guess no |
| 04:32 | hoeck | but i wondered if one really needs it |
| 04:33 | arbscht | I'm writing a function that uses reduce, and I want to terminate and return the accumulated value upon encountering some condition |
| 04:34 | arbscht | without looping, I can't think of another way to do it |
| 04:35 | hoeck | you could throw an exception, but i don't know wether that is `good' style |
| 04:36 | arbscht | eurk, that would require encoding the value in a Throwable |
| 04:36 | hoeck | yeah, thats pretty ugly |
| 04:37 | hoeck | and what about filtering the sequence before reducing? |
| 04:38 | arbscht | order matters, I'm parsing a list of symbols and some are terminators |
| 04:40 | arbscht | well I suppose I could do a search and slice for this particular case |
| 04:40 | arbscht | not sure if that's general enough or as elegant |
| 04:45 | hoeck | mhh |
| 04:50 | hoeck | the problem is that `loop' blocks are not named |
| 04:51 | hoeck | so there is no way to `jump' out of (fn [] ..) :( |
| 04:57 | arbscht | with loop I can choose not to recur |
| 04:57 | arbscht | not possible to jump out of reduce |
| 05:11 | arbscht | oh lovely |
| 05:11 | arbscht | take* works |
| 05:11 | arbscht | even better than jumping out of reduce |
| 05:12 | arbscht | kids, this is why you don't try to port code across languages line by line |
| 05:14 | hoeck | what means better? |
| 05:14 | hoeck | shorter, clearer, simpler ? |
| 05:14 | arbscht | yep |
| 05:15 | arbscht | 1 vs 11 loc |
| 05:15 | arbscht | it looks fine inline, no need to roll a function |
| 05:20 | hoeck | thats a lot of reduction |
| 05:21 | arbscht | this is really typical of porting CL code to clojure I find |
| 05:21 | arbscht | maybe not a factor of 11 but say 4 or 5 at least |
| 05:21 | hoeck | but then it was bad cl code !? |
| 05:21 | arbscht | not necessarily |
| 05:22 | arbscht | maybe not the best but it's not convoluted or anything |
| 05:22 | arbscht | it's easily readable etc |
| 05:24 | arbscht | for example, in swank they have an interface/implementation pattern that doesn't use generic functions |
| 05:24 | arbscht | instead they clobber symbol-plists to overload |
| 05:24 | arbscht | lots of yak shaving there |
| 05:25 | arbscht | I rewrote that with clojure multimethods in less than half the space |
| 05:26 | hoeck | i like them too |
| 05:27 | hoeck | but the feature i'm using most is destructuring in let and fn |
| 05:28 | arbscht | I haven't had to use it yet! |
| 05:28 | arbscht | mainly because I'm rewriting cl stuff |
| 05:28 | hoeck | it's nice of you work with vectors and maps |
| 05:28 | arbscht | well, I haven't used destructuring in let, but a little in fn |
| 05:29 | arbscht | right |
| 05:30 | hoeck | or functions that return multiple values, i always felt bad when i wrote those nested let/destructuring-bind/multiple-value-bind statements |
| 05:31 | hoeck | now everything is a single let :) |
| 05:32 | arbscht | yeah it seems d-b and m-v-b are not all that popular in cl code because of that |
| 05:34 | hoeck | so you're hacking a slime-backend for clojure? |
| 05:34 | arbscht | yeah |
| 05:35 | arbscht | I got a bogged down having to learn java.nio |
| 05:35 | arbscht | bsd sockets are so much easier :? |
| 05:35 | arbscht | :/ |
| 05:39 | hoeck | mhh, i've never done any network stuff |
| 05:42 | hoeck | but i prefer java libs to ffi bindings |
| 05:42 | hoeck | have you sth. working yet? |
| 05:45 | arbscht | partial |
| 05:45 | arbscht | main loop starts but I need to figure out managing threads |
| 05:45 | arbscht | first time doing concurrency in java also |
| 06:00 | hoeck | yeah, it's pretty easy to start threads, start threads, start threads .... but i have no way of controlling them |
| 06:01 | hoeck | i played a bit with java.lang.management |
| 06:04 | hoeck | and decided that i need som clojure code like list-threads and kill-threads |
| 07:45 | arbscht | can someone give me a simple example of using set in a transaction with a ref |
| 07:56 | hoeck | thats called `ref-set' now |
| 07:56 | arbscht | oh |
| 07:56 | hoeck | set constructs a set from a seq |
| 07:57 | arbscht | that explains a lot |
| 07:57 | arbscht | doc's behind the times |
| 07:57 | arbscht | thanks |
| 07:57 | hoeck | yeah |
| 10:00 | cgrand | rhickey: you're right. Despite http://bugs.sun.com/view_bug.do?bug_id=4140318 (which is closer to our bug) I'm filling a new bug. |
| 10:00 | rhickey | thanks |
| 10:01 | Chouser | what's "take*"? |
| 10:02 | arbscht | Chouser: the various take functions |
| 10:02 | Chouser | ah. (doc take*) wasn't getting me anywhere. |
| 10:03 | Chouser | :-) |
| 10:03 | arbscht | heh |
| 10:03 | rhickey | distinct now lazy |
| 10:07 | Chouser | ":as"!? |
| 10:08 | Chouser | soi does [f & r :as xs] give you first, rest, and the whole thing? |
| 10:08 | rhickey | yup |
| 10:08 | Chouser | very cool. |
| 10:08 | rhickey | also in map destructuring |
| 10:17 | Chouser | is that new? |
| 10:17 | rhickey | no, always been in destructuring |
| 10:17 | hoeck | any suggestions on profiling clojure? |
| 10:18 | Chouser | ok |
| 10:18 | rhickey | hoeck: Netbeans has free profiler, but is not happy with non-Java source |
| 10:22 | hoeck | aha |
| 10:22 | hoeck | and the time macro? or is that too inaccurate??ERC> |
| 10:23 | rhickey | time uses nanoTime() |
| 10:27 | rhickey | added if-let, when-let and replace |
| 10:29 | hoeck | how is if-let used? |
| 10:30 | rhickey | (if-let name test then else) => (let [name test] (if name then else)) |
| 10:30 | rhickey | it's used in replace for an example |
| 10:33 | rhickey | sane alternative to anaphora |
| 10:33 | hoeck | nice |
| 10:38 | rhickey | on that note, nested #()s now disallowed |
| 10:38 | Chouser | heh. yeah, probably wise. |
| 10:42 | rhickey | hoeck: also note that for 'manual' profiling, all defns are stored in vars... |
| 10:43 | rhickey | therefore they can be dynamically rebound to counting versions, without changing code that uses them |
| 10:46 | hoeck | i see, but i'm afraid of the overhead that my 'manual' profiling imposes, so i thought to first look for a native java profiler |
| 10:48 | hoeck | but modifying (time ) seems easier right now :) |
| 10:49 | rhickey | I don't mean to sway you from trying a native profiler - Clojure emits the correct SourceDebugExtensions that should aid debugging/profiling |