Add the function to its own globals, so recursive functions work

Currently, recursive functions don't seem to work, because at the time the doctest is run, the function hasn't actually been defined in its own namespace, so the recursive call fails. This pull request adds the function to its own global namespace, so that when it tries to call itself, the call will succeed.