mark.warren
2019-5-23 10:01:48

Hello, I’m trying to make a number of random number generators with fixed seeds and so far I came up with the following (define (make-seeded-rng seed) (let ([old-rng (current-pseudo-random-generator)] [new-rng (make-pseudo-random-generator)]) (current-pseudo-random-generator new-rng) (random-seed seed) (current-pseudo-random-generator old-rng) new-rng)) Does anyone know of an easier way?


rokitna
2019-5-23 11:15:04

@mark.warren I think that’s about as good as it gets, but parameterize takes care of some of the details there:

(define (make-seeded-rng seed)
  (let ([new-rng (make-pseudo-random-generator)])
    (parameterize ([current-pseudo-random-generator new-rng])
      (random-seed seed))
    new-rng))

mark.warren
2019-5-23 11:16:31

@rokitna Thanks I wondered if I’d missed something. I’ve not used parameterize before. Looks interesting.


rokitna
2019-5-23 11:23:18

They essentially manage this pattern for temporarily binding a value, and they do it in a way that cooperates well with first-class continuations.

A bunch of stuff in Racket has behavior that varies based on the current value of some parameters, so it’s pretty common to have to use parameterize (or the pattern you were doing).


mark.warren
2019-5-23 11:24:30

Cool thanks


asumu
2019-5-23 15:18:06

@asumu has joined the channel


asumu
2019-5-23 15:21:45

Whoops, didn’t see this ping until now because slack doesn’t ping me for channels I’m not in. @sydney.lambda I think what it comes down to is that the generic interface feature isn’t really intended to be used for full-on OO with inheritance. It’s more commonly used to, say, implement a uniform data structure interface with different structs. I think I would suggest trying to use the racket/class library if you want to use inheritance to structure your code.


sydney.lambda
2019-5-23 17:00:49

cheers @asumu


joelmccracken
2019-5-24 05:25:14

I think i need to learn how to make a macro to do what i want. wish me luck!