Yes, Julia doesnt have "nargout". The idiomatic way to do this would be to 
use optional arguments:

http://julia.readthedocs.org/en/latest/manual/functions/#optional-arguments

So:

function f(a, b=0)
  if b > 0
     #do the computations for second argument
   end
   #rest of computation
end

Use a default value that makes sense in your domain. 

On Wednesday, 4 March 2015 16:48:28 UTC, Pooya wrote:
>
> I have a function with two outputs. The second one is computationally 
> expensive, so I want to avoid the computation unless the user needs it. I 
> read on another post in the group that the solution in this case is usually 
> to define two functions, but in this case I basically need to do all the 
> computations for the first output to compute the second. Is there any nicer 
> way to do this in julia? In MATLAB, I would just say:
>
> If nargout > 1
>     # do all the computations for second output
> end
>

Reply via email to