January 17, 2017
Here’s our solution:
(define (copy) (let loop ((c (read-char)) (prev #\p)) (cond ((eof-object? c)) ((and (char=? #\space c) (char=? \#space prev)) (loop (read-char) c)) (else (display c) (loop (read-char) c)))))
We read standard input and write standard output. C is the next character on standard input and prev is the current character on standard input, initially anything other than a blank. The loop stops in the first
cond clause when it sees the end-of-file character, skips a character and goes to the next in the second
cond clause when both the current character and the previous character are blanks, and otherwise outputs the current current character and goes to the next in the
else clause (which might be the first blank character in a run of blanks, or any other non-blank character).
You can run the program at http://ideone.com/quOgSe, where you will also see sample output.
Pages: 1 2