digitalmars.D - isExpressions -> isValuesSeq
- Shriramana Sharma (21/21) Dec 11 2015 This is w.r.t. http://dlang.org/phobos/std_traits.html#isExpressions:
- Mike Parker (6/14) Dec 12 2015 All values, 3 and false included, *are* expressions. They are
- Shriramana Sharma (6/11) Dec 12 2015 That's true, but the fact remains that the AliasSeq stores only the
- Mike Parker (5/14) Dec 12 2015 Consider what would happen if they did not evaluate expressions:
- Timon Gehr (2/17) Dec 12 2015 It isn't evaluated.
- Timon Gehr (2/22) Dec 12 2015 Sorry, missed the parentheses.
- Shriramana Sharma (10/11) Dec 14 2015 I never said they should not evaluate expressions. Expressions are alway...
- Timon Gehr (9/28) Dec 12 2015 There is also this:
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? --
Dec 11 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)
Dec 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). --
Dec 12 2015
On Saturday, 12 December 2015 at 14:05:04 UTC, Shriramana Sharma wrote:Mike Parker wrote:Consider what would happen if they did not evaluate expressions: AliasSeq!(someFunc, someFunc()); Would you really want someFunc() not to be evaluated?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).
Dec 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:It isn't evaluated.Mike Parker wrote:Consider what would happen if they did not evaluate expressions: AliasSeq!(someFunc, someFunc()); Would you really want someFunc() not to be evaluated?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).
Dec 12 2015
On 12/12/2015 09:01 PM, Timon Gehr wrote:On 12/12/2015 03:51 PM, Mike Parker wrote:Sorry, missed the parentheses.On Saturday, 12 December 2015 at 14:05:04 UTC, Shriramana Sharma wrote:It isn't evaluated.Mike Parker wrote:Consider what would happen if they did not evaluate expressions: AliasSeq!(someFunc, someFunc()); Would you really want someFunc() not to be evaluated?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).
Dec 12 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. --
Dec 14 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).)
Dec 12 2015