octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Idea: Extension of function / return syntax.


From: Catalin Codreanu
Subject: Re: Idea: Extension of function / return syntax.
Date: Mon, 7 Jan 2013 21:31:21 +0100

> So I just found the first problem with this syntax. What will
> "nargout" return inside a function that does not declare an output
> variable yet uses decorated return statements? We could make it leave
> it at zero, and arguably if you're using both nargout and this new
> syntax you should be considered to be in error. More difficultly,
> perhaps nargout should parse the whole function first to see if there
> is a bare and a non-bare return statement? But then is it possible for
> a function to have both bare and non-bare return statements, in which
> case, what would nargout return?
>
> New syntax is a very delicate matter... The multiple return arguments
> of Matlab that we have to keep in Octave are very problematic:
>
>    https://abandonmatlab.wordpress.com/2010/05/28/multiple-output-arguments/
>
> If nargout should ignore the new syntax and just work as it is, this
> is probably easiest, but I bet someone will think that this is the
> wrong choice.
>
> - Jordi G. H.


Hello everybody and Happy New Year =)

Correct me if I am mistaken, but "nargout" is set by the parser when reading the
function call, not the function header, right ? Assuming the decorated return existed,
then what would be the difference between these two calls :

function A = f1()
  A = nargout;
endfunction

function f2()
  return nargout;
endfunction

x = f1();
y = f2();

As it is, the return list, with named variables, works fine and is very useful. That
shouldn't change ! Maybe the decorated return could be accepted for a function with
only one or no return argument.
Besides, using nargout in functions isn't trivial so I think people that use it can
understand the potential pitfalls.

Cheers,
Catalin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]