So, User-Defined Attributes

2013-01-04 Thread Philippe Sigaud
OK, now that 2.061 is out, we have User-Defined Attributes (UDAs). Except, there is no doc on them, no explanation, nothing. For people who did not follow the monstrous threads in November, it's as if UDA do not exist. Myself, I upgraded from 2.060 only yesterday, and I never used them. Heck

Re: So, User-Defined Attributes

2013-01-04 Thread Jacob Carlborg
On 2013-01-04 16:45, Philippe Sigaud wrote: OK, now that 2.061 is out, we have User-Defined Attributes (UDAs). Except, there is no doc on them, no explanation, nothing. For people who did not follow the monstrous threads in November, it's as if UDA do not exist. Myself, I upgraded from 2.060 on

Re: So, User-Defined Attributes

2013-01-04 Thread Jacob Carlborg
On 2013-01-04 16:45, Philippe Sigaud wrote: Syntax: @(3) int a; @("string", 7) int b; enum Foo; @Foo int c; struct Bar { int x; } @Bar(3) int d; From that, I get we can put any CT symbol (even a value) as an attribute. I thought we were restricted to user defined types. No, basical

Re: So, User-Defined Attributes

2013-01-04 Thread Max Samukha
On Friday, 4 January 2013 at 15:45:21 UTC, Philippe Sigaud wrote: My own rapid reading tells me we will rapidly need good tuple manipulations templates in Phobos. s/we will rapidly need/we have needed for years

Re: So, User-Defined Attributes

2013-01-04 Thread Philippe Sigaud
So, I'm testing how to transfer UDA from one symbol to another. ``` auto transferAttributes(alias origin, To)(To t) { @(__traits(getAttributes, origin)) To temp = t; pragma(msg, __traits(getAttributes, temp)); return temp; } void main() { @(3, "hello") int i = 10; writeln("["

Re: So, User-Defined Attributes

2013-01-04 Thread Max Samukha
On Friday, 4 January 2013 at 16:04:59 UTC, Philippe Sigaud wrote: So, I'm testing how to transfer UDA from one symbol to another. ``` auto transferAttributes(alias origin, To)(To t) { @(__traits(getAttributes, origin)) To temp = t; pragma(msg, __traits(getAttributes, temp)); return t

Re: So, User-Defined Attributes

2013-01-04 Thread Philippe Sigaud
Max: > transferAttributes attaches the attributes to the local declaration. I'd > be surprised if they were copied to the outer declaration. Or did you mean > attributing the return *type*? The declaration. The type, I guess I'd use an alias. Though, I guess the alias syntax limitations would pr

Re: So, User-Defined Attributes

2013-01-04 Thread Max Samukha
On Friday, 4 January 2013 at 17:11:04 UTC, Philippe Sigaud wrote: The declaration. The type, I guess I'd use an alias. Though, I guess the alias syntax limitations would probably forbid that. So yes, the local declaration is attributed, that works. How do I propagate the attribute to the retu

Re: So, User-Defined Attributes

2013-01-04 Thread Era Scarecrow
On Friday, 4 January 2013 at 15:45:21 UTC, Philippe Sigaud wrote: OK, now that 2.061 is out, we have User-Defined Attributes (UDAs). Except, there is no doc on them, no explanation, nothing. For people who did not follow the monstrous threads in November, it's as if UDA do not exist. ...

Re: So, User-Defined Attributes

2013-01-04 Thread Walter Bright
On 1/4/2013 9:48 AM, Max Samukha wrote: It looks we simply cannot modify existing declarations with UDAs. @(attr) alias foo = bar; // @(attr) is ignored. alias provides a way to provide an alternate name for a symbol. It wouldn't be an alternate name if it had different attributes. Trying to

Re: So, User-Defined Attributes

2013-01-04 Thread Philippe Sigaud
On Fri, Jan 4, 2013 at 9:40 PM, Walter Bright wrote: > On 1/4/2013 9:48 AM, Max Samukha wrote: > >> It looks we simply cannot modify existing declarations with UDAs. >> >> @(attr) alias foo = bar; // @(attr) is ignored. >> > > alias provides a way to provide an alternate name for a symbol. It > wo

