Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Questions on closure environment capture


On Thu, 3 May 2018 07:03:12 +0000, Quentin Carbonneaux <quentin@xxxxxx> wrote:

> On Thu, May 03, 2018 at 12:14:31PM +0800, vimacs wrote:
> > Hi,
> > 
> > I'm trying to use the closure in Myrddin, but I'm confused about the
> > implementation of it and the so-called environment capture.
> > 
> > Here are some code in my program.__
> 
> And Ori, please feel free to correct/enrich the explanation.
> 

Yep, that's about right.

> It might be possible to create one environemnt per *dynamic*
> closure, but that would require dynamic stack allocation

Yes. It can also lead to very... questionable behavior if you
have a loop, for example.

	for var i = 0; i < 100_000; i++
		use({; closure()})
	;;

Would that have to allocate 100,000 closures? Heapifying the
function (fndup) will solve the issue here, at a modest runtime
cost, since that copies the closure env to the heap.

For a lot of the 'traditional' closure behaviors in functional
languages, you really want a GC; what I got here seems to be
a sane enough compromise.

-- 
    Ori Bernstein

References:
Questions on closure environment capturevimacs <vimacs.hacks@xxxxxxxxx>
Re: Questions on closure environment captureQuentin Carbonneaux <quentin@xxxxxx>