Question: Huffman Coding with DocumentTools

I need to do Huffman Coding by using Document Tools thus i can produce user interface by using coding that referred in this post by Alec Mihailovs. Below is the coding and Document Tools interface:

Do(Freq = proc (message) options operator, arrow; map(proc (x) options operator, arrow; rhs(x) = lhs(x) end proc, {StringTools:-CharacterFrequencies(message)}) end proc);
Do(Fr = Freq(plaintext));
Do(HuffmanTree = proc (message) options operator, arrow; if nops(message) <= 1 then rhs(message[]) else procname(`union`(message[3 .. -1], {lhs(message[1])+lhs(message[2]) = [rhs(message[1]), rhs(message[2])]})) end if end proc);
Do(HT = HuffmanTree(Fr));
Do(HuffmanCoding = proc (message, r := "") if message::string then message = r else procname(message[1], cat(r, 0)), procname(message[2], cat(r, 1)) end if end proc);
Do(HD = HuffmanCoding(HT));
Do(C = table([HD]));
Do(HC = cat(map(proc (x) options operator, arrow; C[x] end proc, StringTools:-Explode(message))[])

It still can get result for first part of the coding.During execute the second part of the coding(as bolded), it produces error ,the error show below.So how should I modified so that the error won't pop out @Alec Mihaivols


Please Wait...