Re: So, User-Defined Attributes

2013-01-04 Thread Walter Bright
On 1/4/2013 8:04 AM, Philippe Sigaud wrote: So, I'm testing how to transfer UDA from one symbol to another. Remember, attributes are attached to the declaration. They are not transferred through initializers. This will do the transfer: import std.stdio; void main() { @(3, "hello") int i

Re: So, User-Defined Attributes

2013-01-04 Thread Andrei Alexandrescu
On 1/4/13 3:51 PM, Walter Bright wrote: On 1/4/2013 8:04 AM, Philippe Sigaud wrote: So, I'm testing how to transfer UDA from one symbol to another. Remember, attributes are attached to the declaration. They are not transferred through initializers. This will do the transfer: import std.stdio

Re: So, User-Defined Attributes

2013-01-04 Thread Walter Bright
On 1/4/2013 12:49 PM, Philippe Sigaud wrote: Is that a bug or are module declarations not 'real' declarations? Module declarations aren't declarations.

Re: So, User-Defined Attributes

2013-01-04 Thread Walter Bright
On 1/4/2013 12:59 PM, Andrei Alexandrescu wrote: For transfer templates are better than attributes. Sure, but I wanted to illustrate what was happening. Templates tend to obscure things.

Re: So, User-Defined Attributes

2013-01-04 Thread Max Samukha
On Friday, 4 January 2013 at 20:58:42 UTC, Walter Bright wrote: On 1/4/2013 12:49 PM, Philippe Sigaud wrote: Is that a bug or are module declarations not 'real' declarations? Module declarations aren't declarations. They conceptually are.

Re: So, User-Defined Attributes

2013-01-04 Thread Max Samukha
On Friday, 4 January 2013 at 20:40:39 UTC, Walter Bright wrote: On 1/4/2013 9:48 AM, Max Samukha wrote: It looks we simply cannot modify existing declarations with UDAs. @(attr) alias foo = bar; // @(attr) is ignored. alias provides a way to provide an alternate name for a symbol. I know w

Re: So, User-Defined Attributes

2013-01-04 Thread Philippe Sigaud
On Fri, Jan 4, 2013 at 9:58 PM, Walter Bright wrote: > > Module declarations aren't declarations. > Great quote :)

Re: So, User-Defined Attributes

2013-01-04 Thread Philippe Sigaud
On Fri, Jan 4, 2013 at 9:59 PM, Andrei Alexandrescu < seewebsiteforem...@erdani.org> wrote: > On 1/4/13 3:51 PM, Walter Bright wrote: > >> > So, I'm testing how to transfer UDA from one symbol to another. >>> >> >> >> This will do the transfer: >> >> import std.stdio; >> void main() >> { >> @(3,

Re: So, User-Defined Attributes

2013-01-04 Thread Walter Bright
On 1/4/2013 2:03 PM, Max Samukha wrote: On Friday, 4 January 2013 at 20:40:39 UTC, Walter Bright wrote: Hence, no, you cannot use alias to modify the attributes. You can: public struct S { } private alias S S2; // visibility attribute is changed. I'm not really sure if this is an issue or

Re: So, User-Defined Attributes

2013-01-04 Thread Jacob Carlborg
On 2013-01-04 21:33, Era Scarecrow wrote: This is sorta like tuples; But from the brief summaries I cannot fully understand how or where they would be used. I understand some attributes can be made and added that some compilers may use (@noreturn as an example), but outside of the compiler I'd n

Re: So, User-Defined Attributes

2013-01-05 Thread Johannes Pfau
Am Fri, 04 Jan 2013 21:33:03 +0100 schrieb "Era Scarecrow" : > On Friday, 4 January 2013 at 15:45:21 UTC, Philippe Sigaud wrote: > > User Defined Attributes (UDA) are compile time expressions that > > can be attached to a declaration. These attributes can then be > > queried, extracted, and mani

Re: So, User-Defined Attributes

