From: Geoffrey K. <ge...@kn...> - 2003-08-08 13:50:04
|
That's exactly what I was aiming for, thanks! --Geoffrey On Friday, Aug 8, 2003, at 09:29 US/Eastern, Ken Anderson wrote: > 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 |