From: Ken A. <kan...@bb...> - 2003-08-08 13:29:30
|
You can take this one step further by writing a function producing function: > (define (picker x) (lambda () (vector-ref x (.nextInt random-gen (vector-length x))))) (lambda picker (x)...) > (define rocks #(1 2 3 4 5)) #(1 2 3 4 5) > (define rock (picker rocks)) (lambda picker~0 ()...) > (rock) 3 > (rock) 2 At 06:35 AM 8/8/2003 -0400, Geoffrey Knauth wrote: >Never mind, I guess that was a silly question. For now I've done this: > >(define (pick-one v) > (vector-ref v (.nextInt random-gen (vector-length v)))) > >On Friday, Aug 8, 2003, at 00:00 US/Eastern, Geoffrey Knauth wrote: > >>Let's say I have: >> >>(define (stone-size) >> (vector-ref stone-sizes >> (.nextInt random-gen (vector-length stone-sizes)))) >>(define (stone-thickness) >> (vector-ref stone-thicknesses >> (.nextInt random-gen (vector-length stone-thicknesses)))) >>(define (caulking-type) >> (vector-ref caulking-types >> (.nextInt random-gen (vector-length caulking-types)))) >> >>Notice the repetition? How can I use a JScheme macro to write this once? Ignore the fact that "es" pluralizes "thickness" while "s" pluralizes "size" and "type." >> >>Thanks, >>Geoffrey > > > >------------------------------------------------------- >This SF.Net email sponsored by: Free pre-built ASP.NET sites including >Data Reports, E-commerce, Portals, and Forums are available now. >Download today and enter to win an XBOX or Visual Studio .NET. >http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 >_______________________________________________ >Jscheme-user mailing list >Jsc...@li... >https://lists.sourceforge.net/lists/listinfo/jscheme-user |