Re: Help the old man learn D
On Friday, 26 June 2015 at 17:11:54 UTC, Marc Schütz wrote: On Friday, 26 June 2015 at 16:57:14 UTC, Charles Hawkins wrote: [...] I don't fully understand what you're doing, but functions can easily be turned into delegates using std.functional.toDelegate [1]: import std.functional : toDelegate; registerDelegate((&topLevelFunction).toDelegate); [1] http://dlang.org/phobos/std_functional.html#.toDelegate Thanks, Marc. That should work if my brute force duplicate code doesn't. Thanks to everyone, at long last my project compiles with dmd. It crashes right away, but that's not unexpected since I haven't used pointers in several years. Unfortunately, compiling with gdc spits out a bunch of errors regarding getopt so I'm back to sprinkling log statements to find the problem.
Re: Help the old man learn D
On Friday, 26 June 2015 at 16:57:14 UTC, Charles Hawkins wrote: Sorry for talking to myself, but I'm hoping someone will help me out. The above idea doesn't work. It appears that only the main program file is going to have function pointers while modules and classes will have delegates. So, does a library that uses callbacks need 2 callback register functions as well as parallel storage mechanisms, or is there a fairly simple way to make it polymorphic? I was hoping a newbie would be able to use this library, but not many newbies are going to understand this. I suppose I could tell them to call registerFunction and if they get a compiler error, then call registerDelegate? Or am I missing something? I don't fully understand what you're doing, but functions can easily be turned into delegates using std.functional.toDelegate [1]: import std.functional : toDelegate; registerDelegate((&topLevelFunction).toDelegate); [1] http://dlang.org/phobos/std_functional.html#.toDelegate
Re: Help the old man learn D
On Friday, 26 June 2015 at 15:33:25 UTC, Charles Hawkins wrote: On Friday, 26 June 2015 at 14:52:51 UTC, Marc Schütz wrote: On Friday, 26 June 2015 at 14:39:05 UTC, Charles Hawkins wrote: [...] I think I've answered my own question regarding the callbacks as well. I realized that the only reason I made those sections of code classes in OCaml, even though there would only be one instance of them, was so I could do forward referencing. I'm hoping that I'll get function pointers instead of delegate pointers if I convert the class back to a module. Sorry for talking to myself, but I'm hoping someone will help me out. The above idea doesn't work. It appears that only the main program file is going to have function pointers while modules and classes will have delegates. So, does a library that uses callbacks need 2 callback register functions as well as parallel storage mechanisms, or is there a fairly simple way to make it polymorphic? I was hoping a newbie would be able to use this library, but not many newbies are going to understand this. I suppose I could tell them to call registerFunction and if they get a compiler error, then call registerDelegate? Or am I missing something?
Re: Help the old man learn D
On Friday, 26 June 2015 at 14:52:51 UTC, Marc Schütz wrote: On Friday, 26 June 2015 at 14:39:05 UTC, Charles Hawkins wrote: Thanks. I've changed to thread topic to "Help the old man learn D". :) logger package allows those statements to compile with gdc although I'm now getting lots of errors saying "undefined identifier format" even though I'm importing std.format, I believe the `format` method used to be in `std.string` a few releases ago, try importing that one. Thank you! That explains why it wasn't flagging all of them since some of my modules import std.string as well. I think I've answered my own question regarding the callbacks as well. I realized that the only reason I made those sections of code classes in OCaml, even though there would only be one instance of them, was so I could do forward referencing. I'm hoping that I'll get function pointers instead of delegate pointers if I convert the class back to a module.
Re: Help the old man learn D
On Friday, 26 June 2015 at 14:39:05 UTC, Charles Hawkins wrote: Thanks. I've changed to thread topic to "Help the old man learn D". :) logger package allows those statements to compile with gdc although I'm now getting lots of errors saying "undefined identifier format" even though I'm importing std.format, I believe the `format` method used to be in `std.string` a few releases ago, try importing that one.
Help the old man learn D
On Wednesday, 24 June 2015 at 16:21:47 UTC, weaselcat wrote: On Wednesday, 24 June 2015 at 07:52:10 UTC, Charles Hawkins wrote: On Wednesday, 24 June 2015 at 06:54:57 UTC, weaselcat wrote: On Tuesday, 23 June 2015 at 06:50:28 UTC, Charles Hawkins wrote: [...] you can instruct dub to use other compilers with the --compiler option valid options include dmd,ldc,gdc,gdmd,ldmd [...] Is there a quick way to get gdc to recognize std.experimental.logger? I'm already spoiled by it. Choosing between it and a backtrace is difficult. I believe it's available as a dub package albeit outdated, should be roughly similar though. Thanks. I've changed to thread topic to "Help the old man learn D". :) logger package allows those statements to compile with gdc although I'm now getting lots of errors saying "undefined identifier format" even though I'm importing std.format, but not all of them are being flagged. Once I get it to where those are the only errors, perhaps I can figure it out. I'm converting one of my OCaml programs and I have a class (call it Dispatcher) that uses callbacks. With OCaml, it didn't matter if the callbacks were functions or methods but apparently D makes a distinction, which I can understand. I guess this is an opinion question, but should I duplicate Dispatcher's register functions and data structures to handle both, or do I define global functions that call the called-back methods (there's only one instance of the called-back class) and pass those to Dispatcher? Or is there a better way?