|
![](/i/fill.gif) |
In article <4a8ae42c@news.povray.org>,
Warp wrote:
> Daniel Bastos <dbastos+0### [at] toledo com> wrote:
>> How strong are my imperative ways?
>
>> #!/usr/bin/env mzscheme
>> (module cat scheme/base
>
>> (define (cat)
>> (let ([ln (read-line)])
>> (if (not (eq? ln eof))
>> (and (display ln) (newline) (cat))
>> (exit) )))
>
>> ; main
>> (cat)
>> )
[...]
> 'cat' is a program for concatenating files. It's used like:
>
> cat file1 file2 file3 > concatenated_files
>
> Your program does not fulfill this role.
I wasn't aware of the definition of cat. But I think it's true that
without reading files, it is unable to concatenate. After a day of
work, I can now tell one how to scheme a cat.
#!/usr/bin/env mzscheme
(module cat scheme/base
(define (interact f)
(let ([ln (read-line)])
(cond
[(not (eq? ln eof))
(and
(printf "~a\n" (f ln))
(interact f))])))
(define (id x) x)
(define (cat files)
(for-each
(lambda (x)
(with-input-from-file x
(lambda ()
(interact id))))
files))
;main
(cat (vector->list (current-command-line-arguments)))
)
With with-input-from-file, we get the stdin connected to the file
opened, so no changes in interact were required.
This cat does not handle exceptions. I might see how that works next.
Although Haskell has always looked wonderful to me, I had the
intuition that a Lisp like language would suit me better because I'm
kind of syntax minimalist. I gave up on the idea that this is good,
and went to check Haskell out. I liked it a lot, but I'm coming back
to believe that my initial intuition deserves attention.
Like someone once put it; a good language has to be hackable. I think
Lisp likes might be hackestables.
Post a reply to this message
|
![](/i/fill.gif) |