c(tuples1). tuples1.erl:20: illegal guard expression

leeyi 发布于 2015/10/12 09:09
阅读 499
收藏 0

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())).






加载中
0
leeyi
leeyi

第20行应该是 

P1 when is_record(P1, person) ->

既然只是一个拼写错误,让大家见笑了

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部