November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tove | On 11/6/2012 7:14 AM, Tove wrote:
> Hmmm, actually it doesn't work in plain function/block scope either.
Right, I don't see a compelling purpose for that, either.
|
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Tuesday, 6 November 2012 at 15:18:55 UTC, Walter Bright wrote:
> I don't know what use UDAs would be for parameters.
It's pretty much the same as anywhere else: to add useful data for reflection. A few I'd use it for is providing user visible data like label and hint for automatic UI generation, or styling hints again for the auto ui (e.g. "use a multi-line input for this string").
We could also potentially put validation in there, though this may be on the type as well. Or put on info to check for availability of a username.
If you do an automatic UI generator, attributes on the parameters have a lot of uses. Other than that, well, I don't know, but that's probably just because I haven't done it yet!
|
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 2012-11-06 16:15, Walter Bright wrote: >> enum test = "test"; >> >> [test] void foo () {} > > or: > > enum EEE; > [EEE] void foo() { } > First, I didn't know you could have an empty enum. Second, that was my point. I don't like the need for a dummy/empty enum, or the use of a string literal. -- /Jacob Carlborg |
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 11/6/2012 5:04 AM, Jacob Carlborg wrote:
> I agree, I a syntax like this would have been nicer:
>
> @mtype("key" : "value") int a; or @mtype(key : "value") int a;
> @mtype("value") int b;
> @mtype int c;
>
Part of what I was trying to do was minimizing inventing new syntaxes. The
[ ArgumentList ]
invents nothing new but the brackets. Your proposal is both a new syntax, and it can only do key/value pairs - nothing else.
|
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 11/6/2012 7:31 AM, Jacob Carlborg wrote:
> On 2012-11-06 16:15, Walter Bright wrote:
>
>>> enum test = "test";
>>>
>>> [test] void foo () {}
>>
>> or:
>>
>> enum EEE;
>> [EEE] void foo() { }
>>
>
> First, I didn't know you could have an empty enum. Second, that was my point. I
> don't like the need for a dummy/empty enum, or the use of a string literal.
I see your point, but if such was implemented that way, then the UDAs would be extremely limited, and there'd be all sorts of issues with name scoping. Pretty much all that would have to not only be reinvented, but reams of documentation would have to be crafted explaining how it is different from normal names.
|
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 2012-11-06 16:39, Walter Bright wrote: > On 11/6/2012 5:04 AM, Jacob Carlborg wrote: >> I agree, I a syntax like this would have been nicer: >> >> @mtype("key" : "value") int a; or @mtype(key : "value") int a; >> @mtype("value") int b; >> @mtype int c; >> > > Part of what I was trying to do was minimizing inventing new syntaxes. The > > [ ArgumentList ] > > invents nothing new but the brackets. Your proposal is both a new > syntax, and it can only do key/value pairs - nothing else. It depends on how you look at it. * @mtype - is the same syntax as the current syntax for attributes * @mtype("key" : "value") - Uses the above in combination with the syntax for associative array literals How about this then: @mtype("foo", 3, "bar") int a; And have the argument list be optional? I really like to have a short nice looking syntax for the simple use cases, i.e. @mtype int b; -- /Jacob Carlborg |
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 2012-11-06 16:42, Walter Bright wrote: > I see your point, but if such was implemented that way, then the UDAs > would be extremely limited, and there'd be all sorts of issues with name > scoping. Pretty much all that would have to not only be reinvented, but > reams of documentation would have to be crafted explaining how it is > different from normal names. No, I don't think so, see one of my other replies: http://forum.dlang.org/thread/k7afq6$2832$1@digitalmars.com?page=6#post-k7bbsu:2411ls:241:40digitalmars.com -- /Jacob Carlborg |
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Am 06.11.2012 16:55, schrieb Jacob Carlborg:
> On 2012-11-06 16:39, Walter Bright wrote:
>> On 11/6/2012 5:04 AM, Jacob Carlborg wrote:
>>> I agree, I a syntax like this would have been nicer:
>>>
>>> @mtype("key" : "value") int a; or @mtype(key : "value") int a;
>>> @mtype("value") int b;
>>> @mtype int c;
>>>
>>
>> Part of what I was trying to do was minimizing inventing new syntaxes. The
>>
>> [ ArgumentList ]
>>
>> invents nothing new but the brackets. Your proposal is both a new syntax, and it can only do key/value pairs - nothing else.
>
> It depends on how you look at it.
>
> * @mtype - is the same syntax as the current syntax for attributes * @mtype("key" : "value") - Uses the above in combination with the syntax for associative array literals
>
> How about this then:
>
> @mtype("foo", 3, "bar") int a;
>
> And have the argument list be optional? I really like to have a short nice looking syntax for the simple use cases, i.e.
>
> @mtype int b;
>
+1
Also, if mtype is a template, it could naturally be @mtype!(1, 2, 3). Without the '!' it would be a function that is evaluated at CT. And just @mtype would yield an alias of mtype.
|
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Tuesday, 6 November 2012 at 15:19:53 UTC, Walter Bright wrote:
> On 11/6/2012 7:14 AM, Tove wrote:
>> Hmmm, actually it doesn't work in plain function/block scope either.
>
> Right, I don't see a compelling purpose for that, either.
Hmm, what about library based GC annotations?
["GC.NoScan"] int* local_p;
|
November 06, 2012 Re: User Defined Attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to nazriel | On 11/6/2012 5:23 AM, nazriel wrote: > I tried to build DMD git for dpaste, so people can play with UDA but DMD > segfaults when building Phobos The auto tester shows it's working. http://d.puremagic.com/test-results/ |
Copyright © 1999-2021 by the D Language Foundation