help needed to verify expected behavior for scripts and nested functions

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

help needed to verify expected behavior for scripts and nested functions

John W. Eaton
Administrator
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.

Thanks,

jwe

nested-fcn-and-script.zip (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

mmuetzel
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.

Markus

diary (1K) Download Attachment
diary2 (326 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

John W. Eaton
Administrator
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 | Threaded
Open this post in threaded view
|

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

mmuetzel
Am 08. April 2020 um 15:33 Uhr schrieb "John W. Eaton":
> Yes, thanks.

Glad, I could help.

> 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.

Maybe this resource can help understanding their precedence order handling:
https://de.mathworks.com/help/matlab/matlab_prog/function-precedence-order.html

In particular "3. Nested functions within the current function". Looks like the script is *not* "within the current function".
But what that really means is not entirely clear to me either from reading just the documentation.

Not sure if or when that changed. I run fcn1 in R2016a and R2012a, and they both failed with the same error in script1 (like R2019b).

> 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 | Threaded
Open this post in threaded view
|

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

John W. Eaton
Administrator
On 4/8/20 11:18 AM, "Markus Mützel" wrote:

> Maybe this resource can help understanding their precedence order handling:
> https://de.mathworks.com/help/matlab/matlab_prog/function-precedence-order.html
>
> In particular "3. Nested functions within the current function". Looks like the script is *not* "within the current function".
> But what that really means is not entirely clear to me either from reading just the documentation.

Yes, I know about that list.  It's just confusing that a script appears
to be sort of like an include file but not.

jwe

Reply | Threaded
Open this post in threaded view
|

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

mmuetzel
Am 08. April 2020 um 17:25 Uhr schrieb "John W. Eaton":

> On 4/8/20 11:18 AM, "Markus Mützel" wrote:
>
> > Maybe this resource can help understanding their precedence order handling:
> > https://de.mathworks.com/help/matlab/matlab_prog/function-precedence-order.html
> >
> > In particular "3. Nested functions within the current function". Looks like the script is *not* "within the current function".
> > But what that really means is not entirely clear to me either from reading just the documentation.
>
> Yes, I know about that list.  It's just confusing that a script appears
> to be sort of like an include file but not.

Is it possible that there are file(s) missing from the changeset adding related(?) BISTs?
I can't find "script_nest_2":
http://hg.savannah.gnu.org/hgweb/octave/rev/7567413e7246

Markus