erl 编译之后报错,
我本意是:
showPerson/1 函数输出 用户信息,他的参数要么是 元祖 {Name, Age, Phone} 要么是 记录 -record (person, {name, age=0, phone=""}).
求指点,给个争取的实现方式。。。。
编译之后报错,信息如下:
[master●] » erl
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V7.0 (abort with ^G)
1> c(tuples1).
tuples1.erl:20: illegal guard expression
error
2>
元代码如下
-module (tuples1).
-export ([test/0, test1/0 ]).
-record (person, {name, age=0, phone=""}).
birthday({Name, Age, Phone}) ->
{Name, Age+1, Phone};
birthday(P) ->
#person{age=Age} = P,
P#person{age=Age+1}.
joe() ->
{"Joe", 21, "999-999"}.
showPerson(P) ->
case P of
{Name, Age, Phone} ->
io:format("name:~p age:~p phone:~p~n", [Name, Age, Phone]);
P1 when is_recode(P1, person) ->
io:format("name:~p age:~p phone:~p~n", [P1#person.name, P1#person.age, P1#person.phone])
end.
test() ->
P = #person{name="leeyi", age=18, phone="13692177080"},
showPerson(birthday(P)),
Tp = {P#person.name, P#person.age, P#person.phone},
showPerson(Tp),
showPerson(joe()).
test1() ->
showPerson(birthday(joe())).
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
第20行应该是
P1whenis_record(P1,person)->
既然只是一个拼写错误,让大家见笑了