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 On Wednesday, 6 June 2012 21:43:10 UTC+10, Stephen Compall wrote: > > > > The question is: what is the best way to write such a function in > clojure. > > You will never get the clarity you're looking for with a direct port; you > must find and use appropriate Clojurian abstractions. I suggest starting by > thinking about ways to eliminate loops with the numerous lazy sequence > functions, which are less numerous and harder to use in Python. > > Most loop/recurs become far simpler once they are not there anymore. > > > - is this a candidate for transients? probably > > Transients aid in performance; they cannot help you achieve greater > simplicity, because they are strictly less powerful than their persistent > counterparts. > > I suggest trying to find the simplest implementation, and worrying about > efficiency once you have that. > > -- > Stephen Compall > Greetings from sunny Appleton! > -- 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