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: Jordi Gutiérrez Hermoso
Subject: Re: Idea: Extension of function / return syntax.
Date: Mon, 7 Jan 2013 12:24:04 -0500

On 6 January 2013 12:25, Jordi Gutiérrez Hermoso <address@hidden> wrote:
> On 5 January 2013 13:36, Daniel Carrera <address@hidden> wrote:
>> I know that Octave is happy to extend MATLAB's syntax if that makes it
>> a better language. I would like to suggest an extension of the
>> "return" keyword so you can write functions like this:
>>
>> function momentum( mass, speed )
>>
>>     return  mass * speed
>>
>> endfunction
>>
>>
>> In other words, instead of specifying the function outputs on the
>> first line, as it is normally done in MATLAB, the return function
>> could receive the set of values to be returned. This would make Octave
>> consistent with many other languages like Python and Perl.
>
> This could make sense... I'm cautiously in favour of such syntax.
> Syntax additions are very delicate, however, so we need to be very
> careful to make sure this doesn't break more things than what it
> fixes.

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.


reply via email to

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