[racket] How best to repeat a function call n times?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Sep 15 13:53:26 EDT 2014

Not more efficient, but perhaps more readable:

(define (repeater f count)
  (for ([x (in-range count)])
    (f)))


On Mon, Sep 15, 2014 at 12:50 PM, George Rudolph <rudolphg1 at citadel.edu>
wrote:

>   All,
>
> I am sure this question has been answered before, but I can’t find it.
>
> 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
>
> of doing this than passing the expression to a tail-recursive counting
> loop such as the following?
>
>
>
> (define (repeater sexpr count)
>
>   (sexpr)
>
>   (cond
>
>     [(> count 0) (repeater sexpr (- count 1)) ])
>
> )
>
>
>
>
>
>
>
> George Rudolph
>
> Associate Professor of Computer Science
>
> Department of Mathematics and Computer Science
>
> 225 Thompson Hall
>
> The Citadel
>
> 171 Moultrie Street
>
> Charleston, SC 29409
>
> 843.953.5032
>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140915/9adf9a49/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 92 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20140915/9adf9a49/attachment.gif>

Posted on the users mailing list.