[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Idea: Extension of function / return syntax.
From: |
Daniel Carrera |
Subject: |
Re: Idea: Extension of function / return syntax. |
Date: |
Mon, 7 Jan 2013 01:33:21 +0100 |
On 6 January 2013 18:25, Jordi Gutiérrez Hermoso <address@hidden> wrote:
...
>> function momentum( mass, speed )
>>
>> return mass * speed
>>
>> endfunction
...
>
> 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.
>
> - Jordi G. H.
Would it be difficult to add this syntax? I am naive about Octave's
internals, but it seems to me like it just requires a small extension
of the "return" command. But I don't know. I hope it is not difficult.
I think it would be great to write "function foo(...)" for function
declarations, the way you do in other languages.
A slight variation of the proposal is that the last statement of the
function could be returned as the return value. This idea is inspired
by Perl. For example, a function could be written as:
function conserved_quantities(m,v)
energy = 0.5 * m * v * v;
momentum = m*v:
[ energy , momentum ]
endfunction
The point is that now there is no need to make changes to the "return"
statement. This idea seems to work well in the Perl world, and it is
at least clean and simple.
What do you think?
Cheers,
Daniel.
--
Lord of the rings calendar in your Linux/Unix/Mac terminal: cat
/usr/share/calendar/calendar.lotr
- Idea: Extension of function / return syntax., Daniel Carrera, 2013/01/05
- Re: Idea: Extension of function / return syntax., Jordi Gutiérrez Hermoso, 2013/01/06
- Re: Idea: Extension of function / return syntax.,
Daniel Carrera <=
- Re: Idea: Extension of function / return syntax., Júlio Hoffimann, 2013/01/06
- Re: Idea: Extension of function / return syntax., Daniel Carrera, 2013/01/06
- Re: Idea: Extension of function / return syntax., Júlio Hoffimann, 2013/01/07
- Re: Idea: Extension of function / return syntax., Daniel Carrera, 2013/01/07
- Re: Idea: Extension of function / return syntax., Júlio Hoffimann, 2013/01/07
- Re: Idea: Extension of function / return syntax., Michael D. Godfrey, 2013/01/07
- Re: Idea: Extension of function / return syntax., Daniel Carrera, 2013/01/07
- Re: Idea: Extension of function / return syntax., John W. Eaton, 2013/01/07
- Re: Idea: Extension of function / return syntax., Michael D. Godfrey, 2013/01/07
Re: Idea: Extension of function / return syntax., Jordi Gutiérrez Hermoso, 2013/01/07