[Tutor] global variables & recursion

Gregor Lingl glingl at aon.at
Mon Feb 23 17:28:22 EST 2004



Alan Gauld schrieb:

>>>      # function calls itself:
>>>      st(b,r,_eulen+1)
>>>
>>>
>>>      
>>>
>>## Here _rem need not be inserted as argument as it si the default
>>    
>>
>value
>  
>
>>of this fourth parameter.
>>    
>>
>
>While that's true I personally wouldn't advise leaving out _rem since
>it makes the code more obscure and relies on a fairly arcane bit of
>Python black magic. Recursive functions are notoriously hard to
>maintain
>anyway, and by relying on the persistent definition of a mutable
>default
>argument you make the problem even harder. All for the sake of saving
>a
>comma and 4 characters....
>  
>
d'accord!
But I'd destictively prefer my second solution, which uses solely the 
list _rem, because it
does exactly what one does, when one solves this diophantine equation by 
hand,
namely reversing the euclidean algorithm.
Gregor

>Alan G.
>
>
>
>  
>



More information about the Tutor mailing list