Minor extension to cast syntax

Bruce Adams tortoise_74 at yeah.who.co.uk
Wed Oct 31 13:38:19 PDT 2007


Gregor Richards Wrote:

> Blech. Makes it look like you're calling a function with arguments being 
> a type and then some expression. The current syntax is more similar to 
> calling a templated cast function:
> 
> cast(int)(foo)
> cast!(int)(foo)
> 
> That is, cast is a function with a template parameter of the type you're 
> casting it to. This isn't how it's implemented at all of course, but the 
> syntax is reminiscent of that, and I think that's the better analogy.
> 
>   - Gregor Richards

Surely a cast is really a kind of function opCast() so using function syntax is appropriate. The old syntax sticks out as unusual. There is that idea in language design that if it can be done as a function it should be unless there is a good reason not to. So, having inherited the C like syntax was their ever a good reason for it? does that reason still apply? If you were starting over again (as was supposed to be the case with D) would you still do it this way?

Regards,

Bruce.




More information about the Digitalmars-d mailing list