You can't have nested functions/closures like that - all functions exist in
a single global scope. You can return a function value and dereference it,
as you're doing, and argv() and varg() can be used, as you're doing. You
could create a convention for a closure, perhaps - an array whose first
value is a function, and whose subsequent values are the initial arguments
to use when calling it. Then create a call_closure() function that
evaluates such arrays, adding on whatever additional arguments are passed to
it, e.g.
function call_closure(carr,...) {
f = carr[0]
i = 0
arr = []
for ( n=1; n<sizeof(carr); n++ ) {
arr[i++] = carr[n]
}
for ( n=1; n<nargs(); n++ ) {
arr[i++] = argv(n)
}
f(varg(arr))
}
function doit() {
for ( n=0; n<nargs(); n++ ) {
print("doit arg n=",n," = ",argv(n))
}
}
function sean() {
c = [0=doit,1=44,2=55]
call_closure(c,99)
}
The code in call_closure() is a little messier than it should be - it looks
like you can't combine the use of varg and "..." in a single function call,
but it's easy enough to just add them to the array you give to varg(), as
shown.
...Tim...