Re: General subsequence function

2012-06-29 Thread Andy Fingerhut
Getting code into a Clojure contrib library, or into clojure.core, require convincing others that maintain the appropriate namespace. One way to be persuasive is to make a library of useful code on github and clojars.org, advertise it here, and have folks try it out. If they do, and like what

Re: General subsequence function

2012-06-29 Thread John Holland
But elisp vectors can't be accessed like lists, try running "car" on one. On Thu, Jun 28, 2012 at 1:55 PM, Warren Lynn wrote: > Here is "another language" elisp: > > Anybody who use Emacs can do this: > > (subseq (make-vector 5 10) 2 4) => [10 10] > (subseq '(10 10 10 10 10) 2 4) => (10 10) > >

Re: General subsequence function

2012-06-29 Thread mnicky
> If you want to see something like this in clojure.core, you can create a > ticket on JIRA, preferably with a patch adding the new function as well as > some unit tests, and then some day it may be screened and later included in > Clojure's core code. For some of the reasons you have read in

Re: General subsequence function

2012-06-28 Thread Warren Lynn
Is there any reason why "last" needs to be slow on vectors? Can it just do the right thing and be fast on it? On Thursday, June 28, 2012 4:28:30 PM UTC-4, Meikel Brandmeyer (kotarak) wrote: > > Hi, > > Am 28.06.2012 um 20:52 schrieb Tassilo Horn: > > > And yes, there are some counter examples

Re: General subsequence function

2012-06-28 Thread David Nolen
It's a sequence operation and plenty useful. On Thu, Jun 28, 2012 at 4:56 PM, Tassilo Horn wrote: > Meikel Brandmeyer writes: > > Hi Meikel, > > >> And yes, there are some counter examples like `count` and `last`... > > > > last is not a counterexample. last is a sequence function, which acts >

Re: General subsequence function

2012-06-28 Thread David Nolen
On Thu, Jun 28, 2012 at 4:28 PM, Meikel Brandmeyer wrote: > Hi, > > Am 28.06.2012 um 20:52 schrieb Tassilo Horn: > > > And yes, there are some counter examples like `count` and `last`... > > last is not a counterexample. last is a sequence function, which acts on > seqs. It just calls seq on its

Re: General subsequence function

2012-06-28 Thread Tassilo Horn
Meikel Brandmeyer writes: Hi Meikel, >> And yes, there are some counter examples like `count` and `last`... > > last is not a counterexample. last is a sequence function, which acts > on seqs. It just calls seq on its argument so you may pass in a vector > (or anything seqable). The vector equiv

Re: General subsequence function

2012-06-28 Thread Meikel Brandmeyer
Hi, Am 28.06.2012 um 20:52 schrieb Tassilo Horn: > And yes, there are some counter examples like `count` and `last`... last is not a counterexample. last is a sequence function, which acts on seqs. It just calls seq on its argument so you may pass in a vector (or anything seqable). The vector

Re: General subsequence function

2012-06-28 Thread Warren Lynn
Andy: Thanks for laying out the options to move it forward. I think those functions belong to clojure.core, but I will see how persuasive I am, or how receptive the community is. :-) On Thursday, June 28, 2012 2:53:27 PM UTC-4, Andy Fingerhut wrote: > > From quick & easy, to slower & more diffi

Re: General subsequence function

2012-06-28 Thread Warren Lynn
Tassilo: Thanks a lot. Your version may be my private version before it (may) make into the language itself. When I raise an issue like this, a very common answer is "you can do this yourself". Maybe I can, but what is the purpose of a language? It gives you a common framework so nobody needs

Re: General subsequence function

2012-06-28 Thread Andy Fingerhut
>From quick & easy, to slower & more difficult, here are some options: Use the functions you want in your own code, and find happiness in the fact that they are quick & easy to write. Make a library of this and perhaps other related functions on github. Perhaps also release JARs to clojars.org

Re: General subsequence function

2012-06-28 Thread Tassilo Horn
Warren Lynn writes: Hi Warren, > 1. add a new function "append", which splices multiple ordered collection > together and always returns the result in the concrete type of its first > argument. So: > (append [1] '(2 3)) => [1 2 3] > (append '(1) [2 3])) => (1 2 3) > > It is different from "con

Re: General subsequence function

