[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: MATLAB
>>>>> "LDR" == Lennon Day-Reynolds <lennon@day-reynolds.com> writes:
>> Lazy evaluation can win in space even when all the values are
LDR> used, if they
>> aren't needed at once, though. For example, Haskell's foldl1 (+)
>> [1..2^40]
LDR> In comparing 'foldl' to 'reduce', you missed the fairly easy
LDR> solution of using the Python 'xrange' built-in function to
LDR> generate a lazy sequence of integers; i.e.:
LDR> reduce(operator.add, xrange(2L**40))
LDR> There's a similar 'xreadlines' function which lazily iterates
LDR> over the contents of a file.
We're doing better these days. Python 2.2 will offer the following
alternative:
def numbers():
i = 0
while 1:
i += 1
yield i
for i in numbers():
print i
A builtin integer automatically overflows to a builtin long int, so
this just keeps going and going.
Jeremy
- References:
- Re: MATLAB
- From: "Oliver Steele" <steele@cs.brandeis.edu>
- Re: MATLAB
- From: Lennon Day-Reynolds <lennon@day-reynolds.com>