Reimplement the programs below in the CPS style Convert helloUp, doubleUp and mainFun into the CPS functions helloUp_k , doubleUp_k , mainFun_k .Computer Science

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

Attachments:

Instructions Files

Computer Science Experts

expert
Amit
Computer Science

50 Answers

expert
Eleanor Ken
Computer Science

62 Answers

View More Experts
Disclaimer

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.

Get Free Quote!

266 Experts Online