开发者社区> 问答> 正文

c(tuples1). tuples1.erl:20: illegal guar?报错

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






展开
收起
爱吃鱼的程序员 2020-06-12 10:47:18 463 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    第20行应该是 

    P1whenis_record(P1,person)->

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

    2020-06-12 10:47:35
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Lambda Processing for Near Time Search Indexing 立即下载
Stream Processing takes on Everything 立即下载
Towards A Fault-Tolerant Speaker Verification System: A Regularization Approach To Reduce The Condition Number 立即下载