<br><div class="gmail_quote">On Mon, Dec 6, 2010 at 10:21 PM, prad <span dir="ltr"><<a href="mailto:prad@towardsfreedom.com" target="_blank">prad@towardsfreedom.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
i'm trying create a multi-replace function in racket where you can<br>
substitute for patterns in a string with items in a list:<br>
<br>
(mult-repl "~A"<br>
"this ~A string will experience ~A substitution"<br>
(list "wonderful" "massive"))<br>
-> "this wonderful string will experience massive substitution"<br></blockquote><div><br></div><div>Since it looks like what you are doing is just positional (instead of named) substitutions, format is good enough for the purpose: </div>
<div><br></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div class="gmail_quote"><div><font class="Apple-style-span" face="'courier new', monospace">(format "this ~a string will experience ~a substitution" "wonderful" "massive") </font></div>
</div><div class="gmail_quote"><div><br></div></div><div class="gmail_quote"><div>See <a href="http://docs.racket-lang.org/reference/Writing.html#(def._((quote._~23~25kernel)._format))" target="_blank">http://docs.racket-lang.org/reference/Writing.html#(def._((quote._~23~25kernel)._format))</a> for more details. </div>
</div></blockquote><div class="gmail_quote">
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">however, the results are quite inconclusive. they jump around for all</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
of them between 113-300 cpu time, mostly being around 170.<br>
A. is that because i don't have a sufficiently substantial process<br>
running?<br></blockquote><div><br></div><div>Without seeing the test code it will be know what you are doing to profile and hence are to comment. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
B. should any of the above be significantly faster than another?<br></blockquote><div><br></div><div>The only way to know for sure how fast a code runs is to profile them, but it looks like you are using the same primitives (string-append, regexp-split, etc) so they do not look too different. </div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
speed aside, it seems to me that #2 is the easiest to program and<br>
understand.<br>
C. so are regex a good thing to use in these situations anyway<br>
because it's not like there's anything that's going to be thrown at<br>
them that will stress the system out ... or is that a bad attitude?<br></blockquote><div><br></div><div>Speed is not the most important criteria in programming these days, as long as it's perceived to be fast enough. Often times, a performant system automatically emerges with good design. And even if it needs some tuning, a well designed system is more easily profiled and improved. And over time, obscurely written code will be hard to understand if you ever come back to it months or years later, so it is very important to write legible and understandable code. Good design and understandable code will pay dividends even if it might not be the fastest code. </div>
<div><br></div><div>HTH. Cheers,</div><div>yc</div><div><br></div><div><br></div></div>