/* part2.rex (for cs60 hw1, S09) Name: Comments to the graders: */ // pr: #8 // fun: uniq( L ) // in: any list, L // out: that list, with later-appearing top-level duplicate elements removed uniq( [] ) => []; uniq( [f|R] ) => [f|removeAll(f,uniq(R))]; removeAll( e, [] ) => []; removeAll( e, [e|R] ) => removeAll( e, R ); removeAll( e, [f|R] ) => [f|removeAll( e, R )]; test( uniq( [1,2,3,1] ), [1,2,3] ); test( uniq( [1,1,2,1,1,2,1,2,3,2,1,3] ), [1,2,3] ); // problem #9 // removeAll rmvAll( e, [] ) => []; rmvAll( e, [e|R] ) => rmvAll(R); // pr: #10 wordScore // fun: letterScore( let ) // in: a character, let // out: the scrabble score for that character, // or 0 if let is not in the scrabbleScore dictionary *i scrabbleScores.rex letterScore( let ) => value = assoc( let, scrabbleScores ), value ? second(value) : 0; test( letterScore( 'a' ), 1 ); test( letterScore( 'b' ), 3 ); test( letterScore( ' ' ), 0 ); test( letterScore( 'A' ), 0 ); test( letterScore( 42 ), 0 ); rmvAll( e, [f|R] ) => [f|rmvAll(e,R)]; // fun: scoreWord( w ) // in: a string, w // out: the scrabble score for that string scoreWord( w ) => type(w) == "string" ? scoreWord( explode(w) ); scoreWord( [] ) => 0; scoreWord( [f|R] ) => letterScore(f) + scoreWord(R); test( scoreWord( "zap" ), 14 ); test( scoreWord( "zzz" ), 30 ); test( scoreWord( "aah" ), 6 ); test( scoreWord( "twelve" ), 12 ); test( scoreWord( "fortytwo" ), 17 ); rmv1( e, [] ) => []; rmv1( e, [e|R] ) => R; rmv1( e, [f|R] ) => [f|rmv1(e,R)]; // extra credit omitted (it's part of this week's hw!