<div dir="ltr"><div><font color="#000000" face="monospace">Not more efficient, but perhaps more readable:</font></div><div><font color="#000000" face="Verdana, sans-serif" size="3"><br></font></div><div><font color="#000000" face="Verdana, sans-serif" size="3">(define (repeater f count)</font></div><div><font color="#000000" face="Verdana, sans-serif" size="3"> (for ([x (in-range count)])</font></div><div><font color="#000000" face="Verdana, sans-serif" size="3"> (f)))</font></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 15, 2014 at 12:50 PM, George Rudolph <span dir="ltr"><<a href="mailto:rudolphg1@citadel.edu" target="_blank">rudolphg1@citadel.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="white" background="cid:image001.gif@01CFD0EA.E54C9600" lang="EN-US" link="#9D454F" vlink="#814E95">
<img src="cid:image001.gif@01CFD0EA.E54C9600" width="0" height="0" style="width:0;min-height:0">
<div>
<p class="MsoNormal">All,<u></u><u></u></p>
<p class="MsoNormal">I am sure this question has been answered before, but I can’t find it.<u></u><u></u></p>
<p class="MsoNormal">Suppose I want to call some function, either built-in or user-defined, n number of times, and measure the total time it takes. Is there a more efficient or elegant way
<u></u><u></u></p>
<p class="MsoNormal">of doing this than passing the expression to a tail-recursive counting loop such as the following?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">(define (repeater sexpr count)<u></u><u></u></p>
<p class="MsoNormal"> (sexpr)<u></u><u></u></p>
<p class="MsoNormal"> (cond <u></u><u></u></p>
<p class="MsoNormal"> [(> count 0) (repeater sexpr (- count 1)) ])<u></u><u></u></p>
<p class="MsoNormal">) <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Georgia","serif"">George Rudolph<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Georgia","serif"">Associate Professor of Computer Science<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Georgia","serif"">Department of Mathematics and Computer Science<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Georgia","serif"">225 Thompson Hall<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Georgia","serif"">The Citadel<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Georgia","serif"">171 Moultrie Street<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Georgia","serif"">Charleston, SC 29409<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Georgia","serif""><a href="tel:843.953.5032" value="+18439535032" target="_blank">843.953.5032</a><u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>