logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

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

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

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

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

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. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

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

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

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

. 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 Sea Ports. Here are the classes and their instance variables we wish to define:

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

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

650 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

946 Answers

Hire Me
expert
Husnain SaeedComputer science

753 Answers

Hire Me
expert
Atharva PatilComputer science

793 Answers

Hire Me