dynamic classes and duck typing

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 1 10:50:38 PST 2009


Steven Schveighoffer wrote:
> On Sat, 28 Nov 2009 18:36:07 -0500, Walter Bright 
> <newshound1 at digitalmars.com> wrote:
> 
>> And here it is (called opDispatch, Michel Fortin's suggestion):
>>
>> http://www.dsource.org/projects/dmd/changeset?new=trunk%2Fsrc@268&old=trunk%2Fsrc@267 
>>
> 
> I have a few questions:
> 
> 1. How should the compiler restrict opDispatch's string argument?  i.e. 
> if I implement opDispatch, I'm normally expecting the string to be a 
> symbol, but one can directly call opDispatch with any string (I can see 
> clever usages which compile but for instance circumvent const or 
> something), forcing me to always constrain the string argument, i.e. 
> always have isValidSymbol(s) in my constraints.  Should the compiler 
> restrict the string to always being a valid symbol name (or operator, 
> see question 2)?

Where in doubt, acquire more power :o). I'd say no checks; let user code 
do that or deal with those cases.

> 2. Can we cover templated operators with opDispatch?  I can envision 
> something like this:
> 
> opDispatch(string s)(int rhs) if(s == "+") {...}

How do you mean that?


Andrei



More information about the Digitalmars-d mailing list