digitalmars.D.learn - Feature or bug: print braces
- Dennis Ritchie (8/8) May 13 2015 Why doesn't the compiler produces an error?
- Brian Schott (5/13) May 13 2015 You told it to output a function literal, so it did.
- Dennis Ritchie (6/7) May 13 2015 Yes, but it would be logical to deduce something like:
- Alex Parrill (8/15) May 14 2015 Literal what?
- Dennis Ritchie (5/23) May 14 2015 I just wanted to say that writeln function of demand should not
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (24/48) May 14 2015 Yes, it is weird but that value happens to be the address of the
- Dennis Ritchie (2/27) May 14 2015 Thanks. This example explains a lot. It's like echoes UFCS :)
- Dennis Ritchie (9/9) May 13 2015 Turns out that I can put into the function writeln almost any
- Ivan Kazmenko (3/11) May 15 2015 Somehow reminds me of this lambda:
- Dennis Ritchie (16/18) May 15 2015 Maybe it generally blocks for initialization of variables:
Why doesn't the compiler produces an error? ----- import std.stdio; void main() { writeln({}); } ----- http://ideone.com/qTZCAd
May 13 2015
On Thursday, 14 May 2015 at 00:29:06 UTC, Dennis Ritchie wrote:Why doesn't the compiler produces an error? ----- import std.stdio; void main() { writeln({}); } ----- http://ideone.com/qTZCAdYou told it to output a function literal, so it did. (That or you told it to output a struct literal, but the compiler has arbitrarily decided that it's a function literal. This is NOT my favorite part of D's grammar.)
May 13 2015
On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote:You told it to output a function literal, so it did.Yes, but it would be logical to deduce something like: ----- writeln({}); // prints literal[{}] Or the compiler will not be able to distinguish the literal from the ordinary function arguments?
May 13 2015
On Thursday, 14 May 2015 at 00:39:25 UTC, Dennis Ritchie wrote:On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote:Literal what? Associative array? That uses square brackets, not curly brackets. Struct? What struct would you be creating? And curly braces only works for initialization. Lambda? Well you can omit the parameters if there are none, and `{}` in a lambda will give you a block to write, so `{}` is a valid lambda that accepts nothing and does nothing.You told it to output a function literal, so it did.Yes, but it would be logical to deduce something like: ----- writeln({}); // prints literal[{}] Or the compiler will not be able to distinguish the literal from the ordinary function arguments?
May 14 2015
On Thursday, 14 May 2015 at 21:55:40 UTC, Alex Parrill wrote:On Thursday, 14 May 2015 at 00:39:25 UTC, Dennis Ritchie wrote:I just wanted to say that writeln function of demand should not print anything else at this challenge, not 804CF88 :) ----- writeln({});On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote:Literal what? Associative array? That uses square brackets, not curly brackets. Struct? What struct would you be creating? And curly braces only works for initialization. Lambda? Well you can omit the parameters if there are none, and `{}` in a lambda will give you a block to write, so `{}` is a valid lambda that accepts nothing and does nothing.You told it to output a function literal, so it did.Yes, but it would be logical to deduce something like: ----- writeln({}); // prints literal[{}] Or the compiler will not be able to distinguish the literal from the ordinary function arguments?
May 14 2015
On 05/14/2015 03:39 PM, Dennis Ritchie wrote:On Thursday, 14 May 2015 at 21:55:40 UTC, Alex Parrill wrote:Yes, it is weird but that value happens to be the address of the function. Here is another test: import std.stdio; void foo() pure nothrow nogc safe {} void main() { void printInfo(T)(T t) { writefln("%s %s", T.stringof, t); } auto f = (){}; // <-- Why the need for () here? printInfo(&foo); printInfo(f); printInfo({}); // <-- No need for () here. } There is an inconsistency where a lambda need to be defined with empty parentheses in one context while it is just fine without in another context. One output shows that they are all of the same type (function pointers): void function() pure nothrow nogc safe 473264 void function() pure nothrow nogc safe 4732BC void function() pure nothrow nogc safe 4732C4 AliOn Thursday, 14 May 2015 at 00:39:25 UTC, Dennis Ritchie wrote:I just wanted to say that writeln function of demand should not print anything else at this challenge, not 804CF88 :) ----- writeln({});On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote:Literal what? Associative array? That uses square brackets, not curly brackets. Struct? What struct would you be creating? And curly braces only works for initialization. Lambda? Well you can omit the parameters if there are none, and `{}` in a lambda will give you a block to write, so `{}` is a valid lambda that accepts nothing and does nothing.You told it to output a function literal, so it did.Yes, but it would be logical to deduce something like: ----- writeln({}); // prints literal[{}] Or the compiler will not be able to distinguish the literal from the ordinary function arguments?
May 14 2015
On Thursday, 14 May 2015 at 22:55:43 UTC, Ali Çehreli wrote:Yes, it is weird but that value happens to be the address of the function. Here is another test: import std.stdio; void foo() pure nothrow nogc safe {} void main() { void printInfo(T)(T t) { writefln("%s %s", T.stringof, t); } auto f = (){}; // <-- Why the need for () here? printInfo(&foo); printInfo(f); printInfo({}); // <-- No need for () here. } There is an inconsistency where a lambda need to be defined with empty parentheses in one context while it is just fine without in another context. One output shows that they are all of the same type (function pointers): void function() pure nothrow nogc safe 473264 void function() pure nothrow nogc safe 4732BC void function() pure nothrow nogc safe 4732C4 AliThanks. This example explains a lot. It's like echoes UFCS :)
May 14 2015
Turns out that I can put into the function writeln almost any design language: ----- import std.stdio; void main() { writeln( { int n = 5; } ); } ----- http://ideone.com/Rp7gZ2
May 13 2015
On Thursday, 14 May 2015 at 00:29:06 UTC, Dennis Ritchie wrote:Why doesn't the compiler produces an error? ----- import std.stdio; void main() { writeln({}); } ----- http://ideone.com/qTZCAdSomehow reminds me of this lambda: https://github.com/Hackerpilot/Idiotmatic-D/blob/master/idiotmatic.d#L127-L128
May 15 2015
On Friday, 15 May 2015 at 08:44:41 UTC, Ivan Kazmenko wrote:Somehow reminds me of this lambda: https://github.com/Hackerpilot/Idiotmatic-D/blob/master/idiotmatic.d#L127-L128Maybe it generally blocks for initialization of variables: https://github.com/Hackerpilot/Idiotmatic-D/blob/master/idiotmatic.d#L130-L131 ----- for ( { int i = 0; } i < 5; ++i ) { writeln("test"); } It seems to me that this should be fixed :) ----- int x; void foo(int tmp) { x = tmp; } ... writeln( { int i = 5; writeln(i); foo(i); }); writeln(x);
May 15 2015