Recursive calls and stack

jm.suresh@no.spam.gmail.com jm.suresh at gmail.com
Wed Feb 14 01:09:37 EST 2007


Hi,
 I have a program which literately finds the object that overlapping a
point. The horizontal and vertical search are called recursively from
inside each other.
 Is this way of implementation fill the stack space with the local
variables inside each call. If this is not good, is there a better way
to implement? Or python itself will understand that the calls happen
in the last line, so local variables need not be pushed into the
stack?

def find_point(pt):
    return _hor_search(pt, random_obj)

def _hor_search(pt, obj):
    ...
    object = ...
    ...
    if object meets some condition:
        return object
    else:
        return _ver_search(pt, object)

def _ver_search(pt, obj):
    ...
    object = ...
    ...
    if object meets some condition:
        return object
    else:
        return _hor_search(pt, object)


-
Suresh




More information about the Python-list mailing list