dynamic classes and duck typing

Steven Schveighoffer schveiguy at yahoo.com
Tue Dec 1 05:56:48 PST 2009


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)?

2. Can we cover templated operators with opDispatch?  I can envision  
something like this:

opDispatch(string s)(int rhs) if(s == "+") {...}

I'm still hesitant on operators only being definable through templates,  
since it makes for very ugly and complex function signatures, regardless  
of whether they are virtual or not.  I would be all for it if you can make  
shortcuts like:

operator("+")(int rhs)

hm.. that gives me an idea.  new post...

-Steve



More information about the Digitalmars-d mailing list