<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Wed, 23 Sep 2009 19:59:06 +0100
From   : philb@... (Phil Blundell)
Subject: Beeb, this was your grandma!

On Wed, 2009-09-23 at 00:54 +0100, Philip Pemberton wrote:
> But there is one Pascal feature I used to miss -- nested functions:
> 
> function fred(x : Integer; y : Integer) : Integer;
>    function jim(y : Integer) : Integer;
>    begin
>      return y*5;
>    end;
> begin
>    return (x*2)+jim(y);
> end;
> 
> Nothing outside of "fred" can see "jim" -- effectively this is like a 
> static function, but restricted to a single function rather than a 
> single module (or Unit in Pascal parlance). Interestingly Pascal seems 
> to be the only language that supports this...

Nested functions are supported in GNU C, though not (at least at
present) in standard C.  The thing that makes them more than just
trivial sugar for visibility is that nested functions also inherit their
parent's local variables, so you can write:

int foo(int x)
{
  int x_plus_one(void)
  {
    return x+1;
  }
  return x_plus_one();
}

p.
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>