Indexing access for Lists and Maps considered harmful?
Neal Gafter
neal at gafter.com
Fri Jun 26 08:31:55 PDT 2009
On Fri, Jun 26, 2009 at 2:25 AM, Rémi Forax <forax at univ-mlv.fr> wrote:
> Neal Gafter a écrit :
>
>> On Wed, Jun 24, 2009 at 8:35 AM, Rémi Forax <forax at univ-mlv.fr <mailto:
>> forax at univ-mlv.fr>> wrote:
>>
>> import static put symbol name is the scope, do you propose that
>> the compiler look for
>> any "operator_index_get" in the scope ?
>>
>>
>> As I said, this is not my preferred solution to this problem space, but if
>> you take this approach, then yes.
>>
>
> Sorry, I think i've forget to read a mail, what is your preferred solution
> ?
My preferred solution is based on extension methods. The rewriting would
then be from a[b] to a.operator_index_get(b), or something like that. This
solution requires that the language designers think more than one step
ahead: either add extension methods now or defer support for this feature
until we add support for extension methods. The ARM proposal could
similarly be vastly simplified and at the same time broadened in its ability
to be retrofitted onto existing interfaces by the use of this technique.
Generally speaking, to simplify the specification and simplify backward
compatibility, there are a number of techniques that should be considered
when making further changes to the language, including: (a) specification by
syntactic transformation (a pattern-based approach); (b) extension methods
(to make such specifications more broadly applicable and more flexibly
used); and (c) and context-sensitive keywords. The alternatives (e.g.
retrofitting new interfaces and reusing keywords) generally don't work out
as well.
You can approximate some of the benefits of extension methods by saying that
only methods from the static import scope are considered when binding an
indexing operation.
More information about the coin-dev
mailing list