Re: Problem adjusting the implementation of 'partition'

2010-11-23 Thread Benny Tsai
Glad I was able to help :) On Nov 23, 12:53 am, Stefan Rohlfing wrote: > Fantastic! Thanks again! > > On Nov 23, 3:50 pm, Benny Tsai wrote: > > > > > > > > > Indeed there is :) > > >http://clojuredocs.org/clojure_core/clojure.core/cycle > > > On Nov 23, 12:37 am, Stefan Rohlfing > > wrote: > >

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Stefan Rohlfing
Fantastic! Thanks again! On Nov 23, 3:50 pm, Benny Tsai wrote: > Indeed there is :) > > http://clojuredocs.org/clojure_core/clojure.core/cycle > > On Nov 23, 12:37 am, Stefan Rohlfing > wrote: > > > > > > > > > Hi Benny, > > > Your solution is much more elegant and flexible as my hacking of the

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Benny Tsai
Indeed there is :) http://clojuredocs.org/clojure_core/clojure.core/cycle On Nov 23, 12:37 am, Stefan Rohlfing wrote: > Hi Benny, > > Your solution is much more elegant and flexible as my hacking of the > core function! > > How would you implement 'pad-padding' (I like this name) if every item >

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Stefan Rohlfing
Hi Benny, This implementation looks great! If I could only find out what went wrong with my (not so elegant) solution... Stefan On Nov 23, 3:30 pm, Benny Tsai wrote: > Or, to put it all together into a modified partition: > > (defn my-partition >   ([n coll] >      (partition n n coll)) >   ([

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Stefan Rohlfing
Hi Benny, Your solution is much more elegant and flexible as my hacking of the core function! How would you implement 'pad-padding' (I like this name) if every item of the padding should be repeated in order, not only the last one? (defn pad-padding [padding] (concat padding (repeat padding)))

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Benny Tsai
Or, to put it all together into a modified partition: (defn my-partition ([n coll] (partition n n coll)) ([n step coll] (partition n step coll)) ([n step pad coll] (let [expanded-pad (concat pad (repeat (last pad)))] (partition n step expanded-pad coll user=> (my-p

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Benny Tsai
Sorry, pad-padding is a terrible name choice on my part :) Maybe something like "repeat-last" would be at least a little bit better. On Nov 23, 12:17 am, Benny Tsai wrote: > Since (repeat) returns a lazy sequence, and partition will only take > as many as is needed, I think you don't even have t

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Benny Tsai
Since (repeat) returns a lazy sequence, and partition will only take as many as is needed, I think you don't even have to specify how many times to repeat: user=> (partition 3 3 (repeat "a") [1 2 3 4 5 6 7]) ((1 2 3) (4 5 6) (7 "a" "a")) And if the desired behavior is to repeat the last element o

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Stefan Rohlfing
Hi Meikel, What I want to accomplish is to have the function 'fill the gap' if not enough padding is supplied. With the standard 'partition' function this does not work, as it only adds as much padding as provided: (partition 3 3 ["a"] [1 2 3 4 5 6 7 8 9 10]) ;; ((1 2 3) (4 5 6) (7 8 9) (10 "a")

Re: Problem adjusting the implementation of 'partition'

2010-11-22 Thread Meikel Brandmeyer
Hi, while not having looked at your code, partition does what you want: user=> (partition 3 3 (repeat 3 "a") [1 2 3 4 5 6 7]) ((1 2 3) (4 5 6) (7 "a" "a")) user=> (partition 3 3 (repeat 3 "a") [1 2 3 4 5 6 7 8]) ((1 2 3) (4 5 6) (7 8 "a")) user=> (partition 3 3 (repeat 3 "a") [1 2 3 4 5 6 7 8 9])

Problem adjusting the implementation of 'partition'

2010-11-22 Thread Stefan Rohlfing
Dear Clojure Group, I am trying to adjust the implementation of the 'partition' function so that the last element of a provided padding such as ["a" "b"] will be repeated if necessary to ensure the length of the last list returned by 'padding' is the same as the other lists. This is the original