Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
