www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - isExpressions -> isValuesSeq

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
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
Dec 11 2015
next sibling parent reply Mike Parker <aldacron gmail.com> writes:
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)
Dec 12 2015
parent reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
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
Dec 12 2015
parent reply Mike Parker <aldacron gmail.com> writes:
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?
Dec 12 2015
next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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.
Dec 12 2015
parent Timon Gehr <timon.gehr gmx.ch> writes:
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.
Dec 12 2015
prev sibling parent Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
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
Dec 14 2015
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
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).)
Dec 12 2015