New library: open multi-methods
Jean-Louis Leroy via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Tue Jul 18 12:02:11 PDT 2017
On Tuesday, 18 July 2017 at 18:21:21 UTC, Ali Çehreli wrote:
> That reminds me: Would the following be possible and better?
>
> // From
> void main()
> {
> updateMethods();
> // ...
> }
>
> // To
> mixin(constructMethods());
> void main()
> {
> // ...
> }
>
> constructMethods() could return the following string:
>
> string constructMethods() {
> return q{
> shared static this() { updateMethods(); }
> };
> }
>
> If I'm not missing something, this is better because nothing
> needs to be added to main and the methods are available before
> main starts executing (module initialization order issues still
> apply.).
Ah, I would love to get rid of that call in main(), but think
beyond a one module program. The matrix example
(https://github.com/jll63/methods.d/tree/master/examples/matrix/source) consists in three separate modules, plus an app, all defining specializations. They need the mixin, but if we put updateMehods() in there, it will be called many times. And it is a costly operation. Guarding the call with a flag will not work, because more methods may be registered afterwards. Unless you can think of a way the last mixin can detect it's the last?
Incidentally, in yomm11 that function (it's called initialize())
has to be called before any method is called, after any shared
object/DLL is loaded and after a DLL is unloaded. I still have to
write the code to de-register the methods and the specializations
in that case by the way...
J-L
J-L
More information about the Digitalmars-d-announce
mailing list