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) => (3 2)
> because "into" will reverse the order on sequence.

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.

> 2. kind of ugly for such a simple thing, and may not be efficient either.
> 
> Any SIMPLE way to do it? I need concrete type unchanged. I don't think that 
> is a rare need/use case.

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 using vectors already or at 
least know what type they're operating on.

> PS: when I say "sequences", how should I distinguish between general sequence 
> and concrete sequences? Any conventions for the wording?

"Ordered collection" is the preferred term for the general concept, I think.

-- 
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 members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to