octave-maintainers
[Top][All Lists]
Advanced

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

Re: help needed to verify expected behavior for scripts and nested funct


From: John W. Eaton
Subject: Re: help needed to verify expected behavior for scripts and nested functions
Date: Wed, 8 Apr 2020 09:33:00 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 4/8/20 3:11 AM, "Markus Mützel" wrote:
Am 08. April 2020 um 00:47 Uhr schrieb "John W. Eaton":
Could someone please unpack the attached zip file and execute the following commands in a recent version of Matlab (preferably 2019b
or later since it seems there have been some recent changes to
precedence that could be important for this test).

In Matlab, cd to the nested-fcn-and-script directory created by unpacking the zip file and execute

test_script

at the command line.  Post (or mail to me) the resulting diary
file.


Attached please find the diary when running the script with Matlab
R2019b. It failed with a scoping error during "fcn1". So I closed the
diary, opened a new one (diary2) and manually called fcn2 from the
command line.

I hope this helps.

Yes, thanks.

So, scripts are a bit weird. They execute in the workspace of the function where they are called so that they have access to the variables there but they don't see the nested functions that belong to the function that corresponds to that workspace? OK. That's actually consistent with how Octave behaves now in version 6, since the big call stack refactoring. But previously in Octave, the script would see the nested function. It's not really important, but I wonder whether the behavior also changed in Matlab? Or has it always been this way since nested functions were introduced? These details don't seem to be clearly defined in any Matlab docs that I can find online.

Octave doesn't have local functions for scripts that behave the same way as in Matlab, so the fcn2 and script2 is info for the future. It's good to know that the local function is found in that case.

jwe



reply via email to

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