octave-maintainers
[Top][All Lists]
Advanced

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

Re: Functions in scripts


From: John W. Eaton
Subject: Re: Functions in scripts
Date: Tue, 24 Jan 2017 16:03:58 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0

On 01/24/2017 02:52 PM, Rik wrote:

Thanks.  So Matlab is reading through the entire script once and
accepting forward declarations.  There should be a way to accomplish the
same thing in Octave because Octave already knows how to do this for
function files and forward declarations of subfunctions.

Octave also reads a script file completely and creates a parse tree that is executed later. A parsed script is stored as an octave_user_script object, which is slightly different from an octave_user_fcn object (no arguments or return values and different behavior when it is executed).

Within a script, Octave stores an object in the parse tree for each function definition. When the script is executed, function objects are inserted in the symbol table as they are encountered in the parse tree. It should be fairly straightforward to instead make a list of all the function objects in the script and evaluate them first, before the rest of the statements in the script.

It should also be reasonably easy to make the functions local to the script if that is what Matlab is doing. But that is incompatible with the way Octave currently works, so we'd have to make a choice about exactly what we want the behavior to be, whether we want to try to maintain backward compatibility with older versions of Octave, etc.

jwe




reply via email to

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