[erlang-questions] Specs for optional callbacks (try 2)

Ulf Wiger ulf@REDACTED
Sun Sep 28 10:47:41 CEST 2014


The most backwards-compatible way to do this would surely be:

behaviour_info(callbacks) ->
    [{foo, 2}, {bar, 4}];
behaviour_info(optional_callbacks) ->
    [{bar, 3}, {boo, 14}];
behaviour_info(_) ->
   undefined.

Presumably, having behaviour_info/1 together with -callback specs was disallowed because the compiler would have to check consistency between them, and to partial evaluation of the behaviour_info/1 code?

In this respect, -callbacks/1 and -optional_callbacks/1 are better since they can be understood directly after parsing. But they introduce some uncertainties:

- are multiple -callbacks/1 attributes allowed? If not explicitly disallowed, they would have to be unioned together.
- should the compiler produce a default -callbacks/1 directive including all specified callbacks? (except for those represented in -optional_callbacks/1?)

I think the most consistent and clear alternative is to introduce -optional_callback specs, given the path we’re already on.

BR,
Ulf W

On 28 Sep 2014, at 09:11, Robert Virding <rvirding@REDACTED> wrote:

> Just to throw something completely different and definitely not backwards compatible I would prefer something like:
> 
> -callback([foo/2,bar/4]).
> -optional_callback([bar/3,boo/14]).
> 
> foo(...) -> ... .
> bar(...) -> ... .
> baz(...) -> ... .
> boo(...) -> ... .
> 
> This because it mirrors how -export(). behaves and does not push the information down into the actual definition. I think not seeing it at the start of the module is a bad option as it means I have to step down into the module to see what it exports and, in this case, what are the callbacks. You have to delve down into the module to find this "global" information. I find it very annoying with languages that do this, which is why I purposely followed erlang when doing LFE.
> 
> Yes, I know it is too late to change it. Is it? Maybe a parse transform to get it right?
> 
> Robert
> 
> 
> On 25 September 2014 05:38, Loïc Hoguin <essen@REDACTED> wrote:
> On 09/25/2014 03:01 PM, Hans Bolinder wrote:
> [Loïc Hoguin:]
> I didn't get any reply on my previous question almost 2 years ago here:
> http://erlang.org/pipermail/erlang-questions/2013-January/071763.html
> 
> I missed your original question, otherwise I would have replied to it.
> 
> No worries. :)
> 
> There is an implementation in Erlang/OTP 18, see commit 683a293, using
> the second syntax suggested by Kostis, -optional_callbacks/1.
> 
> Woot!
> 
> This looks great. I guess I'll just have to wait now and play with it a few weeks before 18 gets released.
> 
> Thanks for the heads up!
> 
> -- 
> Loïc Hoguin
> http://ninenines.eu
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140928/c5d5d491/attachment.htm>


More information about the erlang-questions mailing list