dynamic classes and duck typing

bearophile bearophileHUGS at lycos.com
Sat Nov 28 07:00:40 PST 2009


Don:
> You mean, if it's known at run-time only?

Yes, sorry.

> What Walter has written is definitely the correct one.

I am not saying that what Walter has written is wrong or useless :-)
I am saying that it's not dynamic. This means that:
1) The name of that operator "opDynamic" is wrong, it needs a name that doesn't contain "dynamic" inside. "opDispatch" suggested by Michel Fortin seems OK. It can have that signature shown by Walter:
T opDispatch(s : string)(args...);
2) A second operator like:
variant opDynamic(string name, variant[]);
can be added for the truly dynamic case, as in C#/Java and in dynamic languages. As I've said such operator will enjoy fast associative arrays when the number of keys is small (Python dicts have an optimization for such very common case).


>you can just write a single function:<

That's not an example of the most readable code, but it's cute :-)

Bye and thank you,
bearophile



More information about the Digitalmars-d mailing list