Thanks to all for the workable solutions. I quickly implemented Ian's idea and it is working for me... thanks again!<div><br></div><div>Here is a little background so you can better educate me:</div><div><br></div><div>
As I've been learning Racket I've created a file called play.rkt that contains useful code I've learned. Its primary purpose is to allow me to quickly search for techniques and code that I vaguely remember. As I built the file I created test functions alongside the code to make sure it is working called test1 ... testn. I originally used test-engine to run these tests. A nice feature of this setup was that I could use (test) to run all the tests and (time (test)) to see how long they all took. When submodules came out I switched to rackunit (module+ test ...) and could run all the tests simply by hitting the "run" button in DrRacket. This worked fine but I was just a little bothered that I could no longer see how long they all take to run. </div>
<div><br></div><div>This morning I thought, "The test functions all look the same, there has to be a way to call them all in a simple function that I can then run with (time (call-fns))." Ian's code does this for me </div>
<div>without having to add a thousand extra lines to the existing file. Now I hit "run" which checks that they are working, then type (time (call-fns)) if I want to see how long they take to run (without the return value checking). This is workable for me. There are probably better ways and I admit that this solution rested on a really bad naming convention (test1...), but this is not production code, just a little something "on the side" as it were.</div>
<div><br></div><div>Regards,</div><div>-Joe</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 27, 2012 at 11:57 AM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org" target="_blank">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">A few minutes ago, J. Ian Johnson wrote:<br>
> If you don't need to dispatch on name at runtime, you can write a<br>
> macro for this and use format-id to construct the identifier naming<br>
> the function. Otherwise you would need to use eval, which is highly<br>
> inadvisable.<br>
<br>
</div><div class="im">A few minutes ago, David Van Horn wrote:<br>
><br>
> This is a slight variation on Ian's suggestion. It uses a macro<br>
> (id-in name n m) that constructs a list consisting of the elements<br>
> namen ... namem-1.<br>
<br>
</div>These suggestions are not too useful, since they both basically<br>
provide an alternative syntax for something that is already in the<br>
code -- for example, the second one works only in cases like<br>
(id-in f 1 4) where you could just as well remove the space and use<br>
`f1'. (Realizing how they're not useful is probably a good exercise<br>
in "getting" macors, or maybe also getting the difference between<br>
macros and `eval' (and fexprs...).)<br>
<br>
In any case, here's another thing to consider, which is more likely to<br>
be a good solution when you run into such a problem: build a table<br>
that maps names to functions:<br>
<br>
(define function-names (make-hash))<br>
(define (call-by-name name . args)<br>
(apply (hash-ref function-names name) args))<br>
<br>
And when you define a function, add it to the table too:<br>
<br>
(define (test1) 'foo)<br>
(hash-set! function-names "test1" test1)<br>
(define (test2) 'bar)<br>
(hash-set! function-names "test2" test2)<br>
(call-by-name (format "test~a" (add1 (random 2))))<br>
<br>
This is looks verbose -- but that's fixable with a very simple macro:<br>
<br>
(define-syntax-rule (define/name (name . xs) body ...)<br>
(begin (define (name . xs) body ...)<br>
(hash-set! function-names (symbol->string 'name) name)))<br>
(define/name (test1) 'foo)<br>
(define/name (test2) 'bar)<br>
(call-by-name (format "test~a" (add1 (random 2))))<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:<br>
<a href="http://barzilay.org/" target="_blank">http://barzilay.org/</a> Maze is Life!<br>
</font></span></blockquote></div><br></div>