Thread overview
isExpressions -> isValuesSeq
Dec 12, 2015
Shriramana Sharma
Dec 12, 2015
Mike Parker
Dec 12, 2015
Shriramana Sharma
Dec 12, 2015
Mike Parker
Dec 12, 2015
Timon Gehr
Dec 12, 2015
Timon Gehr
Dec 14, 2015
Shriramana Sharma
Dec 12, 2015
Timon Gehr
December 12, 2015
This is w.r.t. http://dlang.org/phobos/std_traits.html#isExpressions:

I am trying the following code:

import std.stdio, std.meta, std.traits;
void main()
{
    alias a = AliasSeq!(1 + 2, "foo" == "goo");
    if (isExpressions!a) write("This AliasSeq contains expressions: ");
    foreach (v; a) { write(v.stringof, ", "); } writeln();
    writeln("This should be: ", (1 + 2).stringof, ", ", ("foo" ==
"goo").stringof);
}

The output is:

This AliasSeq contains expressions: 3, false, This should be: 1 + 2, "foo" == "goo"

Clearly, the AliasSeq is not able to store the expressions themselves since they are automatically evaluated at compile time. It stores only the values that the expressions evaluate to. Further, expressions which are not evaluable at compile time aren't permitted in the AliasSeq. (I tried it.) Thus the appropriate name would thus be isValuesSeq, no?

-- 
Shriramana Sharma, Penguin #395953
December 12, 2015
On Saturday, 12 December 2015 at 06:41:11 UTC, Shriramana Sharma wrote:
>
> This AliasSeq contains expressions: 3, false, This should be: 1 + 2, "foo" == "goo"
>
> Clearly, the AliasSeq is not able to store the expressions themselves since they are automatically evaluated at compile time. It stores only the values that the expressions evaluate to. Further, expressions which are not evaluable at compile time aren't permitted in the AliasSeq. (I tried it.) Thus the appropriate name would thus be isValuesSeq, no?

All values, 3 and false included, *are* expressions. They are expressions with one operand and no operator, but they are still expressions.

https://en.wikipedia.org/wiki/Value_(computer_science)
December 12, 2015
Mike Parker wrote:

> All values, 3 and false included, *are* expressions. They are expressions with one operand and no operator, but they are still expressions.
> 
> https://en.wikipedia.org/wiki/Value_(computer_science)

That's true, but the fact remains that the AliasSeq stores only the resultant value of the expression and not the expression itself (which may be valid or not).

-- 
Shriramana Sharma, Penguin #395953
December 12, 2015
On Saturday, 12 December 2015 at 14:05:04 UTC, Shriramana Sharma wrote:
> Mike Parker wrote:
>
>> All values, 3 and false included, *are* expressions. They are expressions with one operand and no operator, but they are still expressions.
>> 
>> https://en.wikipedia.org/wiki/Value_(computer_science)
>
> That's true, but the fact remains that the AliasSeq stores only the resultant value of the expression and not the expression itself (which may be valid or not).

Consider what would happen if they did not evaluate expressions:

AliasSeq!(someFunc, someFunc());

Would you really want someFunc() not to be evaluated?
December 12, 2015
On 12/12/2015 03:51 PM, Mike Parker wrote:
> On Saturday, 12 December 2015 at 14:05:04 UTC, Shriramana Sharma wrote:
>> Mike Parker wrote:
>>
>>> All values, 3 and false included, *are* expressions. They are
>>> expressions with one operand and no operator, but they are still
>>> expressions.
>>>
>>> https://en.wikipedia.org/wiki/Value_(computer_science)
>>
>> That's true, but the fact remains that the AliasSeq stores only the
>> resultant value of the expression and not the expression itself (which
>> may be valid or not).
>
> Consider what would happen if they did not evaluate expressions:
>
> AliasSeq!(someFunc, someFunc());
>
> Would you really want someFunc() not to be evaluated?

It isn't evaluated.
December 12, 2015
On 12/12/2015 07:41 AM, Shriramana Sharma wrote:
> This is w.r.t. http://dlang.org/phobos/std_traits.html#isExpressions:
>
> I am trying the following code:
>
> import std.stdio, std.meta, std.traits;
> void main()
> {
>      alias a = AliasSeq!(1 + 2, "foo" == "goo");
>      if (isExpressions!a) write("This AliasSeq contains expressions: ");
>      foreach (v; a) { write(v.stringof, ", "); } writeln();
>      writeln("This should be: ", (1 + 2).stringof, ", ", ("foo" ==
> "goo").stringof);
> }
>
> The output is:
>
> This AliasSeq contains expressions: 3, false,
> This should be: 1 + 2, "foo" == "goo"
>
> Clearly, the AliasSeq is not able to store the expressions themselves since
> they are automatically evaluated at compile time. It stores only the values
> that the expressions evaluate to. Further, expressions which are not
> evaluable at compile time aren't permitted in the AliasSeq. (I tried it.)
> Thus the appropriate name would thus be isValuesSeq, no?
>

There is also this:

import std.stdio;
int x,y;
@(x+1,y) void foo(){}
void main(){ writeln(__traits(getAttributes,foo)); }

(However, variadic template arguments that are non-symbol expressions are always evaluated, therefore isExpressions does not work on the result of __traits(getAttributes,foo).)
December 12, 2015
On 12/12/2015 09:01 PM, Timon Gehr wrote:
> On 12/12/2015 03:51 PM, Mike Parker wrote:
>> On Saturday, 12 December 2015 at 14:05:04 UTC, Shriramana Sharma wrote:
>>> Mike Parker wrote:
>>>
>>>> All values, 3 and false included, *are* expressions. They are
>>>> expressions with one operand and no operator, but they are still
>>>> expressions.
>>>>
>>>> https://en.wikipedia.org/wiki/Value_(computer_science)
>>>
>>> That's true, but the fact remains that the AliasSeq stores only the
>>> resultant value of the expression and not the expression itself (which
>>> may be valid or not).
>>
>> Consider what would happen if they did not evaluate expressions:
>>
>> AliasSeq!(someFunc, someFunc());
>>
>> Would you really want someFunc() not to be evaluated?
>
> It isn't evaluated.

Sorry, missed the parentheses.
December 14, 2015
Mike Parker wrote:

> Consider what would happen if they did not evaluate expressions:

I never said they should not evaluate expressions. Expressions are always evaluated in any context in D, but they are immediately converted to values (so long as they are evaluable). But for this very reason, alias sequences can not "contain" or "encapsulate" expressions in un-evaluated form in any way (unlike, say http://docs.sympy.org/dev/modules/core.html#sympy.core.mul.Mul) in that the components of the expression are lost by the time the AliasSeq gets defined.

-- 
Shriramana Sharma, Penguin #395953