Hello,
Is there a simple way to pass an *arbitrary* number of arguments to a function called within another function?
For example, I want to write a very silly function silly_f that takes a pointer to another function and the arguments (an arbitrary number) that are to be passed to that other function.
All silly_f does is to execute the other function. The thing is, I don't know it in advance how many arguments the other function takes.
(For the R users out there, I'm thinking of something similar to R's ...)
I'd like to do something along these lines (warning: illegal Mata code ahead!)
Is there a simple way to pass an *arbitrary* number of arguments to a function called within another function?
For example, I want to write a very silly function silly_f that takes a pointer to another function and the arguments (an arbitrary number) that are to be passed to that other function.
All silly_f does is to execute the other function. The thing is, I don't know it in advance how many arguments the other function takes.
(For the R users out there, I'm thinking of something similar to R's ...)
I'd like to do something along these lines (warning: illegal Mata code ahead!)
Code:
mata
real scalar myf(real scalar a, real scalar b) {
c = a + b
return(c)
}
real scalar myf2(real scalar a, real scalar b, real scalar c) {
d = a + b + c
return(d)
}
real scalar silly_f(ponter scalar f, ...) {
(*f)(...)
}
silly_f(&myf(), 2, 4)
silly_f(&myf2(), 2, 4, 5)
end

Comment