Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
fp:homework02-draft [2022/03/28 13:25]
pdmatei
fp:homework02-draft [2022/03/31 13:38] (current)
pdmatei
Line 24: Line 24:
 </​code>​ </​code>​
  
-Notice that there are multiple possible trees to represent one text, however you do not need to take this into account in this homework.+Notice that there are multiple possible ​BS trees to represent one text, however you do not need to take this into account in this homework.
 Our tree is called ''​WTree'',​ and is implemented by the following case classes: Our tree is called ''​WTree'',​ and is implemented by the following case classes:
 <code scala> <code scala>
Line 44: Line 44:
 The method ''​ins''​ is already implemented,​ but the rest must be implemented by you. The project has two parts: ​ The method ''​ins''​ is already implemented,​ but the rest must be implemented by you. The project has two parts: ​
   * **building a WTree** from a text, and   * **building a WTree** from a text, and
-  * **using a WTree**, to gather info about the text.+  * **using a WTree**, to gather info about that particular ​text.
  
 In the next section you will find implementation details about each of the above. In the next section you will find implementation details about each of the above.
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.+**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 =====