To pass C() to A we construct a closure
consisting of C's address and the static link
that would have been used if C would have been
called directly:
1#1
Modula-2 -- global procedures are first-class (can be stored),
local procedures are third-class.
Modula-3 -- global procedures are first-class,
local procedures are second-class (can be passed
as parameters).
Ada 83 -- procedures are third class.
Ada 95 -- nested procedures can be returned
if the scope in which it was declared is at least
as wide as that of the declared return type. I.e.
a procedure can only be propagated to an area of
the program where the referencing environment is
active.
The Scheme built-in function
call-with-current-continuation (also called
call/cc) takes a function as argument:
4#4
foo takes a continuation as argument.
(call/cc foo) calls foo, passing it
the current continuation.
A continuation is a closure that holds the current
program counter and environment.