[Tutor] exercise is recursion

Remco Gerlich scarblac@pino.selwerd.nl
Tue, 21 Nov 2000 17:14:58 +0100


On Tue, Nov 21, 2000 at 11:01:49AM -0500, D-Man wrote:
> I realized that.  That's why I said the client would pass it the empty list when
> it called it,  or maybe make a function that set's it to the empty list.  It
> would be useful b/c the function doesn't have to pass itself the modified list.
> 
> Just a tradeoff and style decision.

Passing it the empty list when calling it doesn't work, since then the default
argument of the recursive calls would still be the same list as when it
was def'd. Unless you also pass the list to the recursive calls, and then
you're using a default argument that has to be filled in all the time...

A wrapper function that sets it to the empty list could work, but it couldn't
do 'l = []', it'd have to do 'l[:]=[]' so it stays the same list. Very
confusing. And you don't really save anything, you just pass the list
implicitly instead of explicitly...

You're basically using the default argument as a global variable for all
the function calls, except that it has to be cleared in an awkward way.

I think it's a style decision alright, with a very clear outcome ;-)

-- 
Remco Gerlich