Revised RFC on range design for D2

Fawzi Mohamed fmohamed at mac.com
Thu Oct 2 11:27:52 PDT 2008


On 2008-10-02 20:06:32 +0200, Sean Kelly <sean at invisibleduck.org> said:

> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
>> Bruno Medeiros wrote:
>>> 
>>> I don't understand that. You stated "It violates economy of syntax.", so
>>> it violates your Principle 1 of language design. So how can you be
>>> happy with that (apart from the assignment issue)? Does fixing this
>>> problem violate some other principle or concern of yours?
>> I think keeping the language simple is also a good goal.
> 
> I apologize if this has been brought up before, but I'm not sure that 
> simplicity
> is a good thing if it can result in unpredictable behavior.  For example:
> 
>     import std.stdio;
> 
>     class C
>     {
>         this( bool delegate() p )
>         {
>             version( a )
>                 cond = p;
>             version( b )
>                 ptr = p;
>         }
>         version( a )
>         {
>             bool delegate() cond;
>         }
>         version( b )
>         {
>             bool delegate() ptr;
>             bool delegate() cond() { return ptr; }
>         }
>     }
> 
>     void main()
>     {
>         bool test() { writefln( "hi" ); return false; }
>         auto c = new C( &test );
>         if( c.cond() )
>             writefln( "true" );
>     }
> 
> Running version=a prints "hi" while version=b prints "true."  If there were
> some way in the language to say "cond() is a property" then this issue would
> not be silently introduced when changing cond from a variable to a method.
> 
> 
> Sean

Ok this is a good reason to have real properties, a somewhat exotic 
example (with a delegate one can also wrap the delegate in the 
functions hew wants to call , and store the wrapped delegate instead of 
having a property access), but still a good reason.

Fawzi



More information about the Digitalmars-d-announce mailing list