Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 15, 12:41 pm, Christian Schuhegger 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 present in the map  (e.g. if

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 th

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 15, 11:51 am, Mark Engelberg wrote: > On Tue, Jun 14, 2011 at 7:41 PM, Matthew Phillips 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 i

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Mark Engelberg
On Tue, Jun 14, 2011 at 7:41 PM, Matthew Phillips 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 having lots of

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 14, 4:40 pm, Alex Osborne wrote: > Matthew Phillips 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)

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Matthew Phillips
On Jun 14, 12:30 pm, Mark Engelberg wrote: > On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips wrote: > > List items = initialItems (); > > > for (Op op : operations) > > { > >  if (op.requiresDelete ()) > >    items.remove (op.indexToDelete ()); > > >  if (op.requiresAdd ()) > >    items.add (op

Re: Wisdom sought for functional iterative processing

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

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Alex Osborne
Matthew Phillips 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 cascade

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Stuart Campbell
On 14 June 2011 12:37, Matthew Phillips 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) > > i.e. I'

Re: Wisdom sought for functional iterative processing

2011-06-13 Thread Mark Engelberg
On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips wrote: > List 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 transform th

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: List 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 clo