Reputation: 117
I am having a problem implementing stream-map for the purpose of removing newlines from a stream of characters.
Below is my current implementation of remove-newlines:
(define remove-newlines2
(lambda (str)
(cond
((stream-empty? str) '())
(else (stream-map (lambda (x)
(cond
((equal? x #\newline) (remove x str ))
(else '())
)) ;procedure
str ; stream
)))))
I've toyed around with different implementations. However, it appears that no matter what I do, Racket only recognizes it as a stream, and does nothing further:
(remove-newlines2 (file->stream "text-source-file"))
#<stream>
>
Is there something simple I'm missing here?
Upvotes: 2
Views: 275
Reputation: 235984
It's the expected behavior, because stream-map
returns a stream
as its output. To get its contents you have to evaluate or force the result, for instance using stream->list
on the stream
:
(stream->list (remove-newlines2 (file->stream "text-source-file")))
Upvotes: 1