Some notes

Scott David Daniels Scott.Daniels at Acm.Org
Fri Oct 15 11:12:57 EDT 2004


Alex Martelli wrote:
> [lotsa stuff I like]
>>>- The functional IF seems interesting, like:
>>>if(cond, code1, code2) ... (Or ... a different syntax, [allowing elif])
>>Many variants have been proposed over the years, but none have ever made
>>it in.
> I think generators could get us close to this kind of thing (in Py3k).
> 
> They'd have to sprout a new method 'skip', similar to 'next' but defined
> to not evaluate the argument of the next yield. 
That seems pretty tough to define.  for a generator like:
     def agen():
         source = open('somedatafile.txt')
         for i in range(1000):
             source.seek(4 * i**2 + 33 * i + 52)
             line = source.readline()
             if line.startswith('magic:'):
                 yield line[6:]
         source.close()

What computation would "skip the evaluation of the next yield" avoid?

> ...  Such functions as lisp's cond might then easily be implemented:
> 
> def cond(@_args):
>     for test in _args:
>         if test: return _args.next()
>         else: _args.skip()

what would be different between this and:

 > def cond(@_args):
 >     for test in _args:
 >         if test: return _args.next()
 >         else: _args.next()

I just don't understand the semantics of .skip().

-Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list