list literal gotcha and suggestion

Tim Peierls tim at peierls.net
Thu Oct 1 14:35:43 PDT 2009


On Thu, Oct 1, 2009 at 4:46 PM, Mark Thornton <mthornton at optrak.co.uk>wrote:

> Tim Peierls wrote:
>
>> That would make for an awfully exciting type system.
>>
>>    Paris in the
>>    the spring.
>>
>> Quick, sentence or not?
>>
> The The ;-)
>

The point of that "sentence" was that it's not always easy to spot whether a
sequence of values has repeats.



> Allowing an immutable List of constants to also be a Set doesn't seem too
> surprising to me. In fact the original proposal might be more surprising.
> From the original proposal:
>
> final Set<Integer> primes = { 2, 7, 31, 127, 8191, 131071, 524287 };
>
> The order of iteration of 'primes' is undefined. With my suggestion
>
> final Set<Integer> primes = [2, 7, 31, 127, 8191, 131071, 524287];
>
> Here the iteration order is as listed because the value will also implement
> List.
>

And I don't think that's a good idea, even if it were somehow achievable,
because changing 8191 to 31, for example, would change the concrete type of
primes in a way that would be difficult to track down.

But I think Joe's recent message in this thread makes this all moot.

--tim



More information about the coin-dev mailing list