[Top][All Lists]

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

Re: A suggestion about the code

From: Nicholas Jankowski
Subject: Re: A suggestion about the code
Date: Thu, 28 May 2015 15:51:14 -0400

On May 23, 2015 10:47 AM, "Jordi Gutiérrez Hermoso" <address@hidden> wrote:
> On Fri, 2015-05-22 at 19:44 -0400, Nicholas Jankowski wrote:
> > I also found that for no discernable reason, octave's implementation of
> > this seems not perfect (surely the errors weren't my fault :) ). I've had
> > scripts unable to find functions for no good reason until closing and
> > restarting Octave, at which point it would be fine.
> The explanation is as follows: Octave allows files to be parsed in
> script mode or function mode. Function files are those whose first
> statement is "function". A script file is one whose first statement is
> anything other than "function".
> Script files have "side effects", so to speak. One of the side effects
> of a script file is to define a new function. Thus if you define a
> function in script mode, then the script has to be evaluated each time
> for the changes to that function to take effect.
> For a function defined in function mode, Octave always checks to see
> if the file has changed without you needing to evaluate it.
> This is also explained in the manual,
> HTH,
> - Jordi G. H.

Just tried this again. Everything works now but, and this didn't make sense until I really thought of the script as a script, only if you define the function ahead of the first call. Used to programming where I can pile all my functions at the end and order doesn't matter. That would work fine if I test-ran the script while editing, and didn't clear memory between runs. Hence I thought it would sometimes work and sometimes not.

So, throwing all my sub-functions in a section at the top of the script, usually after a clear so that 'function' isn't the first line, generally works fine. Makes for a cleaner workspace as long as I don't need ML compatibility.


reply via email to

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