## 模块属性
```erlang
-module(modname).
-import(...).
-export(...).
-compile(Options).
-compile(export_all)%属性经常被使用在调试程序中。
-compile( {parse_transform, Module} ).
-vsn(Version).
%最后一个选项为增加编译选项,Options可以是单个选项或者选项列表。
-vsn(Version).%中的Version可以是任意字符条目。
```
vim attrs.erl
```erlang
-module(attrs).
-vsn(1234).
-author({joe,armstrong}).
-purpose("example of attributes").
-export( [fac/1]).
-type player_id() :: neg_integer().
-callback fun( PlayerId::player_id() ) -> boolean().
fac(1) -> 1;
fac(N) -> N*fac(N一1).
```
```erlang
$ erlc attrs.erl
$ erl -pa ./
1> attrs:module_info().
[{exports,[{fac,1},{rnodul a_ info,0},{rnodul e_i nfo,1}]},
{imports,[]},
{attributes,[{vsn,[1234]},
{author,[{joe,armstrong}]},
{purpose,"example of attributes"}]},
{compile,[{options,[{cwd,"/home/joe/2006/book/JAERLANG/Book/code"},
{outdir,"/home/joe/2006/book/JAERLANG/Book/code"}]},
{version,"4.4.3"},
{time,{2007,2,21,19,23,48}},
{source,"/home/joe/2006/book/JAERLANG/Book/code/attrs.erl"}]}]
2> attrs:module_info(attributes).
[{vsn,[1234]},{author,[{joe,armstrong}]},{purpose,"example of attributes"}]
3> beam_ lib:chunks("attrs.beam",[attributes]),
{ok,{attrs,[{attributes,[{author,[{joe,armstrong}]},
{purpose,"example of attributes"},
{vsn,[1234]}]}]}}
```
* * * * *
## 类型标注
```erlang
-type tuplelist() -> [tuple()].
-spec fun( integer() ) -> [] | {integer(), TupleList} when TupleList :: [Tuple], Tuple::term().
```
http://www.erlang.org/doc/reference_manual/typespec.html
类型标注后可以只用工具dialyzer来进行分析
* * * * *
## 行为回调函数
例如:
a.erl
```erlang
-type player_id() :: neg_integer().
-callback fun( PlayerId::player_id() ) -> boolean().%必须要在具体函数上面
```
b.erl
```erlang
-behaviour(a).
-export( fun/1 ).
fun(PlayerId) ->
io:format( "PlayerId:~p~n", [ PlayerId ] ).
```
* * * * *
## Erlang继承
```erlang
-extends(alpha).
alpha.erl
-module(alpha).
-export([c/2, b/1, a/0]).
a() ->{this_is_module,?MODULE}.
b(S) ->{this_is_module,?MODULE,S}.
c(S,T)->{this_is_module,?MODULE,S,T}.
beta.erl
-module(beta).
-compile(export_all).
-extends(alpha).
show() -> {hello_world,?MODULE,?BASE_MODULE}.
a() ->{hello,?MODULE}.
```
* * * * *

- 1.学习
- 1.1安装与运行环境
- 1.2编辑器、集成开发环境与其它工具
- 1.3代码编译运行
- 2.基础
- 2.1 Erlang终端
- 2.2 基础语法
- 2.2.1 异常处理
- 2.3 数据类型
- 2.4 操作符
- 2.5 模块属性
- 3.库函数
- 3.1 常用模块
- 3.2 OTP模块
- 3.2.1 函数
- 3.2.2 receive
- 3.2.3 .app.src文件
- 3.2.4 _app.erl
- 3.2.5 _sup.erl
- 3.2.6 gen_server
- 3.2.7 gen_fsm
- 3.3 erts
- 3.3.1 init
- 3.3.2 BIF
- 3.3.3 NIF
- 3.4 kernel
- 3.4.1 code_server
- 3.4.2 inet
- 3.4.3 net_kernel
- 3.4.4 net_adm
- 3.4.5 error_logger
- 3.4.6 global
- 3.4.7 application
- 3.5 stdlib
- 3.5.2 array
- 3.5.4 base64
- 3.5.5 binary
- 3.5.6 c
- 3.5.8 calendar
- 3.5.9 code
- 3.5.11 dict
- 3.5.12 erl_
- 3.5.13 file
- 3.5.14 filelib
- 3.5.15 gb_trees
- 3.5.16 gb_sets
- 3.5.17 gen_tcp
- 3.5.18 gen_server
- 3.5.19 httpc
- 3.5.20 init_parse
- 3.5.21 init
- 3.5.22 inet
- 3.5.23 io
- 3.5.24 lists
- 3.5.25 maps
- 3.5.26 os
- 3.5.27 ordsets
- 3.5.28 proplists
- 3.5.29 queue
- 3.5.30 qlc
- 3.5.31 re
- 3.5.32 random
- 3.5.33 rfc4627-json
- 3.5.34 string
- 3.5.35 ssh
- 3.5.36 soft
- 3.5.37 sets
- 3.5.38 supervisor
- 3.5.39 tuple
- 3.5.40 timer
- 3.5.41 unicode
- 3.5.42 cpu
- 3.5.43 math
- 3.5.44 zip
- 3.5.45 shell
- 3.6 SASL
- 3.7 asn1
- 3.8 compiler
- 3.9 tools
- 3.10 OS_Mon
- 3.11 crypto
- 3.12 Port
- 4.工具
- 4.1 Erlang预处理器
- 4.2 Erlang节点
- 4.3 Erlang多节点
- 4.3.1主从节点
- 4.4 Epmd
- 4.5 断点工具
- 4.6 dialyzer
- 4.7 dbg-debug 模块
- 4.7.1 dbg
- 4.8 Erlang跟踪工具
- 4.9 etop
- 4.10 profiling
- 4.10.1 fprof
- 4.10.2 eprof
- 4.10.3 cprof
- 5.进阶
- 5.1 TCP粘包、大小端
- 5.2 rebar发布系统
- 5.3 ErlangVM 心跳
- 5.4 Erlang GC
- 5.5 Erlang Time
- 5.6 Erlang 启动
- 5.6.1 SASL配置
- 5.7 Erlang系统限制
- 6.项目
- 6.1 the_seed
- 6.2 network
- 6.3 parse_tool
- 6.4 cache
- 7.项目研究
- 7.1 Mnesia
- 7.1.1 Mnesia模式
- 7.1.2 Mnesia操作
- 7.1.3 Mnesia增删改查
- 7.1.4 Mnesia过载分析
- 7.1.5 Mnesia高级特性
- 7.1.6 分布式
- 7.1.7 Mnesia表分片
- 7.1.8 Mnesia锁
- 7.1.9 dets
- 7.1.10 ets
- 7.2 Ejabberd
- 7.2.1 mod_echo.erl
- 7.2.2 hooks for module developers
- 7.2.3 Events list
- 7.3 cowboy
- 7.4 rebar
- 7.4.1 rebar Wiki
- 7.4.2 rebar.config.script
- 7.5 RIAK CS
- 7.6 Leofs
- 7.6.1 简介
- 8.资料整理
- 8.1 资料
- 8.1.1 Erlang的调度原理
- 8.1.2 虚拟机代码执行原理
- 8.1.3 SMP
- 8.2 杂记
- 8.2.1 设计