Short list with things to finish for D2

aarti_pl aarti at interia.pl
Thu Nov 19 15:07:15 PST 2009


Walter Bright pisze:
> 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 :-(
> 

"retard" probably already answered it.

I was thinking about something like below:


symbols = '!@#$%^&*'	//quick & dirty definition
identifier = '[a-zA-Z][a-zA-Z0-9]*' //quick & dirty definition

Prefix operator:
1. [symbols][whitespace][identifier]
2. [identifier]whitespace[identifier]

Postfix operator:
1. [identifier][whitespace][symbols]
2. [identifier]whitespace[identifier]

Infix operator:
1. [identifier][whitespace][symbols][whitespace][identifier]
2. [identifier]whitespace[identifier]whitespace[identifier]

With precedence defined as above: first prefix, then postfix, then infix.

Should work...

> 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.

This might be also acceptable. Especially with `` syntax. (I know it's 
currently for strings).

----

I believe that user defined operators will have positive impact on D 
language. Please notice that always when you have more power, then you 
can make more bad things. But you can also do more good things! And 
doing good things or doing bad things is not something what should 
programming language care of. Programming language is IMHO just for 
giving good tools. User should decide how to use them.

I think there aren't enough good reasons to introduce new syntax if it 
will not allow user defined operators. It will be rather source of 
confusion if we only allow to pass few symbols as strings: strings are 
about 'freedom' of content. So using it for passing just a few symbols 
is for me "corner case".

BR
Marcin Kuszczak
(aarti_pl)



More information about the Digitalmars-d mailing list