dynamic classes and duck typing
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Nov 28 14:12:28 PST 2009
KennyTM~ wrote:
> On Nov 28, 09 22:00, bearophile wrote:
>> Walter Bright:
>>> and then s.foo(3), if foo is not a compile time member of s, is
>>> rewritten as:
>>> s.opDynamic!("foo")(3);
>>
>> I don't understand, isn't this the right translation?
>> s.opDynamic("foo", 3);
>> If the "foo" name is known at compile time only (as in all C# examples
>> and in Python) you can't use a template argument.
>> (And then it becomes useful to have associative arrays that are fast
>> when the number of keys is small,< 10).
>>
>> Bye,
>> bearophile
>
> Probably because you can write
>
> Variant myOpReallyDynamic(string name, Variant[] s...) {
> ...
> }
>
> Variant opDynamic(string name)(Variant[] s...) {
> return myOpReallyDynamic(name, s);
> }
>
> but not the other way round.
That is correct. Thanks for pointing that out. The operator is dynamic
because it may perform a dynamic lookup under a static syntax. Straight
dynamic invocation with a regular function has and needs no sugar.
Andrei
More information about the Digitalmars-d
mailing list