www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Problem with trying sample from doc page

reply "Pavel" <noemail noplace.net> writes:
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
next sibling parent "Pavel" <noemail noplace.net> writes:
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
prev sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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
parent "Brad Anderson" <eco gnuk.net> writes:
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