I have a module that is being used. The purpose of the module is to provide some default functions that can be overridden. I am use __before_compile__ to ensure there is a catch-all function at the end of the module with the lowest precedence.
However, in the consuming module if I override the catch-all with a custom catch-all I get the expected warning:
warning: this clause cannot match because a previous clause at line N always matches
defoverridable doesn’t work here because technically it isn’t being overriden. Is there any way to avoid this warning?
One thought I had, but I don’t think it is possible, is at compile-time in __before_compile__ if I had a way to detect if the catch-all function was already defined I would just not define in __before_compile__
I am not actually sure this will work; doesn’t use add code to the module that is being compiled, and as such isn’t the new code added before we have any idea about what functions the user will add to the module?
Using defoverridable here would ‘work’, but also mean that the earlier versions of your functions (the non-catch-all variants) would be overridden.
This is a very interesting problem, @bcardarella. I also would love to hear a solution for this.
True, not at that point, however you can do things like redefine def’s, use __before_compile__ to inject things based on usage, etc… I’ve done that quite a few times… >.>
Yep, but he could put in the ‘default’ versions at the place of ‘use’ with defoverridable, then the user can override ‘some’ of them, then can inject more functions at the end to call the super’s and handle non-handled cases that the user did not handle so as it add in the default states.
Oh yes, more like playing with bombs! If you just need to define attributes or so you could do the __on_definition__ or whatever it is called to build things up, but I tend to do… bigger things to def/defp… ^.^
I’ve gotten lucky with not hitting anything really odd yet, but eh… We need a strong statically typed system, badly. ^.^