Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Nested function
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Simple example === A simple example in Pascal: <syntaxhighlight lang=pascal> function E(x: real): real; function F(y: real): real; begin F := x + y end; begin E := F(3) + F(4) end; </syntaxhighlight> The function <code>F</code> is nested within <code>E</code>. Note that <code>E</code>'s parameter <code>x</code> is also visible in <code>F</code> (as <code>F</code> is a part of <code>E</code>) while both <code>x</code> and <code>y</code> are invisible outside <code>E</code> and <code>F</code> respectively. Similarly, in [[Standard ML]]: <syntaxhighlight lang=ocaml> fun e (x : real) = let fun f y = x+y in f 3 + f 4 end; </syntaxhighlight> In [[Haskell (programming language)|Haskell]]: <syntaxhighlight lang=haskell> e :: Float -> Float e x = f 3 + f 4 where f y = x + y </syntaxhighlight> In [[PL/I]]: {{pre| e: procedure(x) returns(float); declare x float; f: procedure(y) returns(float); declare y float; return x + y end; return f(3.0) + f(4.0); end; }} In [[Python (programming language)|Python]]: <syntaxhighlight lang=python> def e(x: float) -> float: def f(y: float) -> float: return x + y return f(3.0) + f(4.0) </syntaxhighlight> In [[GNU Compiler Collection|GNU C]]<ref>{{cite book |last1=Rothwell |first1=Trevis J. |title=The GNU C Reference Manual |date=2011 |publisher=Free Software Foundation, Inc |page=63}}</ref> {{endash}} which extends standard C with nested functions: <syntaxhighlight lang=c> float E(float x) { float F(float y) { return x + y; } return F(3) + F(4); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)