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

Re: Critique a first prog?



On Mon, 25 Sep 2000, Bryn Keller wrote:
> Hello again, and thanks to everyone for their valuable input. I've 
> attached the new, transmogrified version. ...

> ... In addition to the changes others suggested, I've converted it more
> to a stream-filter approach ...

For amusement/education, you might want to try converting this to more of
a filter-stream approach.  That is, try creating a <wrapper-stream>
subclass such that the main loop of your program can be rewritten as

>     with-open-file(
>         out-stream = filename,
>         direction: #"output", if-does-not-exist: #"create");
>       for (file in files)
>         format-out("%s\n", file);
>         with-open-file(in-stream = concatenate(pathname, file))
>           let good-line-stream
>             = make(<line-filter-stream>, inner-stream: in-stream,
>                    line-filter-test: good-line?);
>           let line = #f;
>           while (line := read-line(line-filter-stream,
>                                    on-end-of-stream: #f))
>             write-line(out-stream, line);
>           end;
>         end;
>       end;
>     end;

:-)

Anyway, what you have looks fine.  As a minor stylistic point, function
arguments which are bound ro predicates (as opposed to module bindings
bound to predicates) tend not to have '?' on the end.  E.g., the
predicate argument for the built-in sort function is "test" rather than
"less-than?".  So I might be tempted to rename "accept-line?" as
"line-accept-test" and "criterion?" as just "test".

Oh yeah, and note that, for things like

>     if (line)
>       nexts[file] := copy-match(line, nextkey,"\"");
>     else
>       nexts[file] := #f;
>     end;

you can write

>     nexts[file] := when (line) copy-match(line, nextkey, "\""); end;

or

>     nexts[file]
>      := if (line)
>           copy-match(line, nextkey, "\"");
>         else
>           #f
>         end;

(if that's not obvious) -- it's a matter of personal taste, I think.

Like I said, though, looking good :-)
Hugh




References: