[racket] regexp-replace* with input-port ==> Re: multi-replace function
On Mon, Dec 6, 2010 at 11:15 PM, Eli Barzilay <eli at barzilay.org> wrote:
>
> One thing to keep in mind is that if you only care about replacing
> occurrences in some input file, then you can avoid the overhead of
> collecting the full text in memory. For example, this will read the
> standard input, and replace each "~a" with a string from the list,
> spitting out the new text:
>
> #lang racket/base
> (require racket/generator)
> (define get-string (generator () (for-each yield '("X" "Y" "Z"))))
> (define (replace-all)
> (when (regexp-match "~a" (current-input-port) 0 #f
> (current-output-port))
> (display (get-string))
> (replace-all)))
> (replace-all)
This brings up something I noticed earlier today looking at regexp docs:
regexp-replace family does not work with input-port, when the other regexp-*
functions do.
Are there reasons for the difference? Is it because input-port cannot be
written to? But since the string & bytes variants all generate new output,
that will seem to be the same for input-port source anyways.
Thanks,
yc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101206/7d172b4c/attachment.html>