stack 中表示这个函数 local variables, parameters, return address, other temporaries 的一段空间,称为 activation record or stack frame.
higher-order function, first-class function, 把函数当 variable 来传,且子函数能访问父函数的 variables
fun f(x) =
let fun g(y) = x+y
in g
end
val h = f(3)
val z = h(5)
如上,支持这样的语言(ML, scheme, lua),就无法用 stack 来保存 local variables
同时满足下面两个条件的,称为 higher-order function
1. nested functions
2. functions as returnable values
Pascal 属于 1. 子函数能访问父函数的 variables,但因为函数不能当返回值,所以可以用 stack 来保存所有的 local variables
而 C 属于 2. 但不满足 1. 也就没有"子函数能访问父函数的 variables"一说了。
to be continue ...
评论