#clojure logs

2008-03-17

04:30arbschtis there anything like CL's return-from in clojure?
04:31hoecki guess no
04:32hoeckbut i wondered if one really needs it
04:33arbschtI'm writing a function that uses reduce, and I want to terminate and return the accumulated value upon encountering some condition
04:34arbschtwithout looping, I can't think of another way to do it
04:35hoeckyou could throw an exception, but i don't know wether that is `good' style
04:36arbschteurk, that would require encoding the value in a Throwable
04:36hoeckyeah, thats pretty ugly
04:37hoeckand what about filtering the sequence before reducing?
04:38arbschtorder matters, I'm parsing a list of symbols and some are terminators
04:40arbschtwell I suppose I could do a search and slice for this particular case
04:40arbschtnot sure if that's general enough or as elegant
04:45hoeckmhh
04:50hoeckthe problem is that `loop' blocks are not named
04:51hoeckso there is no way to `jump' out of (fn [] ..) :(
04:57arbschtwith loop I can choose not to recur
04:57arbschtnot possible to jump out of reduce
05:11arbschtoh lovely
05:11arbschttake* works
05:11arbschteven better than jumping out of reduce
05:12arbschtkids, this is why you don't try to port code across languages line by line
05:14hoeckwhat means better?
05:14hoeckshorter, clearer, simpler ?
05:14arbschtyep
05:15arbscht1 vs 11 loc
05:15arbschtit looks fine inline, no need to roll a function
05:20hoeckthats a lot of reduction
05:21arbschtthis is really typical of porting CL code to clojure I find
05:21arbschtmaybe not a factor of 11 but say 4 or 5 at least
05:21hoeckbut then it was bad cl code !?
05:21arbschtnot necessarily
05:22arbschtmaybe not the best but it's not convoluted or anything
05:22arbschtit's easily readable etc
05:24arbschtfor example, in swank they have an interface/implementation pattern that doesn't use generic functions
05:24arbschtinstead they clobber symbol-plists to overload
05:24arbschtlots of yak shaving there
05:25arbschtI rewrote that with clojure multimethods in less than half the space
05:26hoecki like them too
05:27hoeckbut the feature i'm using most is destructuring in let and fn
05:28arbschtI haven't had to use it yet!
05:28arbschtmainly because I'm rewriting cl stuff
05:28hoeckit's nice of you work with vectors and maps
05:28arbschtwell, I haven't used destructuring in let, but a little in fn
05:29arbschtright
05:30hoeckor functions that return multiple values, i always felt bad when i wrote those nested let/destructuring-bind/multiple-value-bind statements
05:31hoecknow everything is a single let :)
05:32arbschtyeah it seems d-b and m-v-b are not all that popular in cl code because of that
05:34hoeckso you're hacking a slime-backend for clojure?
05:34arbschtyeah
05:35arbschtI got a bogged down having to learn java.nio
05:35arbschtbsd sockets are so much easier :?
05:35arbscht:/
05:39hoeckmhh, i've never done any network stuff
05:42hoeckbut i prefer java libs to ffi bindings
05:42hoeckhave you sth. working yet?
05:45arbschtpartial
05:45arbschtmain loop starts but I need to figure out managing threads
05:45arbschtfirst time doing concurrency in java also
06:00hoeckyeah, it's pretty easy to start threads, start threads, start threads .... but i have no way of controlling them
06:01hoecki played a bit with java.lang.management
06:04hoeckand decided that i need som clojure code like list-threads and kill-threads
07:45arbschtcan someone give me a simple example of using set in a transaction with a ref
07:56hoeckthats called `ref-set' now
07:56arbschtoh
07:56hoeckset constructs a set from a seq
07:57arbschtthat explains a lot
07:57arbschtdoc's behind the times
07:57arbschtthanks
07:57hoeckyeah
10:00cgrandrhickey: 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:00rhickeythanks
10:01Chouserwhat's "take*"?
10:02arbschtChouser: the various take functions
10:02Chouserah. (doc take*) wasn't getting me anywhere.
10:03Chouser:-)
10:03arbschtheh
10:03rhickeydistinct now lazy
10:07Chouser":as"!?
10:08Chousersoi does [f & r :as xs] give you first, rest, and the whole thing?
10:08rhickeyyup
10:08Chouservery cool.
10:08rhickeyalso in map destructuring
10:17Chouseris that new?
10:17rhickeyno, always been in destructuring
10:17hoeckany suggestions on profiling clojure?
10:18Chouserok
10:18rhickeyhoeck: Netbeans has free profiler, but is not happy with non-Java source
10:22hoeckaha
10:22hoeckand the time macro? or is that too inaccurate??ERC>
10:23rhickeytime uses nanoTime()
10:27rhickeyadded if-let, when-let and replace
10:29hoeckhow is if-let used?
10:30rhickey(if-let name test then else) => (let [name test] (if name then else))
10:30rhickeyit's used in replace for an example
10:33rhickeysane alternative to anaphora
10:33hoecknice
10:38rhickeyon that note, nested #()s now disallowed
10:38Chouserheh. yeah, probably wise.
10:42rhickeyhoeck: also note that for 'manual' profiling, all defns are stored in vars...
10:43rhickeytherefore they can be dynamically rebound to counting versions, without changing code that uses them
10:46hoecki 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:48hoeckbut modifying (time ) seems easier right now :)
10:49rhickeyI don't mean to sway you from trying a native profiler - Clojure emits the correct SourceDebugExtensions that should aid debugging/profiling