[ ArgumentList ] vs. @( ArgumentList )

deadalnix deadalnix at gmail.com
Fri Nov 9 06:25:43 PST 2012


Le 08/11/2012 02:48, Walter Bright a écrit :
> On 11/7/2012 4:03 PM, Andrei Alexandrescu wrote:
>> On 11/7/12 10:24 PM, Walter Bright wrote:
>>> On 11/7/2012 11:40 AM, Jonas Drewsen wrote:
>>>> I we were to allow for @foobar style UDA then "safe" would have to be
>>>> a reserved
>>>> keyword somehow. Otherwise I do not know what this would mean:
>>>>
>>>> struct safe { }
>>>> @safe void foobar() { }
>>>
>>> Yes, I agree this is a significant problem.
>>>
>>
>> I think it's solvable. The basic approach would be to plop types "safe",
>> "nothrow" etc. in object.di and then let them just behave like all
>> other arguments.
>
> Consider that if we do that, then someone will need to disambiguate with:
>
> @object.safe
>
> which is ambiguous:
>
> @a.b .c x = 3;
>
> or is it:
>
> @a .b.c x = 3;
>
> ?
>
> Another problem is it pushes off recognition of @safe from the parser to
> the semantic analyzer. This has unknown forward reference complications.

How didn't see that coming. I never was a big fan of .identifier syntax 
for module level stuff.

However, you example isn't quite correct. Attributes are for symbols, 
and your example don't create any new symbol.

Let's consider @a.b .c d = 3;

Now, we have several option to disambiguate that. The first, obvious one 
is to use () : @(a.b) .c d = 3; .

When not using (), the compiler understand this as @(a.b.c) d = 3; which 
is an error.

Another option is to use auto : @a.b auto d = .c(3);

Anyway, I don't expect this to break too much code, if any.


More information about the Digitalmars-d mailing list