-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Efficient implementation of coalesce() and entries() #14
Comments
I'm having second thoughts about this optimization. If an ArraySequence is passed that is being used elsewhere, it gets modified. The optimization should only work for an ArraySequence that is created by the compiler to wrap the sequenced args. Which brings the question, why aren't Ceylon sequenced args compiled as Java sequenced args? Sent via Hubroid |
Perhaps we should change the return types of these functions to plain |
Where is it possible to change ArraySequence? I thought it was always immutable? |
it's supposed to be immutable, but the Java impl has a |
If we change its return type to Iterable we could just leave the second option I had that returns an AbstractIterable that skips over nulls - although that could be a problem if the argument is a mutable collection... |
Right.
That's a bug I suppose. At best it should be |
I don't think it's visible to Ceylon, but it would be to Java. So we could override it with a version that makes a copy. But I don't think we should take into account every trick people could use to make things fail. Once you pass things to Java all bets are off. Sent via Hubroid |
So, after some reflection on this issue, I'm now inclined to think that we should simply remove these functions and replace them by members of
The advantages of this approach:
So I think this is the right approach. |
If it's not marked |
Oh, it's not because
I don't agree with this. Our immutable classes should protect their internal state from mutation. |
FTR the class used to wrap sequenced args is ArraySequence, not ArrayList. Again, why aren't Ceylon sequenced args compiled into Java sequenced args? Sorry to ask this so late in the game, but I'm new to ceylonc, so surely there must be very valid reasons (maybe default args, I don't know), I'd just like to know. |
A Java sequenced arg is a Java array. Ours is a Ceylon Iterable. If we compiled to a java varag method, we would lose the laziness we have today. Sent from my iPhone On Jul 3, 2012, at 5:35 PM, Enrique Zamudioreply@reply.github.com wrote:
|
What would that give us? The idea was that the actual way it's implemented was irrelevant, it's "a Sequence".
I agree, but there are cases where I hardly think that's doable. We should prevent it by means of publicly available (= non-private) methods but the moment you start using tricks you just can't do much, at least not without great cost. How would we ever detect somebody changing the internal array of that class if it was accessed using introspection? Like I said, the simplest thing would be just to just override the |
PS: |
Yes, I think we should remove it. Sent from my iPhone On Jul 3, 2012, at 6:47 PM, Tako Schotanusreply@reply.github.com wrote:
|
And what do we do about |
On Jul 3, 2012, at 6:27 PM, Tako Schotanusreply@reply.github.com wrote:
Well for a start it means you can pass around a ref to ArraySequence to use it to create sequences. And ArrySequence already does (or should) hide its internal implementation. ArraySequence is no different to Singleton or Range in these respects. We should not encourage people to think {} is a somehow magical thing defined outside the type system. It's just a cute abbreviation. |
Right, that's what I just said, I think... Unless you think it's independently useful as a convenience thing to write stuff like: value name=" ".join(coalesce(first, middle, initial)); I can see that being very occasionally useful, I suppose... Sent from my iPhone On Jul 3, 2012, at 7:01 PM, Enrique Zamudioreply@reply.github.com wrote:
|
Actually I suppose it does make sense in general to have a toplevel fn with a sequenced param that has the same semantics as a method if Iterable. It saves a noisy call to elements(). Sent from my iPhone On Jul 3, 2012, at 7:07 PM, Gavin King gavin.king@gmail.com wrote:
|
ok so we'll leave |
I would redefine
I suppose that's the most generally-useful definition. |
OK if we change the signature to that then we can leave the Iterable implementation I already did for |
@chochos Thanks man, looks great. |
These functions should simply wrap their argument sequence. There's no need to allocate a whole new array.
The text was updated successfully, but these errors were encountered: