bugGNU Octave - Bugs: bug #42126, persistent variable inaccessible...

 
 

bug #42126: persistent variable inaccessible from within a nested function

Submitter:  sergey plotnikov <nul0m>
Submitted:  Tue 15 Apr 2014 05:05:05 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 28 Dec 2017 06:33:26 PM UTC, comment #7: 

This works now on the development branch, probably due to a lot of symbol table refactoring by jwe.  Marking as fixed and closing report.

Rik <rik5>
Group administrator
Wed 28 Dec 2016 05:18:18 PM UTC, comment #6: 

As a workaround until someone codes a fix fo this, the persistent variable can be changed to a global.

Rik <rik5>
Group administrator
Wed 28 Dec 2016 04:29:16 PM UTC, comment #5: 

This is marked as "Matlab Compatibility" because Octave is not, in fact, Matlab compatible.  There is a separate classification for "WTF Matlab" when the MathWorks has done something super strange that is barely worth implementing.  This is worth fixing.

Since Octave is a completely volunteer effort, the best way to get something fixed is to do it yourself or get someone else interested in the problem who can fix it.

Rik <rik5>
Group administrator
Wed 28 Dec 2016 10:36:15 AM UTC, comment #4: 

Just pointing out this bug was flagged recently on stackoverflow: stackoverflow.com/questions/41317608/nested-function-does-not-see-local-variable-in-octave-matlab so it's still alive and well after 2 years, and affecting real users.

I would say that describing this bug as a "Matlab Compatibility" issue is sugarcoating the issue a bit. This is clearly an octave bug relating to the implementation of nested functions; matlab is just doing what it's supposed to, this is not a "wtf matlab" moment.

Tasos Papastylianou <tpapastylianou>
Thu 15 Dec 2016 02:44:43 PM UTC, comment #3: 

This issue is still present in Octave 4.2.0.

A function call to the function cited in comment #0 still throws an error in Octave.

Hartmut <hardy>
Wed 25 Nov 2015 09:57:04 PM UTC, comment #2: 

Still present on the development branch (11/25/15).

Rik <rik5>
Group administrator
Tue 15 Apr 2014 07:40:11 PM UTC, comment #1: 

Confirmed on 3.8.1 & 4.1.0+ on WinXP
Although with different line numbers in the error messages - I suppose you didn't show the exact code :-)

Indeed this is documented ML behavior:
http://www.mathworks.nl/help/matlab/matlab_prog/share-data-between-workspaces.html,
see first sentence under "Nested functions".

Apparently this doesn't only hold for persistent vars but for all stuff in the parent's workspace.

OS set to "Any"

Philip Nienhuis <philipnienhuis>
Group Member
Tue 15 Apr 2014 05:05:05 PM UTC, original submission:  

The following function works in Matlab but doesn't in Octave.


function accessPersistVarFromNested
persistent myVar
disp(myVar);
myVar = randn;
myNested;
  function myNested
    disp(myVar);
  end
end


Below is the Octave error message:


>> accessPersistVarFromNested
 0.82211
error: 'myVar' undefined near line 14 column 10
error: evaluating argument list element number 1
error: called from:
error:   /myPlace/accessPersistVarFromNested.m at line 14, column 5
error:   /myPlace/accessPersistVarFromNested.m at line 8, column 1


Matlab has no problem accessing myVar when inside myNested(), so I'm wondering if current Octave behavior was really meant.

sergey plotnikov <nul0m>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tpapastylianou (Posted a comment)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by nul0m (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-12-28 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2014-04-24 rik5 CategoryNone Interpreter
        Summarypersistent variable is inaccessible from within a nested function persistent variable inaccessible from within a nested function
    2014-04-15 philipnienhuis StatusNone Confirmed
        Operating SystemGNU/Linux Any

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code