For Programmers: Free Programming Magazines  


Home > Archive > Scheme > February 2005 > Force/delay and writing to streams









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Force/delay and writing to streams
Hobbyist

2005-02-13, 4:02 pm

For a fully downwards compatible file format, I'd like to record what
is written to a file, but also write out how many items are written
before the entries are actually written. So an old version can just
skip entries that aren't known, because it knows in advance how many
entries have been written to the file by a new version.

I've tried promises like this in PLT Scheme:

(define-syntax delay/count
(syntax-rules ()
((_ ident expr body ...)
(let* ((delayed-values (list (delay body) ...))
(ident (length delayed-values)))
(begin expr
(for-each force delayed-values))))))

(delay/count n (write n) (write "hello") (write "world!"))

==> 2"hello""world"

The problem is, however, that I only want to count applications of
some special procedure, say stream-write, and not everything that is
in the body of delay/count. In general, something like this would do:

(delay/count-proc n proc expr body ...)

Bind n to the numbers of times proc is used in body, evaluate expr in
this environment, and then evaluate the n expressions of the body.

A somewhat crazy control construct, I admit. Is there a way to do
this?

(FYI, this is not a homework assignment.)
Hobbyist

2005-02-14, 9:00 pm

> (delay/count-proc n proc expr body ...)
>
> Bind n to the numbers of times proc is used in body, evaluate expr in
> this environment, and then evaluate the n expressions of the body.


sorry that should read "..and then evaluate the body".

I think I'll just switch to a simpler file format or more conventional
buffering. Still I wonder if the above is possible.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com