Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with Scala programming (argument passing) please. Will rate answer highly: * 1. You MUST NOT use while loops or (re)assignment to variables (you

Need help with Scala programming (argument passing) please. Will rate answer highly:

 * 1. You MUST NOT use while loops or (re)assignment to variables (you can use "val" declarations, * but not "var" declarations). You must use recursion instead. * * 2. You may declare auxiliary functions if you like. 
object argpass { class RefInt (initial : Int) { private var n : Int = initial def get () : Int = n def set (m : Int) : Unit = { n = m } } // Complete the following higher-order function. // It has one parameter f: a function that takes an instance of RefInt (see above for the definition of the class RefInt) and returns Unit (i.e., nothing interesting). // Your code must create ONLY ONE instance of RefInt, then call f three times. // f will update the integer stored in the instances of RefInt it is given. // Your code must return a tuple of the three integers provided by f in the order that they came back from calls, i.e., the integer from the first call to f is the first integer in the returned tuple. def refint1 (f : RefInt => Unit) : (Int, Int, Int) = { // TODO: Provide definition here. // Example call: // val r = new RefInt (0) // f (r) // val n : Int = r.get (-1, -1, -1) } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions

Question

Solve Problems 1519. 7k 15 3 + k 5 k - 3 3 +2

Answered: 1 week ago

Question

Understand the concept of variance in an experiment

Answered: 1 week ago