[Gsll-devel] closure out of letm

Liam Healy lhealy at common-lisp.net
Wed Oct 1 02:22:25 UTC 2008


Tamas,

If you macroexpand the letm, you will find it is
(LET* ((RNG (MAKE-RANDOM-NUMBER-GENERATOR *MT19937*)))
  (UNWIND-PROTECT
       (PROGN (RNG-SET RNG 0)
	      (LAMBDA () (BETA-RD RNG A B)))
    (FREE RNG)))
so you can just do the MAKE-RANDOM-NUMBER-GENERATOR and RNG-SET part
yourself at the start, and then FREE when you're ready to clean up.

Liam

On Tue, Sep 30, 2008 at 2:32 PM, Tamas K Papp <tpapp at princeton.edu> wrote:
> Hi,
>
> I am trying to create a function that would return another function
> that generates draws from a beta distribution.  Something like this:
>
> (defun make-beta-generator (a b)
>  (letm ((rng (random-number-generator *mt19937* 0)))
>    (lambda ()
>      ;; of course this won't work, letm deallocated rng
>      (beta-rd rng a b))))
>
> As the comment says, this does not work.  Is there a way to prevent
> letm from deallocating rng (or achieve the effect I want by some other
> means)?
>
> Thanks,
>
> Tamas



More information about the gsll-devel mailing list