[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What?
- To: address@hidden
- Subject: Re: What?
- From: Andreas Bogk <address@hidden>
- Date: Sun, 11 Aug 2002 13:00:02 -0400
- Cancel-lock: sha1:0QUlD483rNFOtVH8Q5YYFK8tmfU=
- Organization: There Is No Cabal.
- References: <200208111431.g7BEVXmY023559@life.ai.mit.edu>
- Sender: "Gregory T. Sullivan" <address@hidden>
- User-agent: Gnus/5.090007 (Oort Gnus v0.07) XEmacs/21.4 (Honest Recruiter,i386-debian-linux)
- Xref: traf.lcs.mit.edu comp.lang.dylan:14288
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)