Re: Questions on closure environment capture
[Thread Prev] | [Thread Next]
- Subject: Re: Questions on closure environment capture
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Thu, 3 May 2018 17:22:33 -0700
- To: myrddin-dev@xxxxxxxxxxxxxx
- Cc: Quentin Carbonneaux <quentin@xxxxxx>
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
Questions on closure environment capture | vimacs <vimacs.hacks@xxxxxxxxx> |
Re: Questions on closure environment capture | Quentin Carbonneaux <quentin@xxxxxx> |
- Prev by Date: Re: Questions on closure environment capture
- Next by Date: Myrddin 0.2.2: Build correctly using the LLVM linker.
- Previous by thread: Re: Questions on closure environment capture
- Next by thread: Myrddin 0.2.2: Build correctly using the LLVM linker.
- Index(es):