Multiple dispatch handles that in the same way that Ethan’s code demonstrates.

In my experience, nargin usage is often a pattern for working around the 
absence of default arguments, which Julia has.

 — John

On Apr 1, 2014, at 7:59 AM, J Luis <[email protected]> wrote:

> Yes, the variable input arguments is easy for us (matlabers) to adapt for, 
> but I really miss (or didn't find the replacement yet) is the conditional 
> behavior depending on the number of outputs. That is
> 
> if (nargout == 2)
>   ...
> elseif (nargout == 3)
>  ... 
> 
> Terça-feira, 1 de Abril de 2014 15:42:45 UTC+1, John Myles White escreveu:
> +1 for Ethan’s approach 
> 
> Any time that you would have used conditionals in a function to change 
> behavior based on the number of arguments or their types, the Julian approach 
> is to use multiple dispatch instead. 
> 
>  — John 
> 
> On Apr 1, 2014, at 7:29 AM, Ethan Anderes <[email protected]> wrote: 
> 
> > Hi Adrian: 
> > 
> > Not sure how long you've been working with Julia but I also was looking for 
> > nargin from Matlab when I recently converted to Julia. I figure I would 
> > post this for other newbies in my situation.  I had a lot of Matlab code 
> > like the following 
> > 
> > function y = foo(x, z) 
> >         if nargin > 1 
> >                 ... do something with x and z .. 
> >         else 
> >             .... do something with x ... 
> >         end 
> > end 
> > 
> > Then I realized the multiple dispatch approach of Julia make this much more 
> > clean. So in julia I would write 
> > 
> > function foo(x) 
> >         .... do something with x ... 
> > end 
> > function foo(x, z) 
> >         .... do something with x and z .. 
> > end 
> > 
> > 
> > Cheers, 
> > Ethan 
> > 
> > 
> 

Reply via email to