// // simple demo of using recursive functions to operate on lists // println("type in list values (integers), quit to end") val list = fillList() println("you entered:") printList(list) println("sum is " + sumList(list)) println("product is " + productList(list)) def fillList() : List[Int] = { val input = readLine if (input == "quit") { List[Int]() } else { val num = input.toInt num :: fillList() } } def printList(ll : List[Int]) { if (!ll.isEmpty) { println(ll.head) printList(ll.tail) } } def sumList(ll : List[Int]) : Int = { if (!ll.isEmpty) { ll.head + sumList(ll.tail) } else { 0 } } def productList(ll : List[Int]) : Int = { if (!ll.isEmpty) { ll.head * productList(ll.tail) } else { 1 } }