[Gsll-devel] closure out of letm

Tamas K Papp tpapp at Princeton.EDU
Fri Oct 3 00:44:19 UTC 2008


Liam,

Thanks for the solution.  I worked around the issue by using the
inverse distribution function and (random 1d0).

A general question about the architecture of GSLL: would it be
possible to integrate it into Lisp better using finalizers?  The idea
is that when GSLL functions return native GSLL objects (maybe wrapped
in a class, etc), they could also set up a finalizer that would free
the object when it is no longer used.  The library trivial-garbage
provides a standardized interface to finalizers of various
implementations.

Then letm would not be needed at all, and we would achieve a much
better integration into CL.  Just a thought.  Let me know what you
think,

Tamas

On Tue, Sep 30, 2008 at 10:22:25PM -0400, Liam Healy wrote:
> 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