Nested Function - An Example

An Example

An example using Pascal syntax:

function E(x: real): real; function F(y: real): real; begin F := x + y end; begin E := F(3) + F(4) end;

the same example in GNU C syntax:

float E(float x) { float F(float y) { return x + y; } return F(3) + F(4); }

and (one way to write) the same example in Haskell syntax:

e :: Float -> Float e x = f 3 + f 4 where f y = x + y


The function F is nested within E (note that x is visible in F and y is invisible outside F).

Read more about this topic:  Nested Function

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)