POV-Ray : Newsgroups : povray.off-topic : how to scheme a cat up? : Re: how to scheme a cat up? Server Time
5 Sep 2024 09:23:16 EDT (-0400)
  Re: how to scheme a cat up?  
From: Daniel Bastos
Date: 19 Aug 2009 00:06:16
Message: <4a8b7a38@news.povray.org>
In article <4a8ae42c@news.povray.org>,
Warp wrote:

> Daniel Bastos <dbastos+0### [at] toledocom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.