help-octave
[Top][All Lists]
Advanced

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

Scripts within functions


From: John W. Eaton
Subject: Scripts within functions
Date: Mon, 10 Oct 2011 10:37:20 -0400

On 10-Oct-2011, José Vallet wrote:

| Is it possible to define and use scripts within functions?
| 
| I'd like to move some blocks of code (scripts) to the end of the file 
| and then call the scripts in different parts of the function. The 
| purpose is simply for cleanness of the code.
| 
| I know that I can define functions inside functions. That is not what I 
| want, as in this particular case the list of input and output arguments 
| would get too complicated.

Currently in Octave, the script parts would have to go in separate
files and you can't pass any arguments to them.

In Matlab, nested functions work the way you want, but most of the
Octave developers think that is not good programming practice since
Matlab also lacks any sort of local variable declaration, so it makes
modifying code written this way risky.  If your function has many
variables, then it becomes difficult to know whether a nested function
is supposed to be modifying variables in the calling function's scope,
and it is easy to accidentally make changes which have unintended
consequences by changing values in the parent function.

jwe



reply via email to

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