From -823140775579592914
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fb1a92fa405c930c
X-Google-Attributes: gidf78e5,public
From: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Subject: Re: nested functions
Date: 1999/06/23
Message-ID: <37674DB8.B1128CB7@physik.tu-muenchen.de>#1/1
X-Deja-AN: 492870504
Content-Transfer-Encoding: 7bit
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
References: <7jd4c5$nup$1@nnrp1.deja.com> <7jjjr6$r02$1@nnrp1.deja.com> <7jma5c$i85@abyss.West.Sun.COM> <7jmdcv$a56$1@engnews1.eng.sun.com> <7jrqf5$op5$1@nnrp1.deja.com> <7jrv0r$dfq$1@engnews1.eng.sun.com> <7k5vjh$r0d$1@nnrp1.deja.com>
X-Original-Date: Wed, 16 Jun 1999 09:09:44 +0200
X-Accept-Language: German/Germany, de-DE, German, de, en
Content-Type: text/plain; charset=us-ascii
Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUAN3Cnw6wEuYhIxRhxAQGwLgH/dEWMvi077/g885SmHs/xey1V1dU1NPsk Ny7OJl6uogVr7zllV5Rd2WLDLnEm7yDiNtTiK3srM2DeINVISm8m+Q== =R+B3
Mime-Version: 1.0
Newsgroups: comp.std.c++

James.Kanze@dresdner-bank.com wrote:
> 
> In article <7jrv0r$dfq$1@engnews1.eng.sun.com>,
>   clamage@eng.sun.com (Steve Clamage) wrote:
> 
> > C++ has enough different scope control mechanisms you don't need
> > local functions the way you need them in, say, Pascal. The
> > primary reason to have local functions in C++ would be to
> > implement closures. If you just want to share state among
> > cooperating functions, use a class. The code will be simpler
> > and easier to maintain.
> 
> Just a question of vocabulary, but what is a closure, exactly.  I've
> always thought that, in layman's terms, it extended the life of the
> local context beyond the return from the function.  I think that this is
> how it works in lisp (but my lisp experience is limited to customizing
> emacs, so I'm not sure).  And of course, Borland has invented a totally
> different meaning. 

Yes, that's a big problem. Maybe we should always qualify the
word "closure", like "functional closure" and "BC++ closure".
However, I prefer the term "bound member pointer" for the last
one. (BTW, those "BC++ closures"/bound member pointers could be
implemented as usual function pointers with the same trampoline
technique as suggested for pointers to local functions - just that
the trampoline would add the class pointer instead of the local
function context).

> What you are describing would seem to be closure as
> I understand it, but without the extended lifetime.  Or are you
> suggesting that Pascal extended the lifetime of the function context
> beyond the return from the function if the address of the function was
> taken.  (The Pascal I used didn't, but there are so many variations of
> Pascal, it's hard to know what is standard, and what is fantasy on the
> part of the implementer.)

Just for your information: Standard Pascal doesn't allow to
take the address of a function at all, nor does it let you
return (or otherwise store) a reference to a function.
All it allows is passing functions as parameters "by reference".
So the question of surviving contexts doesn't arise at all here.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



