January 04, 2013
On Fri, Jan 4, 2013 at 9:40 PM, Walter Bright <newshound2@digitalmars.com>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 wouldn't be an alternate name if it had different attributes. Trying to make such work would have serious semantic consequences.
>
> Hence, no, you cannot use alias to modify the attributes.
>
>
The (future) documentation says attributes can be used with declarations. I tried to use one before a module declaration but it didn't work.

Is that a bug or are module declarations not 'real' declarations?


January 04, 2013
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 = 10;
    @(__traits(getAttributes, i)) double d2;
    writeln("[",__traits(getAttributes, d2), "]");
}
January 04, 2013
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.
January 04, 2013
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;
> void main()
> {
> @(3, "hello") int i = 10;
> @(__traits(getAttributes, i)) double d2;
> writeln("[",__traits(getAttributes, d2), "]");
> }

For transfer templates are better than attributes.

Andrei
January 04, 2013
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.

January 04, 2013
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 what the intended semantics of alias is. But the reality is slightly different. See below.

> It wouldn't be an alternate name if it had different attributes. Trying to make such work would have serious semantic consequences.
>
> Hence, no, you cannot use alias to modify the attributes.

You can:

public struct S
{
}

private alias S S2; // visibility attribute is changed.

Type modifiers:

alias const(S) S2; // mutability attribute is changed.

I am not saying that UDAs should be designed so that they could modify the aliased "symbols" (that would be a fatality) - just noting that alias is already NOT a plain alternative name.
January 04, 2013
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.
January 04, 2013
On Fri, Jan 4, 2013 at 9:58 PM, Walter Bright <newshound2@digitalmars.com>wrote:

>
> Module declarations aren't declarations.
>

Great quote :)


January 04, 2013
On Fri, Jan 4, 2013 at 9:59 PM, Andrei Alexandrescu < SeeWebsiteForEmail@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, "hello") int i = 10;
>> @(__traits(getAttributes, i)) double d2;
>> writeln("[",__traits(**getAttributes, d2), "]");
>> }
>>
>
Yes, I know. I just want to automate the process. I want a function or some
piece of code that can propagate attributes.
For example, say I receive a piece of unvalidated input. I test it and it's
OK. I want to return it, with a new attribute (say, Validated() ),while
keeping the input attributes. Since it seems a common need, I was looking
for a way to abstract the process somewhat.

For now, we would return a Validated(initialValue) struct. I just want to see how attributes can be used here. It seems that:

@(Validated, __traits(getAttributes, input)) InputType temp;
return temp;

do not work.

If attribute manipulation cannot be isolated in easily reusable code, that would be sad.



Andrei:

>
> For transfer templates are better than attributes.


Could you please give an example?


January 04, 2013
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 not. I'll have to think about it. The visibility "attribute" is a bit of an oddity.

> Type modifiers:
>
> alias const(S) S2; // mutability attribute is changed.

This is not a bug. const(S) is a type constructor, not an attribute, and you are aliasing a type, not a symbol.