How can we accept function name as user input? Is there any member in standard library like readLine, readByte, etc that solves the purpose?
Context: As part of functional programming, I need to pass function name as first argument but instead of hardcoding I want to accept it as user input.
Please suggest.
Here is the sample code:
def square(x:Int):Int = x*x
def sum(f: Int => Int, a:Int, b:Int):Int ={
if(a>b) 0 else f(a) + sum(f,a+1,b)
}
println("Enter the first number:")
var num1 = readInt()
println("Enter the second number:")
var num2 = readInt()
val ressum = sum(square,num1,num2)