Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started