Returning none
Greg Ewing
greg.ewing at compaq.com
Mon Sep 6 17:08:56 EDT 1999
Bernhard Herzog wrote:
>
> clgonsal at keeshah.penguinpowered.com (C.Laurence Gonsalves) writes:
>
> > def new_apply( f, a ):
> > try:
> > result = old_apply( f, a )
> > except NoResultError:
> > return
> > else:
> > return result
It seems that solving this sort of problem properly would require
a special syntactic construct. Maybe an expression
?func_call
which would make the call and evaluate to whatever it returned,
including Nothing. This would allow you to make an either-procedure-
or-function call when you needed to, and test the result. E.g.
def map(f, items):
result_list = None
for item in items:
result = ?f(item)
if result is not Nothing:
if result_list is None:
result_list = []
result_list.append(result)
if result_list is not None:
return result_list
else:
return
Greg
>
> There's one problem with this approach. If the NoResultError is raised
> whithin f, new_apply should reraise the exception and not just silently
> return nothing.
>
> You could, of course, examine the traceback object to find out where the
> exception was raised, but that's very ugly and probably implementation
> dependent.
>
> --
> Bernhard Herzog | Sketch, a drawing program for Unix
> herzog at online.de | http://www.online.de/home/sketch/
More information about the Python-list
mailing list