[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Local procedures
From: |
Antti-Juhani Kaijanaho |
Subject: |
Re: [Tinycc-devel] Local procedures |
Date: |
Wed, 12 Sep 2007 15:26:10 +0300 |
User-agent: |
Mutt/1.5.16 (2007-06-11) |
On Wed, Sep 12, 2007 at 02:10:33PM +0200, Zdenek Pavlas wrote:
> Right. It was just an example how to implement a code semantically
> equivalent to nested functions. Had the second argument to closure() been
> not a stack reference but a literal or a malloc()ed struct, 'fun' would
> become a real closure, a first-class object that could be return'ed, stored
> somewhere, etc.
Still not right. A real closure operator captures its (lexical)
environment in the closure that it creates. Anything you do in C
without compiler magic will have to explicitly name the variables that
are captured.
You solution reminds me of the way closures are emulated in C++ as
function objects. It's close, but not the real thing.
>> You *do* need compiler support for them.
>>
> Syntax sugar, perhaps?
Unfortunately, you do need more compiler support than that.
BTW, the only limitation of nested functions related to real closures is
that you can't safely use a nested function closure after the function
that created it has returned. There are still quite a number of
applications of it that don't need to do that (the canonical example is
the comparison function you give to qsort).
--
Antti-Juhani Kaijanaho, Jyväskylä
http://antti-juhani.kaijanaho.fi/newblog/
http://www.flickr.com/photos/antti-juhani/
- Re: [Tinycc-devel] Local procedures, (continued)
- Re: [Tinycc-devel] Local procedures, Rob Landley, 2007/09/11
- Re: [Tinycc-devel] Local procedures, Antti-Juhani Kaijanaho, 2007/09/11
- Re: [Tinycc-devel] Local procedures, Peter Lund, 2007/09/11
- Re: [Tinycc-devel] Local procedures, Zdenek Pavlas, 2007/09/12
- Re: [Tinycc-devel] Local procedures, Antti-Juhani Kaijanaho, 2007/09/12
- Re: [Tinycc-devel] Local procedures, Zdenek Pavlas, 2007/09/12
- Re: [Tinycc-devel] Local procedures,
Antti-Juhani Kaijanaho <=
- Re: [Tinycc-devel] Local procedures, Zdenek Pavlas, 2007/09/12
- Re: [Tinycc-devel] Local procedures, Rob Landley, 2007/09/12
- Re: [Tinycc-devel] Local procedures, Rob Landley, 2007/09/11
- Re: [Tinycc-devel] Local procedures, Antti-Juhani Kaijanaho, 2007/09/12
- Re: [Tinycc-devel] Local procedures, Rob Landley, 2007/09/12
- Re: [Tinycc-devel] Local procedures, Antti-Juhani Kaijanaho, 2007/09/13
- Re: [Tinycc-devel] Local procedures, Zdenek Pavlas, 2007/09/13
- Re: [Tinycc-devel] Local procedures, Antti-Juhani Kaijanaho, 2007/09/13
- Re: [Tinycc-devel] Local procedures, Peter Lund, 2007/09/13
- Re: [Tinycc-devel] Local procedures, Antti-Juhani Kaijanaho, 2007/09/13