Dave: I don't know if it will help you do it more succinctly, and I don't know whether with-local-vars is implemented in ClojureScript, but at least in Clojure with-local-vars is a way to have local mutable variables in a single-threaded piece of code, and know that the mutability stays local to that piece of code. It doesn't make the persistent data structures like maps and vectors mutable, but it allows you to write code with assignments and loops in a style somewhat more similar to the way you may be accustomed to in an imperative language.
There is an example on ClojureDocs.org here: http://clojuredocs.org/clojure_core/clojure.core/with-local-vars I suspect there is likely to be a more purely-functional way to write Clojure code with the desired behavior, and is succinct, but I tend to find that it takes a bit of time to come up with such solutions. It takes practice to get faster at it, that is for sure. Andy On Jun 6, 2012, at 5:46 AM, Dave Sann wrote: > Hi Stephen, thanks for the answer. > > Let me be more clear. I am porting the functionality, not the form of the > code. I want to use pure clojure - because I'd like it available to clojure > and clojurescript. > > Generally: > I can write code that will do what this does - but I can't (so far) do it > succinctly. > - I suppose I am asking if anyone else can - to see how they might approach > it. (the original section in question is about 15 LOC). > > On efficiency, lazyness and clojurian sequences: > At the end the for loop is effectively a reduction of a number of short, > offset arrays/vectors to a single longer array/vector. In a persistent world, > I can't help but feel that this process will generate a lot of unnecessary > garbage - because it is only ever going to be intermediate data. Premature > optimisation maybe - but if feels like an appropriate thing to think about. > at least briefly. > > On transients: > At the moment, I disagree - I think that there are some situations where > strictly contained mutability can make a solution simpler as well as possibly > more efficient. I offer no proof :) > > But, if it is the case that the original is contained, imperative and short - > it might well be preferable just to have this imperative section embedded as > an imperative chunk - but out of harms way - precisely because it is simple - > hence transients - maybe. > > > I'd like to hear other opinions, this is a useful discussion for me. > > Cheers > > Dave -- 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 Note that posts from new members are moderated - please be patient with your first post. 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