apply()
of Lisp and other languages. Essentially,
functions are stand-alone methods that are not associated with any
class. They are not compiled and so are easier to modify, test,
modify,...
function foo(x = 1, y = new util.Vector(10)) { }
static
variables in C and Java
and leads to fields in classes.
User Classes
Function
is to
implement tail recursion. By this we mean a function whose last
instruction is to call itself. Hence we have recursion in the tail of
the function. Recognizing such functions means we need not create a
new evaluation frame for the recursive call, since when we return from
it, we will also return from the parent call - a feature of the
tail. This has efficiency implications and avoiding stack
overflow.
Omegahat analyzes functions when they are defined and determines the appropriate class - Closure, Tail Recursive function, Tail Recursive closure, etc.
[1] foo = function(...) { get("...").size(); $1;} function foo(...) -> java.lang.Object get("...").size(); $1; [7] foo(1,2,3) 2
To avoid specifying each argument as lazy
,
one can set the default argument mode for a function
by preceeding it with a lazy
qualifier.
lazy function foo(x, y) { .. }Then individual arguments can be specified as eager
lazy function foo(x, eager y) { }just as one can specify
lazy
qualifiers when the default mode is
eager
.
The eager
and lazy
qualifiers preceed any type declarations for the parameter.
function foo(lazy util.Vector x)
The type information will be specifiable externally from the function (as an additional argument to the compiling method) so as to avoid redefining the function. In this way, we can think of the function as a template.
In addition to functions, we will be able to compile user-level classes and methods as well as global methods/functions.
Duncan Temple Lang <duncan@research.bell-labs.com> Last modified: Sat Aug 7 11:32:22 EDT 1999