// // simple demo of using recursive functions to operate on lists // def fillList() : List[Int] = { val input = readLine if (input == "quit") Nil else input.toInt::fillList() } def printList(list : List[Int]) { if (list != Nil) { println(list.head); printList(list.tail); } } def listCombine(list : List[Int], combine : (Int, Int) => Int, identity : Int) : Int = { if (list != Nil) { combine(list.head, listCombine(list.tail, combine, identity)) } else { identity } } println("enter values for list, quit to end:") val list1 = fillList() printList(list1); println("sum = " + listCombine(list1, (x,y)=>(x+y), 0)) println("product = " + listCombine(list1, (x,y)=>(x*y), 1)) println("min = " + listCombine(list1, (x,y) => (x min y), Int.MaxValue)) println("max = " + listCombine(list1, (x,y) => (x max y), Int.MinValue))