From 9dfc9857ff5089282f97656fe59012c26ccae52a Mon Sep 17 00:00:00 2001
From: Hans Bolinder
Date: Tue, 25 Mar 2014 14:08:30 +0100
Subject: refman: Clarify the '-callback' attribute
---
system/doc/design_principles/spec_proc.xml | 16 ++++++++--------
system/doc/reference_manual/modules.xml | 19 ++++++++++++++++---
2 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/system/doc/design_principles/spec_proc.xml b/system/doc/design_principles/spec_proc.xml
index 69bf2e0448..e4fb5fdca7 100644
--- a/system/doc/design_principles/spec_proc.xml
+++ b/system/doc/design_principles/spec_proc.xml
@@ -4,7 +4,7 @@
- 19972013
+ 19972014
Ericsson AB. All Rights Reserved.
@@ -431,11 +431,11 @@ loop(...) ->
User-Defined Behaviours
- To implement a user-defined behaviour, write code similar to
+
To implement a user-defined behaviour, write code similar to
code for a special process but calling functions in a callback
module for handling specific tasks.
If it is desired that the compiler should warn for missing callback
- functions, as it does for the OTP behaviours, add callback attributes in the
+ functions, as it does for the OTP behaviours, add -callback attributes in the
behaviour module to describe the expected callbacks:
-callback Name1(Arg1_1, Arg1_2, ..., Arg1_N1) -> Res1.
@@ -445,15 +445,15 @@ loop(...) ->
where NameX are the names of the expected callbacks and
ArgX_Y, ResX are types as they are described in Specifications
for functions in Types and
- Function Specifications. The whole syntax of spec attributes is
- supported by callback attributes.
+ Function Specifications. The whole syntax of -spec attribute is
+ supported by -callback attribute.
Alternatively you may directly implement and export the function:
behaviour_info(callbacks) ->
- [{Name1,Arity1},...,{NameN,ArityN}].
- where each {Name,Arity} specifies the name and arity of a callback
+ [{Name1, Arity1},...,{NameN, ArityN}].
+
where each {Name, Arity} specifies the name and arity of a callback
function. This function is otherwise automatically generated by the compiler
- using the callback attributes.
+ using the -callback attributes.
When the compiler encounters the module attribute
-behaviour(Behaviour). in a module Mod, it will call
Behaviour:behaviour_info(callbacks) and compare the result with the
diff --git a/system/doc/reference_manual/modules.xml b/system/doc/reference_manual/modules.xml
index 9e5f4de385..cd4c3a1b1b 100644
--- a/system/doc/reference_manual/modules.xml
+++ b/system/doc/reference_manual/modules.xml
@@ -4,7 +4,7 @@
- 20032013
+ 20032014
Ericsson AB. All Rights Reserved.
@@ -134,8 +134,21 @@ fact(0) -> % |
standard behaviours gen_server, gen_fsm,
gen_event or supervisor.
The spelling behavior is also accepted.
- Read more about behaviours and callback modules in OTP Design
- Principles.
+ The callback functions of the module can be specified either
+ directly by the exported function behaviour_info/1:
+
+behaviour_info(callbacks) -> Callbacks.
+ or by a -callback attribute for each callback
+ function:
+
+-callback Name(Arguments) -> Result.
+ where Arguments is a list of zero or more arguments.
+ The -callback attribute is to be preferred since the
+ extra type information can be used by tools to produce
+ documentation or find discrepancies.
+ Read more about behaviours and callback modules in
+
+ OTP Design Principles.