Warren Lynn <wrn.l...@gmail.com> 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 "concat" because it keeps the original concrete
> type.  This will solve the "into" problem. and "into" still has its
> value because it works on non ordered collections too.

Here's a version that seems to work.  Well, it uses reflection and
exploits the fact that all concrete clojure collections have a static
create() method receiving a java.util.List, but since you said you don't
care about performance...

--8<---------------cut here---------------start------------->8---
(defn create-method [c]
  (.getMethod (if (isa? c clojure.lang.ISeq)
                clojure.lang.PersistentList
                c)
              "create"
              (into-array Class [java.util.List])))

(defn append [coll & more]
  (.invoke (create-method (class coll)) nil
           (to-array [(apply concat coll more)])))
--8<---------------cut here---------------end--------------->8---

testi.core> (append [1 2] '(3 4))
[1 2 3 4]
testi.core> (append '(1 2) '(3 4))
(1 2 3 4)
testi.core> (append (seq [1 2]) '(3 4))
(1 2 3 4)
testi.core> (append #{1 2} '(3 4)) ;; ok, that's no sequential...
#{1 2 3 4}

> If a post like this will get no attention from the Clojure gods, where
> should I submit the idea?

You got attention.  No clue if gods or mere mortals responded, but
hey. ;-)

But I think there are no big chances to get a function into Clojure that
performes badly with some collections and is super-fast with others.
The problem is simply, as soon as it's there, it will be used and people
will start complaining about Clojure's slowness without considering that
they use the wrong collection types for the functions they are using.
And yes, there are some counter examples like `count` and `last`...

Bye,
Tassilo

-- 
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