Iteration for Factorials

Mensanator at aol.com Mensanator at aol.com
Tue Oct 23 07:13:41 CEST 2007


 
In a message dated 10/22/2007 8:46:59 PM Central Daylight Time, 
python.list at tim.thechases.com writes:

> > Still, why do you want None instead of raisng an exception
> > (as is the case in other factorial implementations)?
> 
> A null value is as good/bad as raising an exception in my book.
> Since you can't do math on a None object, any attempt to do so
> will raise an exception:
> 
>   >>> 42 + fact(-1)
 
Fair enough.
 
> 
> I generally prefer my functions to return semi-sensible results
> (in this case, None makes sense to me, as there isn't really a
> definition of "negative-one factorial").  It also fits in my head
> alongside my SQL where NULL values/expressions can be returned
> and evaluated without the whole query falling over.
 
Ok, but in SQL, 42 + fact(-1) wouldn't raise an exception, it
would simply return a NULL if fact(-1) returned None. I suppose
the only reason to not use None is for consistent behavior. If all
the functions from the gmpy library raise exceptions on error, I
think I would want mine to do the same.
 
> 
> I suppose if you really wanted to throw an exception using this
> lambda craziness, you could wrap the whole result in "0 +
> ([body])" which, if the body returned Null, would push up
> exception daisies (with slightly misleading exception information).
> 
> -tkc
 
 
 








************************************** See what's new at http://www.aol.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071023/28a6cfa2/attachment.html>


More information about the Python-list mailing list