얼랭에서 함수 호출은 다음과 같은 형태를 갖는다
- %% module_name:function(argument1, argument2, ...)
- > lists:max([1, 2, 3]).
모듈의 모든 함수를 export 시킨다
- -compile([export_all]).
사용자 정의 속성을 정의할 수 있다
- -author("V. Trigonakis").
- -date({2011, 03, 11}).
- -module(md).
- -export([same/1, double/1]).
- -author("V. Trigonakis").
- -date({2011, 03, 11}).
-
- same(l) ->
- l.
-
- double(N) ->
- 2 * N.
-
- not_exported() ->
- same(smthing),
- double(123).
얼랭 에뮬레이터에서 코드를 컴파일 하기 위해서는 BIF 중 c(module_name)를 사용한다
- 1> c(md).
- {ok, md}
컴파일 과정에서 오류가 발생하지 않았다면 .beam 파일이 생성되었을 것이다
Erlang Compiler
- $ erlc md.erl
- $ ls
- md.beam md.erl
컴파일된 모듈은 다음과 같은 형태로 로딩할 수 있다
- 1> l(md).
- {module, md}.
모든 컴파일된 모듈은 module_info/0, module_info/1 함수를 통하여 해당 모듈의 속성을 가져올 수 있다
- 1> erlang:module_loaded(md).
- false
- 2> l(md).
- {module,md}
- 3> erlang:module_loaded(md).
- true
- 4> md:module_info().
- [{exports,[{same,1},
- {double,1},
- {module_info,0},
- {module_info,1}]},
- {imports,[]},
- {attributes,[{vsn,[205824271517095806442935620583334286333]},
- {author,"Vasileios Trigonakis"},
- {date,[{2011,3,13}]}]},
- {compile,[{options,[{cwd,"~/Documents/playing/erlang/post_modules"},
- {outdir,"~/Documents/playing/erlang/post_modules"}]},
- {version,"4.6.4"},
- {time,{2011,3,14,7,54,12}},
- {source,"~/Documents/playing/erlang/post_modules/md.erl"}]}]
- 5> md:module_info(attributes).
- [{vsn,[205824271517095806442935620583334286333]},
- {author,"Vasileios Trigonakis"},
- {date,[{2011,3,13}]}]