Funarg problem: Difference between revisions

Content deleted Content added
Line 19:
compose f g = λx → f (g x)
 
The <code>[[lambdaLambda calculus|λ]]</code> is the operator for constructing a new function, in this case of one argument <code>''x''</code>, which returns the result of first applying <code>''g''</code> to <code>''x''</code>, then applying <code>''f''</code> to the result. This function carries the functions <code>''f''</code> and <code>''g''</code> (or pointers to them) as internal state.
 
The problem in this case exists if the compose function had allocated the parameter variables <code>''f''</code> and <code>''g''</code> on the stack. When <code>''compose''</code> returns, the stack frame containing <code>''f''</code> and <code>''g''</code> is discarded. When the internal function <code>''λx''</code> attempts to access <code>''g''</code>, it will access a discarded memory area.