What does the “head mismatch” compiler error mean?

后端 未结 2 1043
遇见更好的自我
遇见更好的自我 2021-02-18 23:40

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         


        
2条回答
  •  醉梦人生
    2021-02-19 00:28

    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:

    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)] );
    

    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.

提交回复
热议问题