Debuging Part 2
After having debugged the program, the new program is shown below. I followed a programming pattern with the first program, but that pattern did not the follow the algorithm I had in mind. What I wanted to do was to print the first letter encountered in the list. the previous program printed the last letter. It is interested how debugging to bring that out. And I used the helper function called compress.2.run with two inputs to solve. The technique is worth remembering. I think this is related to another technique of scanning the list twice(ie simumlation of 2 for loops, more on that later).
to compress.2.run :list :item ifelse emptyp :list [output :list] [ifelse equalp :item first :list [output compress.2.run butfirst :list :item] [output sentence first :list compress.2.run butfirst :list first :list]] end to compress.2 :list output compress.2.run :list [] end show compress.2 [a a a a b c c a a d d e e e e]
Comments