2013-01-05 Thread Philippe Sigaud
Clojure uses its metadata (attached to values, though, not declaration) to put documentation strings there. That's quite doable with D: @(doc("This function does ")) auto foo() { ... } I'm also interested in tagging data: @(Sorted!(withThisFun)) someRange ... @(Ranged(0.0, 1.0)) someRange .

Re: So, User-Defined Attributes

2013-01-05 Thread Jacob Carlborg
On 2013-01-05 15:13, Philippe Sigaud wrote: Clojure uses its metadata (attached to values, though, not declaration) to put documentation strings there. That's quite doable with D: @(doc("This function does ")) auto foo() { ... } I'm also interested in tagging data: @(Sorted!(withThisFun)

Re: So, User-Defined Attributes

2013-01-05 Thread Philippe Sigaud
On Sat, Jan 5, 2013 at 6:00 PM, Jacob Carlborg wrote: > Just for the record, the extra parentheses are not needed: > > @doc("This function does ") auto foo () { } > @Sorted!(withThisFun) someRange ... Good to know. I tested it with basic values and this fails: @"hello" int i; @3 inj j; W

Re: So, User-Defined Attributes

2013-01-05 Thread Jacob Carlborg
On 2013-01-05 19:54, Philippe Sigaud wrote: Good to know. I tested it with basic values and this fails: @"hello" int i; @3 inj j; Worth a bug report? No, that's by design. When I added that syntax first but I was asked to change it to only accept call expressions. Have a look at the grammar

Re: So, User-Defined Attributes

2013-01-05 Thread Philippe Sigaud
> > No, that's by design. When I added that syntax first but I was asked to > change it to only accept call expressions. > >> @int S s; >> >> is not >> > > That is not supposed to be legal (see above), but this might be: > > @(int) S s; > > Does that work? No. It produces reams of error. >

Re: So, User-Defined Attributes

2013-01-05 Thread Walter Bright
On 1/5/2013 10:54 AM, Philippe Sigaud wrote: Another bug report? This is as designed, not a bug. The attribute must start with a @( or @identifier. Not @keyword, @number, @string, @operator, etc. If you want, file an enhancement request for more. But the design was deliberately restrictive

Re: So, User-Defined Attributes

2013-01-05 Thread Philippe Sigaud
On Sat, Jan 5, 2013 at 10:20 PM, Walter Bright wrote: > On 1/5/2013 10:54 AM, Philippe Sigaud wrote: > >> Another bug report? >> > > This is as designed, not a bug. The attribute must start with a @( or > @identifier. Not @keyword, @number, @string, @operator, etc. > That, I can understand. But

Re: So, User-Defined Attributes

2013-01-05 Thread Walter Bright
On 1/5/2013 2:06 PM, Philippe Sigaud wrote: But why is @(MyType) accepted, whereas @(int) is not? Because it's looking for an expression inside the parents, and int is not an expression.

Re: So, User-Defined Attributes

2013-01-05 Thread Philippe Sigaud
On Sat, Jan 5, 2013 at 11:14 PM, Walter Bright wrote: > On 1/5/2013 2:06 PM, Philippe Sigaud wrote: > >> But why is @(MyType) accepted, whereas @(int) is not? >> > > Because it's looking for an expression inside the parents, and int is not > an expression. > > Well, first that would be nice to hav

Re: So, User-Defined Attributes

2013-01-05 Thread Jacob Carlborg
On 2013-01-05 23:44, Philippe Sigaud wrote: Well, first that would be nice to have the grammar online :) Yeah, still waiting for that pull request to be merged. -- /Jacob Carlborg

Re: So, User-Defined Attributes

2013-01-05 Thread Domain
On Saturday, 5 January 2013 at 22:57:03 UTC, Jacob Carlborg wrote: On 2013-01-05 23:44, Philippe Sigaud wrote: Well, first that would be nice to have the grammar online :) Yeah, still waiting for that pull request to be merged. UDA can not apply to function argument? enum attr; void func(@

Re: So, User-Defined Attributes

2013-01-05 Thread Walter Bright
On 1/5/2013 10:57 PM, Domain wrote: On Saturday, 5 January 2013 at 22:57:03 UTC, Jacob Carlborg wrote: On 2013-01-05 23:44, Philippe Sigaud wrote: Well, first that would be nice to have the grammar online :) Yeah, still waiting for that pull request to be merged. UDA can not apply to funct

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
On Sun, Jan 6, 2013 at 8:16 AM, Walter Bright wrote: > > >> UDA can not apply to function argument? >> >> > Currently, no. > Walter, what is the official way to return an attributed value? XXX? foo() { @Marked int i; return i; }

Re: So, User-Defined Attributes

2013-01-06 Thread Walter Bright
On 1/6/2013 1:48 AM, Philippe Sigaud wrote: Walter, what is the official way to return an attributed value? XXX? foo() { @Marked int i; return i; } Values do not have attributes. Attributes are attached to symbols - not values or types.

Re: So, User-Defined Attributes

2013-01-06 Thread Jacob Carlborg
On 2013-01-06 10:48, Philippe Sigaud wrote: Walter, what is the official way to return an attributed value? XXX? foo() { @Marked int i; return i; } Don't know if this is what you want but: struct Marked {} struct Attrs (T...) {} auto bar () { @Marked int i; return Attrs!(_

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
> Don't know if this is what you want but: > > struct Marked {} > struct Attrs (T...) {} > > auto bar () > { > @Marked int i; > return Attrs!(__traits(getAttributes, i))(); > } > > void main () > { > writeln(bar()); // prints Attrs!(Marked)() > } I just want to be able to return an at

Re: So, User-Defined Attributes

2013-01-06 Thread Jacob Carlborg
On 2013-01-06 14:29, Philippe Sigaud wrote: I just want to be able to return an attributed something. How can a function return something that's attributed? IIUC what Walter said, a function cannot return an attributed value: any internal symbol can be attributed, but these cannot get out. I ca

Re: So, User-Defined Attributes

2013-01-06 Thread Jacob Carlborg
On 2013-01-06 14:29, Philippe Sigaud wrote: Don't know if this is what you want but: struct Marked {} struct Attrs (T...) {} auto bar () { @Marked int i; return Attrs!(__traits(getAttributes, i))(); } void main () { writeln(bar()); //

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
The only way would be what you suggest: >> >> - extract the attributes from the internal i >> - store them in a specially-crafted struct >> - return that >> - in the external code, catch the returned struct >> - extract the artificially stored attributes >> - generate a new value with the same attr

Re: So, User-Defined Attributes

2013-01-06 Thread Jacob Carlborg
On 2013-01-06 15:25, Philippe Sigaud wrote: That would mean two mixins, one internal and one external. Plus, that means every function where I want to propagate UDA has to be crafted exactly for this need. This is a drag. It seems natural to me that int foo(int i) { return i;} should forward

Re: So, User-Defined Attributes

2013-01-06 Thread Andrei Alexandrescu
On 1/6/13 9:25 AM, Philippe Sigaud wrote: That's too bad, because declaring UDA is simple, and receiving them with arguments is easy also. There is a fundamental imbalance in having having propagating attributes through functions so difficult. For designing attributes that navigate with types

Re: So, User-Defined Attributes

2013-01-06 Thread bearophile
Andrei Alexandrescu: For designing attributes that navigate with types templates would be the solution of choice. There's an interesting cognitive impercetion phenomena here, that's worth studying and not ignoring. From the little evidence here, it seems that D programmers want to use UDAs i

Re: So, User-Defined Attributes

2013-01-06 Thread Era Scarecrow
On Saturday, 5 January 2013 at 11:57:39 UTC, Johannes Pfau wrote: Era Scarecrow wrote: This is sorta like tuples; But from the brief summaries I cannot fully understand how or where they would be used. I understand some attributes can be made and added that some compilers may use (@noreturn as

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
On Sun, Jan 6, 2013 at 3:58 PM, Andrei Alexandrescu < seewebsiteforem...@erdani.org> wrote: > On 1/6/13 9:25 AM, Philippe Sigaud wrote: > >> That's too bad, because declaring UDA is simple, and receiving them with >> arguments is easy also. There is a fundamental imbalance in having >> having prop

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
On Sun, Jan 6, 2013 at 3:29 PM, Jacob Carlborg wrote: > > Yeah, if you want to work with UDA's you need to work with symbols, not > values or types. If you want to pass a symbol, including its UDA, you need > to pass it as an alias: > That was the explanation I needed: UDA are attached to symbol

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
Hmm, did anyone try to put attribute before a function overload and not > another? > > Ca > Damn tab. Can attributes be defined by templates arguments? @(T) class C(T) : T { } Answer: no. OK.

Re: So, User-Defined Attributes

2013-01-06 Thread Timon Gehr
On 01/04/2013 11:43 PM, Philippe Sigaud wrote: On Fri, Jan 4, 2013 at 9:58 PM, Walter Bright mailto:newshou...@digitalmars.com>> wrote: Module declarations aren't declarations. Great quote :) Walter often argues in terms of DMD implementation details. ... struct ModuleDeclaration {

Re: So, User-Defined Attributes

2013-01-06 Thread deadalnix
On Saturday, 5 January 2013 at 22:14:47 UTC, Walter Bright wrote: On 1/5/2013 2:06 PM, Philippe Sigaud wrote: But why is @(MyType) accepted, whereas @(int) is not? Because it's looking for an expression inside the parents, and int is not an expression. And mytype is an expression ?

Re: So, User-Defined Attributes

2013-01-06 Thread deadalnix
On Sunday, 6 January 2013 at 14:58:07 UTC, Andrei Alexandrescu wrote: On 1/6/13 9:25 AM, Philippe Sigaud wrote: That's too bad, because declaring UDA is simple, and receiving them with arguments is easy also. There is a fundamental imbalance in having having propagating attributes through func

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
On Fri, Jan 4, 2013 at 9:58 PM, Walter Bright > > >> wrote: >> >> >> Module declarations aren't declarations. >> >> >> Great quote :) >> >> >> > Walter often argues in terms of DMD implementation details. > > ... > struct ModuleDeclaration > { > Identi

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
On Sun, Jan 6, 2013 at 11:24 PM, deadalnix wrote: > On Saturday, 5 January 2013 at 22:14:47 UTC, Walter Bright wrote: > >> On 1/5/2013 2:06 PM, Philippe Sigaud wrote: >> >>> But why is @(MyType) accepted, whereas @(int) is not? >>> >> >> Because it's looking for an expression inside the parents,

Re: So, User-Defined Attributes

2013-01-06 Thread Timon Gehr
On 01/06/2013 07:24 PM, Philippe Sigaud wrote: Can attributes be defined by templates arguments? @(T) class C(T) : T { } Answer: no. OK. This works: template C(T){ @T class C : T { } } The above appears to annotate the template itself, which is inconsistent. You should probably file a bu

Re: So, User-Defined Attributes

2013-01-06 Thread Timon Gehr
On 01/06/2013 11:27 PM, deadalnix wrote: On Sunday, 6 January 2013 at 14:58:07 UTC, Andrei Alexandrescu wrote: On 1/6/13 9:25 AM, Philippe Sigaud wrote: That's too bad, because declaring UDA is simple, and receiving them with arguments is easy also. There is a fundamental imbalance in having ha

Re: So, User-Defined Attributes

2013-01-06 Thread Timon Gehr
On 01/06/2013 11:24 PM, deadalnix wrote: On Saturday, 5 January 2013 at 22:14:47 UTC, Walter Bright wrote: On 1/5/2013 2:06 PM, Philippe Sigaud wrote: But why is @(MyType) accepted, whereas @(int) is not? Because it's looking for an expression inside the parents, and int is not an expression.

Re: So, User-Defined Attributes

2013-01-06 Thread Walter Bright
On 1/6/2013 2:24 PM, deadalnix wrote: On Saturday, 5 January 2013 at 22:14:47 UTC, Walter Bright wrote: On 1/5/2013 2:06 PM, Philippe Sigaud wrote: But why is @(MyType) accepted, whereas @(int) is not? Because it's looking for an expression inside the parents, and int is not an expression.

Re: So, User-Defined Attributes

2013-01-06 Thread deadalnix
On Monday, 7 January 2013 at 00:38:35 UTC, Walter Bright wrote: On 1/6/2013 2:24 PM, deadalnix wrote: On Saturday, 5 January 2013 at 22:14:47 UTC, Walter Bright wrote: On 1/5/2013 2:06 PM, Philippe Sigaud wrote: But why is @(MyType) accepted, whereas @(int) is not? Because it's looking for a

Re: So, User-Defined Attributes

2013-01-06 Thread Walter Bright
On 1/6/2013 5:06 PM, deadalnix wrote: On Monday, 7 January 2013 at 00:38:35 UTC, Walter Bright wrote: On 1/6/2013 2:24 PM, deadalnix wrote: On Saturday, 5 January 2013 at 22:14:47 UTC, Walter Bright wrote: On 1/5/2013 2:06 PM, Philippe Sigaud wrote: But why is @(MyType) accepted, whereas @(in

Re: So, User-Defined Attributes

2013-01-06 Thread Timon Gehr
On 01/07/2013 01:38 AM, Walter Bright wrote: On 1/6/2013 2:24 PM, deadalnix wrote: On Saturday, 5 January 2013 at 22:14:47 UTC, Walter Bright wrote: On 1/5/2013 2:06 PM, Philippe Sigaud wrote: But why is @(MyType) accepted, whereas @(int) is not? Because it's looking for an expression inside

Re: So, User-Defined Attributes

2013-01-06 Thread Timon Gehr
On 01/07/2013 04:27 AM, Timon Gehr wrote: ... (Eg. I am still reducing the massive breakage introduced by 2.061 regressions. Mostly 'forward reference' errors -- mentioned nowhere in the spec, and seemingly introduced in order to 'fix' ICEs.) ... dustmite ftw. http://d.puremagic.com/issues/sho

Re: So, User-Defined Attributes

2013-01-06 Thread Philippe Sigaud
On Mon, Jan 7, 2013 at 4:27 AM, Timon Gehr wrote: > > > The compiler should obviously use the part of the parser that parses > template arguments to parse UDA's. I am surprised this is not what is done. > I humbly concur. Walter, you yourself presented UDAs as 'linking the dots' between differen

Re: So, User-Defined Attributes

2013-01-06 Thread Walter Bright
On 1/6/2013 8:37 PM, Timon Gehr wrote: dustmite ftw. http://d.puremagic.com/issues/show_bug.cgi?id=9276 Thank you.

Re: So, User-Defined Attributes

2013-01-06 Thread Walter Bright
On 1/6/2013 9:44 PM, Philippe Sigaud wrote: I humbly concur. Walter, you yourself presented UDAs as 'linking the dots' between different part of the D language (tuples...). It's an interesting and elegant approach, but the current situation is somewhat inadequate: UDA can be manipulated like temp

Re: So, User-Defined Attributes

2013-01-06 Thread Walter Bright
On 1/6/2013 7:27 PM, Timon Gehr wrote: I am still reducing the massive breakage introduced by 2.061 regressions. Sorry about that, but 2.061 has been available for 2 months in beta. We fixed all but 3 of the reported regressions, and had good reasons for deferring those. In fact, the 2.062 w

Re: So, User-Defined Attributes

2013-01-06 Thread Timon Gehr
On 01/07/2013 07:27 AM, Walter Bright wrote: On 1/6/2013 7:27 PM, Timon Gehr wrote: I am still reducing the massive breakage introduced by 2.061 regressions. Sorry about that, No problem. There will be some way to get it to compile. The reduced code shows which points to concentrate modific

Re: So, User-Defined Attributes

2013-01-07 Thread Walter Bright
On 1/6/2013 11:31 PM, Timon Gehr wrote: I am sure that very good progress is being made. However, the forward reference error problem will need formal treatment at some point. I think one reason they pop up is that symbol lookup for the intended language is inherently impossible to compute. A h

Re: So, User-Defined Attributes

2013-01-07 Thread Era Scarecrow
On Monday, 7 January 2013 at 07:58:29 UTC, Walter Bright wrote: A huge source of fwd ref problems was not at all about symbol lookup. It was about partial types referencing properties of themselves. For example, struct S { int a; int b = S.sizeof; int c; } for a simple example. Th