Thread overview
Problem with trying sample from doc page
Jul 16, 2014
Pavel
Jul 16, 2014
Pavel
Jul 16, 2014
Adam D. Ruppe
Jul 16, 2014
Brad Anderson
July 16, 2014
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?



July 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
July 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...
July 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