<br><div class="gmail_quote">On Mon, Dec 6, 2010 at 11:15 PM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br></div>One thing to keep in mind is that if you only care about replacing<br>
occurrences in some input file, then you can avoid the overhead of<br>
collecting the full text in memory. For example, this will read the<br>
standard input, and replace each "~a" with a string from the list,<br>
spitting out the new text:<br>
<br>
#lang racket/base<br>
(require racket/generator)<br>
(define get-string (generator () (for-each yield '("X" "Y" "Z"))))<br>
(define (replace-all)<br>
(when (regexp-match "~a" (current-input-port) 0 #f (current-output-port))<br>
(display (get-string))<br>
(replace-all)))<br>
(replace-all)</blockquote><div><br></div><div>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. </div><div>
<br></div><div>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. </div>
<div><br></div><div>Thanks,</div><div>yc</div><div><br></div></div>