[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What?



Gabor Greif <gabor@mac.com> writes:

> The initial impementation is here:
> http://monday.sourceforge.net/wiki/index.php/BitsAndPieces

I've tweaked it a little.  Using this framework, the original problem
of summing up numbers from a file becomes:

with-open-file(file = "bar")
  reduce1(\+, lazy-sequence(curry(read-line, file, on-end-of-stream: #f),
                            filter: string-to-integer)
end with-open-file;

Note that one could do without the filter: feature:

reduce1(\+, map(string-to-integer,
                lazy-sequence(curry(read-line, file, on-end-of-stream: #f))))

but this builds an intermediate sequence in memory.

Much nicer would be a full-blown implementation of lazy sequences,
that preserves laziness across standard sequence operations like map,
do, reduce etc., but that sounds like a project for a long winter
evening.

Andreas

-- 
"In my eyes it is never a crime to steal knowledge. It is a good
theft. The pirate of knowledge is a good pirate."
                                                       (Michel Serres)