bugGNU Octave - Bugs: bug #32083, nested functions and developers...

 
 

bug #32083: nested functions and developers sources

Submitter:  Ben Abbott <bpabbott>
Submitted:  Sun 09 Jan 2011 05:56:53 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Ben Abbott Open/Closed:  * Closed
Release:  * dev Operating System:  * Mac OS
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sun 09 Jan 2011 07:36:41 PM UTC, comment #6: 

I checked in the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/21b5284fa78d

This seems to fix the problem for me and all tests pass, so I'm closing this report.  If there are new problems parsing functions as a result of this change, then please open a new bug report.

John W. Eaton <jwe>
Group administrator
Sun 09 Jan 2011 07:00:33 PM UTC, comment #5: 

I'd prefer that they were coerced. But that's easy for me to say since I'm trying to run some code written for Matab and am asking someone else (you?) to do the work.

If it requires much effort, I'd say we should just turn the warning into an error.

Ben Abbott <bpabbott>
Group Member
Sun 09 Jan 2011 06:47:47 PM UTC, comment #4: 

I think things will work the same in 3.0.x as 3.2.x, but note that nested functions are not supported.  Previously, Octave would silently treat them as subfunctions.  For example, try this with 3.0.x:


function nested_functions (txt)
 x = 1;
 subfun1 (txt)
 function subfun1 (txt)
   disp (txt)
   x
 end
end


Calling this with


nested_functions ('foo')


I see


-foo
error: `x' undefined near line 6 column 4
error: called from:
error:   /scratch/jwe/build/octave/nested_functions.m at line 6, column 4
error:   /scratch/jwe/build/octave/nested_functions.m at line 3, column 2
octave3.2:2> type nested_functions
nested_functions is the user-defined function defined from: /scratch/jwe/build/octave/nested_functions.m
verbatim-

But I see now that the functions are no longer being properly coerced and instead that there is a parse error.

So, should we just fail for nested functions, or coerce them to subfunctions (some may work that way, some will not).  In your example, they all do have "end" statements, so the error seems wrong.  But I think we should still warn about functions that are recognized as nested but actually handled as subfunctions.

John W. Eaton <jwe>
Group administrator
Sun 09 Jan 2011 06:26:10 PM UTC, comment #3: 

The part below ...


warning: nested functions are coerced into subfunctions


... seems to indicate that the nested functions would be treated as the unnested types. Which means no sharing of variables.

I don't have a 3.2.x version to run, but with 3.0.5 ...


octave:1> nested_functions ('test')
test


Should the warning be replaced by an error, or has this feature been reverted by mistake?

Ben Abbott <bpabbott>
Group Member
Sun 09 Jan 2011 06:11:14 PM UTC, comment #2: 

Nested functions are not yet supported.  This is not a change we will make before 3.4 is released.  Should we change the error message to be more explicit about this?

John W. Eaton <jwe>
Group administrator
Sun 09 Jan 2011 05:58:22 PM UTC, comment #1: 

... trying a 2nd time.

With the following nested function ...


function nested_functions (txt)
 subfun1 (txt)
 function subfun1 (txt)
   disp (txt)
 end
end


I get an error with the nested functions are coerced into unnested
subfunctions.


octave:3> nested_functions test
parse error near line 8 of file
/Users/bpabbott/Development/git/matlab2tikz/src/nested_functions.m

 inconsistent function endings -- if one function is explicitly ended, so
must all the others

warning: nested functions are coerced into subfunctions in file
/Users/bpabbott/Development/git/matlab2tikz/src/nested_functions.m
error: parse error while reading function file
/Users/bpabbott/Development/git/matlab2tikz/src/nested_functions.m


Ben Abbott <bpabbott>
Group Member
Sun 09 Jan 2011 05:56:53 PM UTC, original submission:  

With the following nested function ...


function nested_functions (txt)
  subfun1 (txt)
  function subfun1 (txt)
    disp (txt)
  end
end
-verbatiim-

I get an error with the nested functions are coerced into unnested subfunctions.

+verbatim+
octave:3> nested_functions test
parse error near line 8 of file /Users/bpabbott/Development/git/matlab2tikz/src/nested_functions.m

  inconsistent function endings -- if one function is explicitly ended, so must all the others

warning: nested functions are coerced into subfunctions in file /Users/bpabbott/Development/git/matlab2tikz/src/nested_functions.m
error: parse error while reading function file /Users/bpabbott/Development/git/matlab2tikz/src/nested_functions.m


Ben Abbott <bpabbott>
Group Member

 

(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 jwe (Posted a comment)
  • -email is unavailable- added by bpabbott (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-01-09 jwe StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code