digitalmars.D.learn - Problem with trying sample from doc page
- Pavel (20/20) Jul 16 2014 Hi! I've been experimenting with D functions, and found this
- Pavel (2/23) Jul 16 2014 Link to the doc is: http://dlang.org/expression#FunctionLiteral
- Adam D. Ruppe (4/4) Jul 16 2014 I would just change all the longs to ints and it would probably
- Brad Anderson (2/6) Jul 16 2014 https://github.com/D-Programming-Language/dlang.org/pull/615
Hi! I've been experimenting with D functions, and found this piece of code: // int abc(int delegate(long i)); int def(int function(long s)); void test() { int b = 3; abc( (long c) { return 6 + b; } ); // inferred to delegate def( (long c) { return c * 2; } ); // inferred to function } // On linux machine with [DMD64 D Compiler v2.065] it doesn't compile, giving me this error: test.d(10): Error: function test.def (int function(long s)) is not callable using argument types (long function(long c) pure nothrow safe) Here DMD infers (long c) { return c * 2; } as long function(long c). And "def" definition doesn't match. Is that an error in the docs, or mayber I'm doing something wrong?
Jul 16 2014
On Wednesday, 16 July 2014 at 15:12:58 UTC, Pavel wrote:Hi! I've been experimenting with D functions, and found this piece of code: // int abc(int delegate(long i)); int def(int function(long s)); void test() { int b = 3; abc( (long c) { return 6 + b; } ); // inferred to delegate def( (long c) { return c * 2; } ); // inferred to function } // On linux machine with [DMD64 D Compiler v2.065] it doesn't compile, giving me this error: test.d(10): Error: function test.def (int function(long s)) is not callable using argument types (long function(long c) pure nothrow safe) Here DMD infers (long c) { return c * 2; } as long function(long c). And "def" definition doesn't match. Is that an error in the docs, or mayber I'm doing something wrong?Link to the doc is: http://dlang.org/expression#FunctionLiteral
Jul 16 2014
I would just change all the longs to ints and it would probably work. Or all the longs to ints. It really should have been consistent in the docs, since the point of this is delegate vs function, not int vs long...
Jul 16 2014
On Wednesday, 16 July 2014 at 15:44:03 UTC, Adam D. Ruppe wrote:I would just change all the longs to ints and it would probably work. Or all the longs to ints. It really should have been consistent in the docs, since the point of this is delegate vs function, not int vs long...https://github.com/D-Programming-Language/dlang.org/pull/615
Jul 16 2014