Re: positions

2009-11-22 Thread nchubrich
Thanks Emeka, I took a look at it. I still say it would be nice to organize the sequence functions (somehow). -- 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 membe

Re: positions

2009-11-22 Thread John Harrop
On Sun, Nov 22, 2009 at 7:54 AM, Emeka wrote: > John, > > You should have added that you code came from Programming Clojure. > It didn't. If it's the same as, or closely similar to, code from there, it's entirely coincidental. In Clojure there's usually several ways to do something, but often o

Re: positions

2009-11-22 Thread Emeka
John, You should have added that you code came from Programming Clojure. Regards, Emeka On Thu, Nov 19, 2009 at 8:05 PM, John Harrop wrote: > On Thu, Nov 19, 2009 at 1:23 PM, Sean Devlin wrote: > >> Try clojure.contrib.seq-utils :) >> >> As a learning exercise, I'd recommend re-writing it to

Re: positions

2009-11-22 Thread Emeka
Nick, Remember to re-visit indexed and index-filter functions of programming Clojure. Regard, Emeka On Thu, Nov 19, 2009 at 7:13 PM, nchubrich wrote: > Thanks Sean, I'll do the exercise. I don't know how I missed it in > seq-utils. > After months of programming Clojure, I realize how much I

Re: positions

2009-11-20 Thread nchubrich
If you think about it, the tower of sequence types is like this: seq | gathered seq /\ multiset permutation \ / set The way to do the various options I pointed out is to mix types: the k

Re: positions

2009-11-20 Thread nchubrich
My 'requirements' were not so much for any particular need, but to try to think up a logical and complete API for dealing with multisets. I agree that there should be an actual collection type for multisets (implemented as an underlying map of values to frequencies I presume); but you might as wel

Re: positions

2009-11-19 Thread Alex Burka
Yesterday I need a similar function (interleave, but don't stop when the shortest seq ends), so I wrote it. I subsequently refactored the program and didn't need it anymore, but here it is anyway. It could probably be written more succinctly, but I followed the implementation of core/interleave

Re: positions

2009-11-19 Thread John Harrop
On Thu, Nov 19, 2009 at 7:51 PM, Alex Osborne wrote: > John Harrop wrote: > > This is just (sort (concat [1 2 3 4 5 6 7] [3 2 7])) though. > > > > > > I think he also wants the original order of the first input coll to be > > preserved, though. Sort wouldn't do that. > > Hmmm.. that's a prett

Re: positions

2009-11-19 Thread Alex Osborne
John Harrop wrote: > This is just (sort (concat [1 2 3 4 5 6 7] [3 2 7])) though. > > > I think he also wants the original order of the first input coll to be > preserved, though. Sort wouldn't do that. Hmmm.. that's a pretty weird set of requirements. Usually a multiset/bag is unordered

Re: positions

2009-11-19 Thread John Harrop
On Thu, Nov 19, 2009 at 7:15 PM, Alex Osborne wrote: > John Harrop wrote: > > On Thu, Nov 19, 2009 at 7:00 PM, Sean Devlin > > wrote: > > > > That's why there are two separate functions do do what you suggest > > > > user=>(interleave [1 2 3 4] [1 2 3 4])

Re: positions

2009-11-19 Thread Alex Osborne
John Harrop wrote: > On Thu, Nov 19, 2009 at 7:00 PM, Sean Devlin > wrote: > > That's why there are two separate functions do do what you suggest > > user=>(interleave [1 2 3 4] [1 2 3 4]) > (1 1 2 2 3 3 4 4) > > user=> (concat [1 2 3 4] [1 2 3 4

Re: positions

2009-11-19 Thread John Harrop
On Thu, Nov 19, 2009 at 7:00 PM, Sean Devlin wrote: > That's why there are two separate functions do do what you suggest > > user=>(interleave [1 2 3 4] [1 2 3 4]) > (1 1 2 2 3 3 4 4) > > user=> (concat [1 2 3 4] [1 2 3 4]) > (1 2 3 4 1 2 3 4) > Poor choice of example. I think he meant even if he

Re: positions

2009-11-19 Thread Sean Devlin
That's why there are two separate functions do do what you suggest user=>(interleave [1 2 3 4] [1 2 3 4]) (1 1 2 2 3 3 4 4) user=> (concat [1 2 3 4] [1 2 3 4]) (1 2 3 4 1 2 3 4) There's also the doall function to override lazyness. On Nov 19, 6:38 pm, nchubrich wrote: > Yeah, remove will work

Re: positions

2009-11-19 Thread nchubrich
Yeah, remove will work for one kind of 'multiset' operator I am thinking of. The others might as well preserve as much order as possible. For instance, (add [1 2 3 4] [1 2 3 4]) could have two interpretations; you just append, or you add like elements to positions of like elements, so you get [1

Re: positions

2009-11-19 Thread Alex Osborne
ajuc wrote: > On 20 Lis, 01:49, nchubrich wrote: >> While we're on the topic, where is something like (subtract [1 2 3 3 4 >> 4 5 6] evens) -> (1 3 3 5)? Doesn't seem to be in seq-utils or API. >> Seems like there should be a parallel "multiset" library for colls, to >> clojure.set. (I guess the

Re: positions

2009-11-19 Thread ajuc
On 20 Lis, 01:49, nchubrich wrote: > While we're on the topic, where is something like (subtract [1 2 3 3 4 > 4 5 6] evens) -> (1 3 3 5)? Doesn't seem to be in seq-utils or API. > Seems like there should be a parallel "multiset" library for colls, to > clojure.set. (I guess there could be two ve

Re: positions

2009-11-19 Thread nchubrich
While we're on the topic, where is something like (subtract [1 2 3 3 4 4 5 6] evens) -> (1 3 3 5)? Doesn't seem to be in seq-utils or API. Seems like there should be a parallel "multiset" library for colls, to clojure.set. (I guess there could be two versions of subtract, one that removes \all, a

Re: positions

2009-11-19 Thread John Harrop
On Thu, Nov 19, 2009 at 1:23 PM, Sean Devlin wrote: > Try clojure.contrib.seq-utils :) > > As a learning exercise, I'd recommend re-writing it to be lazy. Your > version is eager because it uses loop. In order to make it lazy, > you'd want to construct a lazy-seq. See the macro w/ the same name

Re: positions

2009-11-19 Thread nchubrich
Thanks Sean, I'll do the exercise. I don't know how I missed it in seq-utils. After months of programming Clojure, I realize how much I still have to learn. (Knowledge is power; knowledge of lack of knowledge is power to power.) Nick. -- You received this message because you are subscribe

Re: positions

2009-11-19 Thread Sean Devlin
Try clojure.contrib.seq-utils :) As a learning exercise, I'd recommend re-writing it to be lazy. Your version is eager because it uses loop. In order to make it lazy, you'd want to construct a lazy-seq. See the macro w/ the same name. Another choice is to use built-in functions, like this: (d