Re: [julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-02 Thread Oliver Lylloff
Are the default values then considered in a global scope? Not sure I fully understand the doc: http://docs.julialang.org/en/latest/manual/functions/#evaluation-scope-of-default-values function foo(x,z=1) ...# z in global scope? end function foo2(x) z=1 # Local scope ...

Re: [julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-02 Thread Ivar Nesje
No, the difference in scope is for the right side of the = sign. Default parameters is only fancy syntax for declaring multiple methods at once. function foo(x, z = a) ## calculation using x and z end is equivalent to function foo(x,z) ## calculation using x and z end foo(x) = foo(x, a) In

[julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-01 Thread Adrian Torrie
As the title says, is there an equivalent? If not, would setting optional args to a ridiculous value, e.g. -, and then testing for which args have/don't have that value suffice to determine the number of args passed through. I'm trying to port some MATLAB code I found on the

Re: [julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-01 Thread Jacques Rioux
I don't know Matlab but I believe what you are after is length as used below. function demo (x...) length (x) end demo(3, 4, 5) 3 On Apr 1, 2014 7:14 AM, Adrian Torrie adriantor...@gmail.com wrote: As the title says, is there an equivalent? If not, would setting optional args to a

Re: [julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-01 Thread Ethan Anderes
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

Re: [julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-01 Thread John Myles White
+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 ethanande...@gmail.com wrote:

Re: [julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-01 Thread John Myles White
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 jmfl...@gmail.com wrote: Yes, the variable input

Re: [julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-01 Thread Steven G. Johnson
On Tuesday, April 1, 2014 10:59:44 AM UTC-4, J Luis 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 Julia functions do not know

Re: [julia-users] What is the Julia equivalent of the MATLAB function: nargin()

2014-04-01 Thread Steven G. Johnson
Note that default arguments in Julia can simplify this further. Often you have Matlab code like function y = foo(x, z) if nargin 2 z = ...default value... end end Which in Julia can be simplified to function foo(x, z = ...default value...) ... end This is