Re: Strange closure behaviour

2019-06-15 Thread Timon Gehr via Digitalmars-d-learn
On 15.06.19 18:29, Rémy Mouëza wrote: On Saturday, 15 June 2019 at 01:21:46 UTC, Emmanuelle wrote: On Saturday, 15 June 2019 at 00:30:43 UTC, Adam D. Ruppe wrote: On Saturday, 15 June 2019 at 00:24:52 UTC, Emmanuelle wrote: Is it a compiler bug? Yup, a very longstanding bug. You can work

Re: Using scanw Ncurses in D lang

2019-06-15 Thread ag0aep6g via Digitalmars-d-learn
On 15.06.19 23:20, Gabol wrote: example: scanw("% i", & number); // The compiler accuses error. Error: function deimos.ncurses.curses.scanw(char* fmt, ...) is not callable using argument types (string, int*) source/app.d(8,14):    cannot pass argument "0" of type string to parameter char*

Using scanw Ncurses in D lang

2019-06-15 Thread Gabol via Digitalmars-d-learn
how can I use the scanw() function; of the ncurses of the deimos.ncurses project since the conventional mode does not work example: scanw("% i", & number); // The compiler accuses error. Error: function deimos.ncurses.curses.scanw(char* fmt, ...) is not callable using argument types (string,

Re: Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread user1234 via Digitalmars-d-learn
On Saturday, 15 June 2019 at 17:42:04 UTC, ag0aep6g wrote: On Saturday, 15 June 2019 at 17:24:45 UTC, user1234 wrote: --- void foo(){writeln(__PRETTY_FUNCTION__);} void main(string[] args) { void delegate() dg; dg.funcptr = dg.ptr = null; // usually a "this" or a frame address

Re: Strange closure behaviour

2019-06-15 Thread Emmanuelle via Digitalmars-d-learn
On Saturday, 15 June 2019 at 16:29:29 UTC, Rémy Mouëza wrote: I don't know if we can tell this is a compiler bug. The same behavior happens in Python. The logic being variable `x` is captured by the closure. That closure's context will contain a pointer/reference to x. Whenever x is updated

Re: Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 15 June 2019 at 17:24:45 UTC, user1234 wrote: --- void foo(){writeln(__PRETTY_FUNCTION__);} void main(string[] args) { void delegate() dg; dg.funcptr = dg.ptr = null; // usually a "this" or a frame address dg(); } --- because dg.ptr would be used to retrieve the

Re: Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread user1234 via Digitalmars-d-learn
On Saturday, 15 June 2019 at 16:34:22 UTC, Robert M. Münch wrote: On 2019-06-15 16:19:23 +, Anonymouse said: By design, I think: "delegate and function objects cannot be mixed. But the standard function std.functional.toDelegate converts a function to a delegate." Your example compiles

Re: Strange closure behaviour

2019-06-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 15 June 2019 at 16:29:29 UTC, Rémy Mouëza wrote: I don't know if we can tell this is a compiler bug. I can't remember where the key fact was, but I used to agree with you (several languages work this same way, and it makes a lot of sense for ease of the implementation), but

Re: Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread Alex via Digitalmars-d-learn
On Saturday, 15 June 2019 at 16:34:22 UTC, Robert M. Münch wrote: On 2019-06-15 16:19:23 +, Anonymouse said: By design, I think: "delegate and function objects cannot be mixed. But the standard function std.functional.toDelegate converts a function to a delegate." Your example compiles

Re: Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-06-15 16:19:23 +, Anonymouse said: By design, I think: "delegate and function objects cannot be mixed. But the standard function std.functional.toDelegate converts a function to a delegate." Your example compiles if the assignment is changed to dg = toDelegate(); (given

Re: Strange closure behaviour

2019-06-15 Thread Rémy Mouëza via Digitalmars-d-learn
On Saturday, 15 June 2019 at 01:21:46 UTC, Emmanuelle wrote: On Saturday, 15 June 2019 at 00:30:43 UTC, Adam D. Ruppe wrote: On Saturday, 15 June 2019 at 00:24:52 UTC, Emmanuelle wrote: Is it a compiler bug? Yup, a very longstanding bug. You can work around it by wrapping it all in another

Re: Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread Anonymouse via Digitalmars-d-learn
On Saturday, 15 June 2019 at 15:54:00 UTC, Robert M. Münch wrote: Why does the follwing code give: Error: cannot implicitly convert expression & myFunc of type void function(int a) to void delegate(int) void myFunc(int a){return;} void main() { void delegate(int) dg; dg = } See:

Delegate / Error: cannot implicitly convert expression...

2019-06-15 Thread Robert M. Münch via Digitalmars-d-learn
Why does the follwing code give: Error: cannot implicitly convert expression & myFunc of type void function(int a) to void delegate(int) void myFunc(int a){return;} void main() { void delegate(int) dg; dg = } See: https://run.dlang.io/is/iTYo2L -- Robert M. Münch