Hi,
I'm not sure why I said it can be. My original post was going to be about
why there isn't a into! (Thanks Alan for the hint!)

I think the

(if (instance? clojure.lang.IEditableCollection to)

line made me draw false conclusions. It was a bit late, apologies for the
noise and thx!

2012/3/20 Andy Fingerhut <andy.finger...@gmail.com>

> Sorry, I said something incorrect.  into cannot take transients as the
> first arg.  It calls transient internally on the first arg for speed.  This
> does not modify the value you passed in at all -- it creates a new
> transient data structure from what you pass in.
>
> If you try calling transient on a data structure that is already a
> transient, you get an error.  Thus this gives an error:
>
> user=> (def x [1 2 3])
> #'user/x
> user=> (def tx (transient x))
> #'user/tx
> user=> (into tx [5 6 7])
> ClassCastException clojure.lang.PersistentVector$TransientVector cannot be
> cast to clojure.lang.IPersistentCollection  clojure.core/conj (core.clj:83)
> user=> (into x [5 6 7])
> [1 2 3 5 6 7]
>
> Andy
>
>
> On Mar 20, 2012, at 11:30 AM, Andy Fingerhut wrote:
>
> func! (bang) is a naming convention from the programming language Scheme
> that Clojure often uses.  In general it means that the function mutates
> data, i.e. it is not a pure function.  Clojure does not have a ! after all
> of its core functions that do this, but it does after some.  In particular,
> the functions that operate on transients like conj! assoc! persistent! etc.
> mutate their arguments.
>
> Many (maybe most) regular collection functions do not take transients.  As
> I said, I think it is an accident, not by design, that 'into' can take a
> transient as an argument.  Originally it only took persistent collections
> as arguments (perhaps also seqs, but those are immutable, too).
>
> Andy
>
> On Mar 20, 2012, at 11:17 AM, László Török wrote:
>
> Ok,
>
> so the pattern is:
>
> func! (bang) takes a transient and returns a transient
>
> regular collection functions MAY take a transient but ALWAYS return a
> persistent collection, right? :)
>
> thx
> Las
>
> 2012/3/20 Andy Fingerhut <andy.finger...@gmail.com>
>
>> into uses transient and persistent! for speed.  The fact that into can
>> take a transient as input is an accidental consequence of that, I think.
>>  Before into was changed to use transients internally, it could only take
>> persistent data structures as input, and return a persistent data structure.
>>
>> Andy
>>
>> On Mar 20, 2012, at 10:32 AM, László Török wrote:
>>
>> Hi,
>>
>> While implementing qsort with clojure for fun, I thought about using
>> transient vectors to speed up sorting vs the "naive" functional
>> implementation.
>>
>> I need an *into!* version of *into *when joining two sorted subarrays
>> and I was wondering why there isn't one.
>>
>> It seems that (source into) does in fact support a transient collection
>> as the first argument, however it calls persistent! on the result.
>>
>> What was the rationale behind the decision? (Note: I'm not questioning
>> it, just interested.)
>> Is there a particular reason why this feature remains undocumented?
>>
>> --
>> László Török
>>
>>
>> --
>> 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
>
>
>
>
> --
> László Török
>
>
> --
> 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
>



-- 
László Török

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