I give up. I don't know what's wrong and I don't want to just punt and go on to a totally different implementation. Can while loops have more that one statement in the body? Maybe it's something dumb.
I'm not turning my back on what people say about loop/recur or functional programming. I'm just trying to accomplish my original goal of constructing an iterative-looking example. I get the added benefit of learning how reference dereference works, while loops . . .and how to read the errors. Or not. I'm not making headway. I just want to get this out of my system, but I'm getting some class cast exception and no useful line number. Can you not set a variable to a vector? the definition passes (compiles?), but when I call it I get a runtime error. I've made the code as simple (broken down) as possible. listmerge works (because I didn't write it myself). (defn listmerge [l1 l2] (let [l1first (first l1) l2first (first l2)] (cond (empty? l1) l2 (empty? l2) l1 (< l1first l2first) (cons l1first (listmerge (rest l1) l2)) :else (cons l2first (listmerge (rest l2) l1)))))) (defn msort [toSort] (with-local-vars [my-list (for [x toSort] [x]) l1 0 l2 0] (while (rest @my-list) (var-set l1 (first @my-list)) (var-set l2 (second @my-list)) (var-set my-list (drop 2 @my-list)) (var-set my-list (concat @my-list (listmerge [...@l1] [...@l2])))) @my-list)) (msort [64 45 2 67 1]) Thanks again. On Mon, Jan 12, 2009 at 1:10 PM, James Reeves <weavejes...@googlemail.com>wrote: > > On Jan 12, 5:24 am, e <evier...@gmail.com> wrote: > > It's funny, whenever I tried to be all safe like this and take the time > to > > make stuff safe in C++, coworkers would say, "we are grown-ups. At some > > point you gotta stop being a paranoid programmer. > > Given that software bugs are a very common occurrence, I'd say we're > far from being paranoid enough :) > > > Another thing is to make the common case easy . . . .and uh, mutable > local > > variables are pretty darn common, > > In imperative languages, yes, but not really in functional languages. > I've written a fair amount of Clojure code, and I haven't used with- > local-vars once. > > - James > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---