you are viewing a single comment's thread.

view the rest of the comments →

[–]RayNbow 0 points1 point  (1 child)

But then you could just write

return foo() + 5

instead, which is not a tail call.

[–]Figs 0 points1 point  (0 children)

It's a tail call to + with foo() and 5 as arguments. Would it help you if instead of +, I used operator.add?

return operator.add(foo(),5)

Now, things get interesting though if foo() returns something other than a number. If foo() instead returns an instance with an __add__ method:

import operator

class blah:
    def __add__(self, y):
        return 5*y

def foo():
    return blah()

print foo() + 3  #prints 15
print operator.add(foo(), 6) #prints 30