Short list with things to finish for D2

Don nospam at nospam.com
Fri Nov 20 02:22:57 PST 2009


Walter Bright wrote:
> aarti_pl wrote:
>> I know that quite a few people here doesn't like to allow users to 
>> define their own operators, because it might obfuscate code. But it 
>> doesn't have to be like this. Someone here already mentioned here that 
>> it is not real problem for programs in C++. Good libraries don't abuse 
>> this functionality.
> 
> The problem with user defined operators is:
> 
>  1. User defined tokens - mixes up lexing with semantic analysis
> 
>  2. User defined syntax - mixes up parsing with semantic analysis
> 
> and then we're in C++ land :-(
> 
> Unless such have a unique grammar that can be lexed and parsed:
> 
>     a :string: b
> 
> where string is the user defined name, so you can do things like:
> 
>     a :^^: b
> 
> and define your own pow operator. The problem with this approach is the 
> sheer ugliness of it.

There's not many sensible operators anyway. opPow is the only missing 
one that's present in many other general-purpose languages. The only 
other ones I think are remotely interesting are dot and cross product.

Anything beyond that, you generally want a full DSL, probably with 
different precendence and associativity rules. Eg, for regexp, you'd 
want postfix * and + operators. There are examples of clever things done 
in C++  with operator overloading, but I think that's just because it's 
the only way to do DSLs in C++.

I don't think the applications are there.



More information about the Digitalmars-d mailing list