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 abstraction" is less of a abstraction if I still need to keep a watchful eye what is the underlying concrete type with functions like "into". The unfortunate thing is this has nothing to do with whether the language is functional or not. Adding a "subseqx" like what you did into the language, or let "into" always return results in the same order won't change the fact that Clojure is functional. What we see seems just like unnecessary nuance. On the other hand, those nuances are not beyond fix. Maybe next version Clojure will have a function similar to subseqx. Although changing "into" will break compatibility, we can add another function. But the bigger the code base out in the wild, the more difficult it will be. 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 walk much more than fly. And there is no REAL reason that you need to walk slower when trying to fly higher. All those nuances are self imposed without any true substantial reason. Again, just my views and feelings. No scientific proofs of any. Still, I am glad that at least there is one more Lisp to play with (and put my hope on). On Wednesday, June 27, 2012 5:51:57 PM UTC-4, Larry Travis wrote: > > 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 (drop start (take end s))] > (cond > (instance? clojure.lang.IPersistentList s) > (apply list slice) > > (instance? clojure.lang.PersistentTreeSet s) > (apply sorted-set slice) > > (instance? clojure.lang.PersistentTreeMap s) > (apply sorted-map (concat slice)) > > :else > slice)))) > > And you can add conditions for other kinds of ordered collections if and > when a need arises. This is neither simple nor pretty, but an advantage of > no-side-effects functional programming is that when you call a pure > function you don't need to worry about how simple or pretty might be its > internal details. > --Larry > > On 6/27/12 3:24 PM, Warren Lynn wrote: > > 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 type out again while preserving order. >> >> How about: >> >> (defn sub-seq [start end coll] >> (take (- end start) (drop start coll))) >> >> U >> > -- > 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 > > > > -- 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