Implement of Matlab function "nargout" in Julia

It is easy to dynamically obtain the number of output variables in MATLAB by function “nargout”,how can I do such in Julia?
For example,these is the code in MATLAB

function [ varargout ] = CopyElement( V )
% V is a tensor, varargout copy its element value
if( nargout > numel( V ) )
    error( 'In CopyElement: the number of elements in V should no less than nargout!' );
end
for i = 1 : nargout
    varargout{ i } = V( i );
end
end

Does not exist, see e.g. noteworthy differences where you find

In Julia, multiple values are returned and assigned as tuples, e.g. (a, b) = (1, 2) or a, b = 1, 2. MATLAB’s nargout, which is often used in MATLAB to do optional work based on the number of returned values, does not exist in Julia. Instead, users can use optional and keyword arguments to achieve similar capabilities.

2 Likes

ok thank u, I will try some additional arguments.

The number of outputs (ie. length of output tuple) is decided from within the function in Julia, not from outside.

2 Likes