“头部不匹配”是什么意思?编译器错误是什么意思?
我尝试编写代码来打印 Z 字符。
zzzzzzz
z
z
z
z
z
zzzzzzz
但是当我编译这段代码时,它抛出了
D:\erlang\graphics>erlc zeez2.erl
d:/erlang/graphics/zeez2.erl:19: head mismatch
d:/erlang/graphics/zeez2.erl:6: function zeez/3 undefined
I can't fix this 错误。我没有发现我的能力有什么问题。
有没有人请推荐我一下。
谢谢。
-module(zeez2).
-export([main/0]).
main() ->
L = 8,
zeez( false ,1, L). % line 6
zeez(true, M,M) ->
init:stop();
zeez(false, M, N) ->
io:format("~p~n", [zeez(z, N-M)] ),
zeez(M rem N =:= 0, M + 1, N );
zeez(true, M, N) ->
io:format("~p~n", [zeez(space, N-M)] ), % line 16
zeez(M rem N =:= 0, M + 1 , N );
zeez(space, M) ->
io:format("~p~n", ["-" ++ zeez(space, M-1)] );
zeez(space, 0) ->
"Z";
zeez(z, M) ->
io:format("~p~n", ["Z" ++ zeez(z, M-1)] );
zeez(z,0) ->
"Z".
I tries to write code to print Z character.
zzzzzzz
z
z
z
z
z
zzzzzzz
But when I compile this code, it throws
D:\erlang\graphics>erlc zeez2.erl
d:/erlang/graphics/zeez2.erl:19: head mismatch
d:/erlang/graphics/zeez2.erl:6: function zeez/3 undefined
I can't fixed this error. I didn't find what wrong in my could.
Does one please suggest me.
Thank you.
-module(zeez2).
-export([main/0]).
main() ->
L = 8,
zeez( false ,1, L). % line 6
zeez(true, M,M) ->
init:stop();
zeez(false, M, N) ->
io:format("~p~n", [zeez(z, N-M)] ),
zeez(M rem N =:= 0, M + 1, N );
zeez(true, M, N) ->
io:format("~p~n", [zeez(space, N-M)] ), % line 16
zeez(M rem N =:= 0, M + 1 , N );
zeez(space, M) ->
io:format("~p~n", ["-" ++ zeez(space, M-1)] );
zeez(space, 0) ->
"Z";
zeez(z, M) ->
io:format("~p~n", ["Z" ++ zeez(z, M-1)] );
zeez(z,0) ->
"Z".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是你混淆了 2 个函数:
zeez/2 和 zeez/3
如果你通过以句号而不是分号结束 zeez/3 函数来终止它,它应该编译:
错误消息的意思是,'嘿我“在 zeez/3 中,你添加了一个 2 元数子句,wtf?”
the problem is that you have mixed up 2 functions:
zeez/2 and zeez/3
If you terminate the zeez/3 function by ending it with a full stop not a semi-colon it should compile:
The error message means, 'hey I'm in zeez/3 and you have thrown in a 2-arity clause, wtf?'
您尝试定义两个函数,第一个具有 3 个参数 (zeez/3),另一个具有 2 个参数 (zeez/2)。头不匹配错误是因为上一行的 zeez/3 函数应该以“.”结尾。
即,因为您已经用“;”结束了前一个 zeez/3 函数,所以它期望以下声明是 zeez/3 的另一个匹配项:
您还应该注意,编译器将向您发出有关“...前一个子句”的警告由于 zees(space, 0) 和 zeez(space, M) 的顺序,第 xxx 行始终匹配”。您应该将 zees(space, 0) 放在 zeez(space, M) 之前,因为它更具体。
You're trying to define two functions, the first with 3 parameters (zeez/3) and another with 2 parameters (zeez/2). The head mismatch error is because the zeez/3 function on the previous line should be terminated with a '.'.
I.e. because you've ended the previous zeez/3 function with a ';', it expects the following declaration to be another match for zeez/3:
You should also note that the compiler will give you warnings about "... previous clause at line xxx always matches" because of the ordering of zees(space, 0) and zeez(space, M). You should put zees(space, 0) before zeez(space, M), because it is more specific.