无法弄清楚为什么Erlang函数未定义

Can't figure out why Erlang function is undefined

我有一个函数,不断显示"功能代码/ 3未定义"错误。以下是该函数的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
table(Sample)->
Freq=freq(Sample),
Tree = huffman(lists:keysort(2, Freq)),
codes(Tree).

codes(Tree)->
    {_,_,X,_}=Tree, <---- Masks out a tuple
    {Y,_,_,_}=Tree, <----- Masks out an atom
    codes(X,Y,[]). <------ Here is where it gives error.

codes({},_,List)->List;
codes(Entry,Type,List)->
    case Type of
        leaf->
            NewList=[element(3,Entry)|List];
        node->
            Entry1=element(2,Entry),
            Entry2=element(2,Entry),
            codes(Entry1,element(1,Entry1),List),
            codes(Entry2,element(1,Entry2),List);
    end.

不知道为什么,有人知道吗?

编辑:问题是最后一个end之后的;,而不是现在已解决的.


即使其他人解决了这个问题,以下是来自erlang

的结构

1
2
3
4
5
6
7
case Expr of
    Pattern1 [when GuardSeq1] ->
        Body1;
        ...;
    PatternN [when GuardSeqN] ->
        BodyN
end