[Python-ideas] lazy list

Andrew Barnert abarnert at yahoo.com
Thu May 14 22:29:58 CEST 2015


On May 14, 2015, at 08:44, Alexander Atkins <alexander at tutorfair.com> wrote:
> 
>> A slice is just a subsequence of indexed values. If you can index it,
>> you should be able to slice it.
>> 
>> assert spam[start:end:step] == [spam[i] for i in range(start, end, step)]
> 
> What I was trying to do was to create a slice without losing the laziness.  For example, in my implementation you can take a slice like foo[start:] from an infinite sequence without causing problems.  I haven't quite done it right, because I've returned an iterator instead of another LazyList object, but I could fix it up.  I discuss this a bit more in the example program given in the repository.

Having gone through this whole idea before (and then never finding a good use for it...), that's the only hard part--and the easiest way to solve that hard part is to create a generic sequence view library, which turns out to be more useful than the lazy list library anyway.

(Plus, once you build the slice view type of the sequence view abstract type, it's pretty easy to build a deque- or rope-like sequence of discontiguous, or even different-source, slices, at which point tail-sharing becomes trivial, which makes lazy lists a lot more useful.)

One more thing: a lot of the problems you (at least if you're thinking the same way I was) think you want lazy lists for, you only need tee--or you only need tee with its cache exposed so you can explicitly access it. Being able to directly index or slice or even delete from it as a sequence is a neat problem to solve, but it's hard to find a case where explicitly working on the cache is significantly less readable, and it's a lot simpler.

But anyway, if you think it could be useful to someone else, you don't need to ask python-ideas whether to upload it to PyPI; just do it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150514/091eeadc/attachment.html>


More information about the Python-ideas mailing list