Tail recursion means that you must directly return the result of a recursive call without further manipulation.
, , . , .
- ; map .
def map(l, f):
if l == []:
return []
else:
return map(l[1:], f, f(l[0]))
! . 3 , . , 3- . ( ), : , , . , , . , . :
def map(l, f):
return map_acc(l, f, [])
def map_acc(l, f, a):
if l == []:
return a
else:
b = a + [f(l[0])]
return map_acc(l[1:], f, b)
, , . .
a . , , , , , " ", .
map " f l ", map_acc " f on l, , a, , ".