Python or Java or maybe PHP?

Hans Nowak hans at zephyrfalcon.org
Mon Jan 2 23:06:39 EST 2006


Alex Martelli wrote:

> A Ruby example of reimplementing while:
> 
> def WHILE(cond)
>     |   return if not cond
>     |   yield
>     |   retry
>     | end
> i=0; WHILE(i<3) { print i; i+=1 }
> 
> Python's a bit less direct here, but:
> 
> def WHILE(cond):
>     if not cond(): return
>     yield None
>     yield WHILE(cond)

Maybe I misunderstand, but shouldn't this be:

def WHILE(cond):
     if not cond(): return
     yield None
     for x in WHILE(cond): yield x

After all, the original version only yields two things: None and a 
generator.

(Or is this behavior different in Python 2.5?  I hope not...)

-- 
Hans Nowak
http://zephyrfalcon.org/



More information about the Python-list mailing list