Skip to content

Commit

Permalink
bug fix for _Tail.py for handling the case of evaluating a @recursive
Browse files Browse the repository at this point in the history
…wrapped funciton
  • Loading branch information
yuhangwang committed Jul 1, 2016
1 parent 756a4e6 commit ff0dfac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions FunctionalX/src/TailCallOptimization/_Recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Recursive(object):
def __init__(self, target_recursive_function):
self.function = target_recursive_function

def call(self, *args, **kwargs):
return self.function(*args, **kwargs)

def __call__(self, *args, **kwargs):
value = self.function(*args, **kwargs)
while type(value) is Tail:
Expand Down
7 changes: 5 additions & 2 deletions FunctionalX/src/TailCallOptimization/_Tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
"""
class Tail(object):
def __init__(self, target_function, *args, **kwargs):
self.function = target_function
self.target = target_function
self.args = args
self.kwargs = kwargs

def eval(self):
return self.function(*self.args, **self.kwargs)
if hasattr(self.target, "call"):
return self.target.call(*self.args, **self.kwargs)
else:
return self.target(*self.args, **self.kwargs)

0 comments on commit ff0dfac

Please sign in to comment.