2012-06-28 Thread Warren Lynn
Here is "another language" elisp: Anybody who use Emacs can do this: (subseq (make-vector 5 10) 2 4) => [10 10] (subseq '(10 10 10 10 10) 2 4) => (10 10) As simple as that. Is that even worth the debate? :-) On Thursday, June 28, 2012 11:30:25 AM UTC-4, Warren Lynn wrote: > > Some of my thought

Re: General subsequence function

2012-06-28 Thread Warren Lynn
Some of my thoughts: 1. The argument that other languages do not have a similar thing is not valid. If that is valid, we don't need Clojure in the first place. 2. The argument that other people did not raise the issue before and not enough people support it so this is a non-issue is also not va

Re: General subsequence function

2012-06-28 Thread Timothy Baldridge
> I like Lisp in general but it frustrated me (before also with Common Lisp) > that it seems Lispers often claim the language can help you fly higher while > in reality it actually makes your walking more difficult. Even it can help > you fly higher, that will still turn off many people because we

Re: General subsequence function

2012-06-27 Thread Devin Walters
Warren, I would ask myself (quite seriously, no snark intended) whether or not a fixation on ordered collections or sub-collections woven throughout a program (as you seem to be describing) is a language feature, or the responsibility of the programmer. Larry, Ulises, and Michael have all offe

Re: General subsequence function

2012-06-27 Thread Warren Lynn
It seems the name "append" has not yet been taken. How about we do this with Clojure: 1. add a new function "append", which splices multiple ordered collection together and always returns the result in the concrete type of its first argument. So: (append [1] '(2 3)) => [1 2 3] (append '(1) [2

Re: General subsequence function

2012-06-27 Thread Warren Lynn
Again, everything I wrote here is "in my view". (think of :injection ("In my view")). Thanks. I am certainly sure it is doable with Clojure, as you just did it. The unpleasant thing is Clojure does not provide a built-in function for that (which might be much more efficient), and the "sequence

Re: General subsequence function

2012-06-27 Thread Larry Travis
Something like this will give you what you want: (defn subseqx [s start end] (cond (instance? clojure.lang.IPersistentVector s) (subvec s start end) (instance? java.lang.String s) (subs s start end) :else (let [slice (dr

Re: General subsequence function

2012-06-27 Thread Warren Lynn
Thanks, but this does not keep the concrete type. On Wednesday, June 27, 2012 3:42:25 PM UTC-4, Ulises wrote: > > > I'd forgotten that 'into adds things in the "default" place for whatever > type you're using, hence the reversal on lists. I'm not sure if there's a > simple way to get the same ty

Re: General subsequence function

2012-06-27 Thread Warren Lynn
> > Ordering problem aside, I'd argue this is not an unreasonable amount of > code for what seems to me a pretty rare set of requirements. Most people > who want a same-type segment from the middle of an ordered collection > (which is already uncommon in my experience) are probably either usin

Re: General subsequence function

2012-06-27 Thread Ulises
> I'd forgotten that 'into adds things in the "default" place for whatever type > you're using, hence the reversal on lists. I'm not sure if there's a simple > way to get the same type out again while preserving order. How about: (defn sub-seq [start end coll] (take (- end start) (drop start

Re: General subsequence function

2012-06-27 Thread Michael Gardner
On Jun 27, 2012, at 1:02 PM, Warren Lynn wrote: > Do you mean something like this: > > (defn subseqx [s start end] (into (empty s) (drop-last (- (count s) end) > (drop start s > > Two things I don't like it: > > 1. It does not work > (subseqx [1 2 3] 1 3) => [2 3] > (subseqx '(1 2 3) 1 3)

Re: General subsequence function

2012-06-27 Thread Warren Lynn
You can combine 'drop and 'drop-last to get a seq version of subvec (but > lazy and O(n)). As for the issue of concrete types: in general, clojure's > sequence functions return seqs, not instances of whatever concrete type you > gave them. If you need a specific type, you normally just pour t

Re: General subsequence function

2012-06-27 Thread Michael Gardner
On Jun 27, 2012, at 9:39 AM, Warren Lynn wrote: > I am surprised that there seems to be no general sub-sequence function that > will return a segment of a sequence without changing the underlying concrete > type. I found "subvec", but it works only on vectors. "subseq" is not what I > thought i