Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Stuart Campbell
On 14 June 2011 12:37, Matthew Phillips mattp...@gmail.com wrote: The only way I can think of to write it in Clojure is: (reduce (fn [items op] (let [items1 (if (:delete op) (drop-index (:delete op) items) items)] (if (:insert op) (cons (:insert op) items1) items1))) items ops)

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Alex Osborne
Matthew Phillips mattp...@gmail.com writes: The only way I can think of to write it in Clojure is: (reduce (fn [items op] (let [items1 (if (:delete op) (drop-index (:delete op) items) items)] (if (:insert op) (cons (:insert op) items1) items1))) items ops) i.e. I'm using a

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 14, 12:05 pm, gaz jones gareth.e.jo...@gmail.com wrote: if i was writing the java i would probably do a tell dont ask refactoring so that the operations had an applyTo method: ListItem items = initialItems (); for (Op op : operations) {   op.applyTo(items); } not sure what your

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 14, 12:30 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips mattp...@gmail.com wrote: ListItem items = initialItems (); for (Op op : operations) {  if (op.requiresDelete ())    items.remove (op.indexToDelete ());  if

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 14, 4:40 pm, Alex Osborne a...@meshy.org wrote: Matthew Phillips mattp...@gmail.com writes: The only way I can think of to write it in Clojure is: (reduce   (fn [items op]     (let [items1 (if (:delete op) (drop-index (:delete op) items) items)]       (if (:insert op) (cons

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Mark Engelberg
On Tue, Jun 14, 2011 at 7:41 PM, Matthew Phillips mattp...@gmail.com wrote: Yes. I agree that can work, and that's what I've done in some other situations, but it has the downside of lots of recur points sprinkled around the loop body, which I think makes it almost as hard to reason about as

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 15, 11:51 am, Mark Engelberg mark.engelb...@gmail.com wrote: On Tue, Jun 14, 2011 at 7:41 PM, Matthew Phillips mattp...@gmail.com wrote: Yes. I agree that can work, and that's what I've done in some other situations, but it has the downside of lots of recur points sprinkled around

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Christian Schuhegger
Ah, sorry, perhaps I misunderstand you, but if you use multimethods (defmulti) in Clojure you do not need to attach methods to anything. The defmulti will allow you dispatch-on-type based on the key which is present in the map (e.g. if :delete is present or if :insert is present). The nice thing

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 15, 12:41 pm, Christian Schuhegger christian.schuheg...@gmail.com wrote: Ah, sorry, perhaps I misunderstand you, but if you use multimethods (defmulti) in Clojure you do not need to attach methods to anything. The defmulti will allow you dispatch-on-type based on the key which is

Re: Wisdom sought for functional iterative processing

2011-06-13 Thread gaz jones
if i was writing the java i would probably do a tell dont ask refactoring so that the operations had an applyTo method: ListItem items = initialItems (); for (Op op : operations) { op.applyTo(items); } not sure what your op data structure is, but i would image you could translate that to the

Re: Wisdom sought for functional iterative processing

2011-06-13 Thread Mark Engelberg
On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips mattp...@gmail.com wrote: ListItem items = initialItems (); for (Op op : operations) {  if (op.requiresDelete ())    items.remove (op.indexToDelete ());  if (op.requiresAdd ())    items.add (op.indexToAdd (), op.newItem ()); } One way to