Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
fp:homework02-draft [2022/03/31 13:25] pdmatei |
fp:homework02-draft [2022/03/31 13:38] (current) pdmatei |
||
---|---|---|---|
Line 50: | Line 50: | ||
===== Implementation ===== | ===== Implementation ===== | ||
- | **1.** Write a function which splits a text using the single whitespace character as a separator. Multiple whitespaces should be treated as a single separator. If the list contains only whitespaces, ''split'' should return the empty list. (Hints: Your implementation must be recursive, but do not try to make it tail-recursive. It will make your code unnecessarily complicated. Several patterns over lists, in the proper order will make the implementation cleaner.) | + | **1.** Write a function which splits a text using the single whitespace character as a separator. Multiple whitespaces should be treated as a single separator. If the list contains only whitespaces, ''split'' should return the empty list. (//Hints: Your implementation must be recursive, but do not try to make it tail-recursive. It will make your code unnecessarily complicated. Several patterns over lists, in the proper order will make the implementation cleaner.//) |
<code scala> | <code scala> | ||
/* split(List('h','i',' ','t','h','e','r','e')) = List(List('h','i'), List('t','h','e','r','e')) | /* split(List('h','i',' ','t','h','e','r','e')) = List(List('h','i'), List('t','h','e','r','e')) | ||
Line 58: | Line 58: | ||
**2.** Write a function which computes a list of ''Token'' from a list of strings. Recall that Tokens keep track of the string frequency. Use an auxiliary function | **2.** Write a function which computes a list of ''Token'' from a list of strings. Recall that Tokens keep track of the string frequency. Use an auxiliary function | ||
- | ''insWord'' which inserts a new string in a list of Tokens. If the string is already a token, its frequency is incremented, otherwise it is added as a new token. | + | ''insWord'' which inserts a new string in a list of Tokens. If the string is already a token, its frequency is incremented, otherwise it is added as a new token. (//Hint: the cleanest way to implement aux is to use one of the two folds//). |
<code scala> | <code scala> | ||
def computeTokens(words: List[String]): List[Token] = { | def computeTokens(words: List[String]): List[Token] = { | ||
Line 104: | Line 104: | ||
def wordCount : Int = ??? | def wordCount : Int = ??? | ||
</code> | </code> | ||
+ | |||
+ | **Note:** In order to be graded, exercises 5 to 9 must rely on a correct implementation of the previous parts of the homework. | ||
===== Using andThen ===== | ===== Using andThen ===== |