pythontutor-dev / pythontutor

10 stars 4 forks source link

server error in code that issues RecursionError in CPython #100

Open pgbovine opened 5 years ago

pgbovine commented 5 years ago

gives a server error in OPT without any trace being generated ... would be good to generate a partial trace so that something can be visualized.

example:

def subset(list, sublist=[]):
    if len(list) == 0:
        for value in sublist:
            print(value, end=" ")
            print()
    else:
        subset(list[len(list)-1:], sublist)

subset(["1", "2", "3"])

When run in CPython, it gives this error: RecursionError: maximum recursion depth exceeded ...

other examples:

def keep_if_even(lst):
    new_list=[]
    if (lst[0]%2)==0:
        new_list.append(lst[n])
        if n==len(lst):
            return new_list

    return keep_if_even(lst)

print((keep_if_even([1,2,3,4,5,6])))
def edit_diff(start, goal, limit):
    """A diff function that computes the edit distance from START to GOAL."""
    if start == goal: # Fill in the condition
        return 0
    elif limit < 0:
        return 0
    else:
        add_diff =  1 + edit_diff(start[: len(start)-1], goal, limit)
        remove_diff =  1 + edit_diff(start, goal[len(goal)-1], limit)
        substitute_diff =  1 + edit_diff(start[: len(start)-1], goal[len(goal)-1], limit)
        return min(add_diff, remove_diff, substitute_diff)

big_limit = 10
edit_diff("wird", "wiry", big_limit)
def summ(x):
    k = 2
    total = 0
    if x == 2:
        return k
    else:
        return (summ((-1)**x) * (3*x)) + summ(x-1)
        k += 1

summ(4)
def binary_search_recursive(input_list, key):
    # The input_list must be sorted
    # this function searches for the "key" and in the "input_list"
    # returns True if the "key" was found, False otherwise

    return get_binary_search_recursive(input_list, key)

def get_binary_search_recursive(input_list, key):
    if input_list == []:
        return False
    else:
        mid = (0 + len(input_list)) // 2
        if input_list[mid] == key:
            return True
        else:
            if input_list[mid] < key:
                return get_binary_search_recursive(input_list[mid:], key)
            elif input_list[mid] > key:
                return get_binary_search_recursive(input_list[:mid], key)

print(binary_search_recursive([1,2,3,4,5,6,7,8,9,10], 11))
y=2
def a(z):
    return a(3)
def b(z):
    def c(z):
        return y+z
    return c

m= a(b(y))
print(m)