Reputation: 107
I have a function that keeps giving me "function codes/3 undefined" error. Here is the code for the function:
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.
Can't figure out why, does anyone know?
EDIT: the problem was a ;
after the final end
rather than a .
, now fixed.
Upvotes: 1
Views: 1008
Reputation: 25
Even though someone else solved the question, below is the structure from the erlang
case Expr of
Pattern1 [when GuardSeq1] ->
Body1;
...;
PatternN [when GuardSeqN] ->
BodyN
end
Upvotes: 1