Thu 31 Jul 2014 02:17:01 AM UTC, original submission:
This report relates to the lack of re-compilation of a .m file when it changes during the execution of a script. This may be intentional/desirable for performance reasons. However, it seems to differ from Matlab, causes a discrepancy between normal execution and execution in debug mode, and should be made explicit in the documentation.
The context in which I came across this behaviour related to an existing non-Octave program adapted to output matrices in .m format. A loop in my Octave script ran this program with different input parameters before calling the resulting .m file to load the data. I had expected each new data set to be read from the output file in turn, but in fact only the first data set was ever used.
Curiously, each new data set was correctly loaded in debug mode. This may be because Octave checks for changes at each new line when running interactively, as explained here. Thus, a changing .m file is not re-compiled when a script is running normally, but is re-compiled when step-debugging - clearly undesirable.
While the documentation does cover the re-compilation of changing files, it is not immediately obvious that files will not be recompiled during the execution of a script - even with ignore_function_time_stamp("none"). I therefore suggest that this is made explicit, and it is explained that if .m files change during script execution, the relevant function should should either be cleared, or the script file run using source() or run(), which ensure re-compilation.
Finally, in contrast to Octave, Matlab does seem to re-compile functions during script execution, but only after a time delay of about 1 second. However, experiments seemed to indicate that this behavior was in fact quite undesirable, producing different outputs depending on the time at which the script was executed (NB this was relayed to me on IRC - I am unsure whether it related to straight calls, calls through run() or both).
Example
See attachment. Comment out lines in foo() as appropriate. using run() or source() will result in y=1, 2, ... , 10. Calling testb directly results in y = 1, 1, ... , 1. Matlab may produce something like y = 1, 1, 1, 1, 6, 6, 6, 6, 6, 6, depending on the run.
|