On Fri, Mar 6, 2015 at 11:43 AM, J Luis <jmfl...@gmail.com> wrote: > Is there any fundamental reason why the nargout mechanism cannot (or is > very hard) to implement? > Because if not I really think it would be very very handy to have it. > While we can workaround the nargin concept with the multiple dispatch, the > same does help for the nargout. >
I'm not an expert on the innards of the Julia compiler, but I believe the most important reason is that it interferes with type stability of a function, which in turn interferes with the ability of the compiler to generate optimized code. Additionally, functions can currently be used as callbacks from C and Fortran code (and there's generally a desire to keep/enhance C interactivity as much as possible). If we wanted functions to know the number of output parameters, there would need to be a mechanism to provide this information to the function at call time (e.g., the number of args would perhaps need to be passed in as a hidden parameter). As there is no mechanism to do this in C, we would either lose compatibility with C, or need to provide a new kind of function, solely for this purpose. So while adding such functionality might add convenience (mostly for people coming from Matlab), it 1) would produce slower, less optimized code, and 2) would require adding a new kind of function to the language and compiler (which is already pretty complicated). I think that would be a pretty hard sell to the primary developers. Cheers! Kevin