这个标题的内容就简单多了,直接看用例吧,仍然以 helloworld.erl模块为例。
函数:
函数:
%% This is a simple Erlang module
% Test ...
-module(helloworld).
-export([pie/0, print/1]).
pie() ->
3.14
.
print(Msg) ->
io:format("The Message is ~p.~n",[Msg]) %~p 表示以美化的方式打印Erlang项式,~n 表示插入一个换行符, ~w 表示打印Erlang字符串
函数子句:
-module(helloworld).
-export([area/1, either_or_both/2]).
% “_” 表示省略模式
either_or_both(true, _) ->
true;
either_or_both(_, true) ->
false;
either_or_both(false, false) ->
false;
area({a, X, Y}) ->
io:format("a, X, Y: ~p, ~p, ~p.~n", [a, X, Y]);
area({b, X, Y}) ->
io:format("b, X, Y: ~p, ~p, ~p.~n", [b, X, Y]).
%编译:
c(helloworld

本文探讨Erlang编程基础,重点在于函数的使用和子句保护式的概念。通过详细解释函数的不同子句以及子句保护式如何确保程序的正确执行,帮助开发者更好地掌握Erlang语言的核心特性。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



