<spanclass="synComment">;; P10 (*) Run-length encoding of a list.</span>
<spanclass="synComment">;; Use the result of problem P09 to implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as lists (N E) where N is the number of duplicates of the element E.</span>
<spanclass="synComment">;; Example:</span>
<spanclass="synComment">;; * (encode '(a a a a b c c a a d e e e e))</span>
<spanclass="synComment">;; ((4 A) (1 B) (2 C) (2 A) (1 D)(4 E))</span>
<spanclass="synSpecial">(</span>define <spanclass="synSpecial">(</span>pack-seed front sublist result l<spanclass="synSpecial">)</span>
[<spanclass="synSpecial">(</span><spanclass="synStatement">null</span>? l<spanclass="synSpecial">)</span><spanclass="synSpecial">(</span><spanclass="synStatement">append</span> result <spanclass="synSpecial">(</span><spanclass="synStatement">list</span> sublist<spanclass="synSpecial">))</span>]
[<spanclass="synSpecial">(</span><spanclass="synStatement">eq</span>? front <spanclass="synSpecial">(</span><spanclass="synStatement">car</span> l<spanclass="synSpecial">))</span><spanclass="synSpecial">(</span>pack-seed front
<spanclass="synSpecial">(</span><spanclass="synStatement">append</span> result <spanclass="synSpecial">(</span><spanclass="synStatement">list</span> sublist<spanclass="synSpecial">)))</span>
<spanclass="synSpecial">(</span><spanclass="synStatement">append</span> result <spanclass="synSpecial">(</span><spanclass="synStatement">list</span> sublist<spanclass="synSpecial">)))</span>