Re: subtle side effect of generator/generator expression

2005-10-16 Thread [EMAIL PROTECTED]
> Are you saying that the bugs it causes aren't subtle? *wink* Exactly. Destructive generator problems are caught almost immediately. -- http://mail.python.org/mailman/listinfo/python-list

Re: subtle side effect of generator/generator expression

2005-10-16 Thread [EMAIL PROTECTED]
thanks. I was looking for scanl in itertools but can't find it so I implement my own then run into some subtle bugs which first made me think my scanl is the problem. Then notice my wrong perception about generator(and iterable in general, though the built-in iterables like list, dict don't seem to

Re: subtle side effect of generator/generator expression

2005-10-16 Thread Steven D'Aprano
On Sun, 16 Oct 2005 15:52:54 +0200, Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > >> I initially thought that generator/generator expression is cool (sort of >> like the lazy evaluation in Haskell) until I notice this side effect. >> >> >>>a=(x for x in range(2)) >> >>>list(a) >> [1,2] >> >>>

Re: subtle side effect of generator/generator expression

2005-10-16 Thread [EMAIL PROTECTED]
True. That is why I have now reverted back to use list whenever possible. As while list can also be modified(say in a multi-thread situation), at least if I don't do the update(coding policy, practice or whatever), they are sort of "guaranteed". I would only use generator as IO monad in Haskell, i

Re: subtle side effect of generator/generator expression

2005-10-16 Thread Simon Percivall
If you find that you want to iterate over an iterable multiple times, have a look at the solution that the tee() function in the itertools module provides (http://docs.python.org/lib/itertools-functions.html). (Have a look at the rest of the itertools module as well, for that matter.) -- http://m

Re: subtle side effect of generator/generator expression

2005-10-16 Thread Fredrik Lundh
Diez B. Roggisch wrote: > Files allow to seek, in addition to stream semantics. Some files. Not all files support seek operations. Some only support forward seek. -- http://mail.python.org/mailman/listinfo/python-list

Re: subtle side effect of generator/generator expression

2005-10-16 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > That is exactly what I meant, in fact. These IO thing are expected to > have side effects so they are not subtle. Generator on the other hand, > is sort of "clever iteratables". > > Now that I notice that, Of course I can be sure I would be careful. But > what about the

Re: subtle side effect of generator/generator expression

2005-10-16 Thread [EMAIL PROTECTED]
That is exactly what I meant, in fact. These IO thing are expected to have side effects so they are not subtle. Generator on the other hand, is sort of "clever iteratables". Now that I notice that, Of course I can be sure I would be careful. But what about the following situation : I import some

Re: subtle side effect of generator/generator expression

2005-10-16 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I initially thought that generator/generator expression is cool (sort of > like the lazy evaluation in Haskell) until I notice this side effect. > > >>>a=(x for x in range(2)) > >>>list(a) > [1,2] > >>>list(a) > [] > > Would this make generator/generator expression's usa

subtle side effect of generator/generator expression

2005-10-16 Thread [EMAIL PROTECTED]
Hi, I initially thought that generator/generator expression is cool(sort of like the lazy evaluation in Haskell) until I notice this side effect. >>>a=(x for x in range(2)) >>>list(a) [1,2] >>>list(a) [] Would this make generator/generator expression's usage pretty limited ? As when the program/