Name: WRITE YOUR NAME HERE
1 / TEST HELPER
2 def passed(points: Int) {
3 require(points >=0)
4 if (points == 1) print(s"\n*** Tests Passed (1 point) ***\n")
5 else print(s"\n*** Tests Passed ($points points) ***\n") 6 }
Problem 1 (20 points): CPS Style Transformation
Reimplement the programs below in the CPS style.
A (10 points)
Convert helloUp, doubleUp and mainFun into the CPS functions helloUp_k , doubleUp_k , mainFun_k . They should take continuations that are of type String => String .
def helloUp(x: String): String = { "Hello " + x
}
def doubleUp(x: String): String = { x + x
}
def mainFun(x: String): String = { doubleUp(helloUp(x) + "World")
}
1 ??? // YOUR CODE HERE
I
1 //BEGIN TEST
2 assert(helloUp_k("World", x => x) == "HelloWorld", "Test 1, Set 1
3 assert(doubleUp_k("World", x => x) == "WorldWorld", "Test 2 Set 1
4 assert(mainFun_k("Donkey", x => x) == "HelloDonkeyWorldHelloDonke
5 passed(5)
6 //END TEST
1 //BEGIN TEST
2 assert(helloUp_k("Hello", x => ("*"+x+"*")) == "*HelloHello*", "T
3 assert(doubleUp_k("HelloWorld", x => ("*"+x+"*")) == "*HelloWorld
4 assert(mainFun_k("Cruel", x => ("*"+x+"*")) == "*HelloCruelWorldH
5 passed(5)
6 //END TEST
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of