Thread overview
alias c=mixin(expr); disallowed, why?
Jun 22, 2013
Timothee Cour
Jun 22, 2013
Timon Gehr
Jun 22, 2013
Timothee Cour
Jun 22, 2013
Timon Gehr
Jun 22, 2013
Timothee Cour
Jun 23, 2013
Jacob Carlborg
Jun 23, 2013
Timon Gehr
Jun 23, 2013
Jacob Carlborg
June 22, 2013
Is there a reason the language spec disallows this?

----
void main(){
auto a=mixin("1");//OK
alias b=a;//OK
mixin("alias c=a;");//OK
// alias c=mixin("a");//NG : Error: basic type expected, not mixin
}
----


June 22, 2013
On 06/22/2013 09:52 PM, Timothee Cour wrote:
> Is there a reason the language spec disallows this?
>
> ----
> void main(){
>     auto a=mixin("1");//OK
>     alias b=a;//OK
>     mixin("alias c=a;");//OK
>     // alias c=mixin("a");//NG : Error: basic type expected, not mixin
> }
> ----

No, it is arbitrary.
June 22, 2013
On Sat, Jun 22, 2013 at 2:47 PM, Timon Gehr <timon.gehr@gmx.ch> wrote:

> On 06/22/2013 09:52 PM, Timothee Cour wrote:
>
>> Is there a reason the language spec disallows this?
>>
>> ----
>> void main(){
>>     auto a=mixin("1");//OK
>>     alias b=a;//OK
>>     mixin("alias c=a;");//OK
>>     // alias c=mixin("a");//NG : Error: basic type expected, not mixin
>> }
>> ----
>>
>
> No, it is arbitrary.
>

that's what i thought!
same with template mixin's being restricated.

... can we fix it?

it makes for cleaner code.


June 22, 2013
On 06/22/2013 11:51 PM, Timothee Cour wrote:
>
>
> On Sat, Jun 22, 2013 at 2:47 PM, Timon Gehr <timon.gehr@gmx.ch
> <mailto:timon.gehr@gmx.ch>> wrote:
>
>     On 06/22/2013 09:52 PM, Timothee Cour wrote:
>
>         Is there a reason the language spec disallows this?
>
>         ----
>         void main(){
>              auto a=mixin("1");//OK
>              alias b=a;//OK
>              mixin("alias c=a;");//OK
>              // alias c=mixin("a");//NG : Error: basic type expected,
>         not mixin
>         }
>         ----
>
>
>     No, it is arbitrary.
>
>
> that's what i thought!
> same with template mixin's being restricated.
>

?

> ... can we fix it?
>
> it makes for cleaner code.
>

It surely could be fixed if you want to spend the time hacking on DMD.
I think the grammar is somewhat poorly designed in general.
June 22, 2013
On Sat, Jun 22, 2013 at 2:55 PM, Timon Gehr <timon.gehr@gmx.ch> wrote:

> On 06/22/2013 11:51 PM, Timothee Cour wrote:
>
>>
>>
>> On Sat, Jun 22, 2013 at 2:47 PM, Timon Gehr <timon.gehr@gmx.ch <mailto:timon.gehr@gmx.ch>> wrote:
>>
>>     On 06/22/2013 09:52 PM, Timothee Cour wrote:
>>
>>         Is there a reason the language spec disallows this?
>>
>>         ----
>>         void main(){
>>              auto a=mixin("1");//OK
>>              alias b=a;//OK
>>              mixin("alias c=a;");//OK
>>              // alias c=mixin("a");//NG : Error: basic type expected,
>>         not mixin
>>         }
>>         ----
>>
>>
>>     No, it is arbitrary.
>>
>>
>> that's what i thought!
>> same with template mixin's being restricated.
>>
>>
> ?
>
>
they're restricted to declarations. I don't see the need for such restriction.



>  ... can we fix it?
>>
>> it makes for cleaner code.
>>
>>
> It surely could be fixed if you want to spend the time hacking on DMD. I think the grammar is somewhat poorly designed in general.
>


June 23, 2013
On 2013-06-22 23:47, Timon Gehr wrote:

> No, it is arbitrary.

I think the spec says you can only mixin whole expression. But for some reason you can use a mixin in a __traits expression without having the whole expression in a mixin.

-- 
/Jacob Carlborg
June 23, 2013
On 06/23/2013 11:32 AM, Jacob Carlborg wrote:
> On 2013-06-22 23:47, Timon Gehr wrote:
>
>> No, it is arbitrary.
>
> I think the spec says you can only mixin whole expression.

That only means you cannot do things like eg:

mixin("a*"); mixin("b");

but instead you need to do:

mixin("a*b");

such that the string content forms a valid expression according to the grammar.


> But for some
> reason you can use a mixin in a __traits expression without having the
> whole expression in a mixin.
>

Example?
June 23, 2013
On 2013-06-23 13:27, Timon Gehr wrote:

> Example?

@(3) int a;
alias Tuple!(__traits(getAttributes, mixin("a"))) attrs;

-- 
/Jacob Carlborg