Alternatives to extern(delegate) (DIP 1011)

Jonathan Marler johnnymarler at gmail.com
Mon Oct 2 07:48:54 UTC 2017


Andrei suggests we take a closer look at alternatives to DIP 1011 
(extern(delegate)) that can be implemented in a library.  In the 
past I've failed to come up with anything good, however, my last 
attempt seemed to be less horrible than before.  I'm inviting 
anyone to view/modify my feeble attempt at a solution here 
https://github.com/marler8997/externdelegate

A good library solution would be great but my current solution 
has problems.  It doesn't really support template parameters yet 
and I'm not sure if it can be solved in the general case without 
pulling in a fair chunk of the language grammar into the library. 
Assuming that can be fixed, the bigger concern is that the API to 
define a "delegate function" looks very awkward.  It provides a 
template mixin that you can use to create a delegate function by 
passing in your function definition as a string.

With the current solution I believe its very unlikely that 
applications would use the library. Keep in mind that this 
feature is something that a library could use on most or all of 
it's functions.  If it has to use such an awkward syntax it's 
highly unlikely it would be used at that scale.  Not to mention 
that when you start pushing the limits of the language like this 
you almost always run into bugs and end up having to go with a 
different solution.  Also I haven't measured it but I'm almost 
certain this would greatly increase compile time as more 
functions start using it.



More information about the Digitalmars-d mailing list