/* * Yet another version of summing a list * This one, instead of gettign the head and recurring on * the rest of the list, does everything positionally. Depending * on the implementation of the list, this version may be much * faster, or must slower, than the other version */ fun main() { println(bb(listOf(1,2,3,4,5,6))) } /* * Another list summer, this time using get to do a list element * @param b3 -- a list of integers : default=null * @param summ -- the number to consider to be the sum of an empty or null list: default 0 * @param pos -- the positionof the next item in the list to put into the * sum : default=0 */ tailrec fun bb(b3: List?=null, pos:Int=0, summ:Int=0) : Int { if (b3==null) return summ if (b3.isEmpty()) return summ if (pos<0) return summ if (pos >= b3.count()) return summ return bb(b3, pos+1, summ+b3.get(pos)) }