bugGNU Octave - Bugs: bug #52851, parse error at command line or in...

 
 

bug #52851: parse error at command line or in scripts "duplicate subfunction or nested function name"

Submitter:  Marshall <marsian>
Submitted:  Wed 10 Jan 2018 02:41:37 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Marsian Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 09 Sep 2020 09:15:24 PM UTC, comment #5: 

Verified.  Marking as fixed and closing report.

Rik <rik5>
Group administrator
Wed 09 Sep 2020 06:12:37 PM UTC, comment #4: 

I pushed the following changeset on stable and merged with default:

http://hg.savannah.gnu.org/hgweb/octave/rev/d45d1b4bb919

I believe this fixes the problem, but with recent changes to function handles, I think the behavior of the script that uses a persistent array of handles has changed.  However, I think the current behavior is correct since lookup of functions through simple function handles is performed at the time of the function call, not when the handle is created, and only one "computation" function will be defined globally.

John W. Eaton <jwe>
Group administrator
Mon 31 Dec 2018 05:23:33 PM UTC, comment #3: 

This is going to require an architectural discussion and perhaps a philosophical one on Octave-Maintainers list about whether to support this.  In any case, it won't be fixed for version 5.0 (https://wiki.octave.org/Bug_Fix_List_-_5.0_Release#Bugs_with_severity_.3E.3D_4).

Rik <rik5>
Group administrator
Fri 12 Jan 2018 12:52:51 AM UTC, comment #2: 

I can see the point of not allowing sub-functions or nested functions from having the same name, which is why I didn't even try to address this bug in relation to a function file. However, I still have two arguments for why this is desirable behavior for scripts:

1) If I can manually type or paste something in in at the command line and it works, I should be able to run that exact same code from running it as a script to run it all at once. Running a script (F5) is better then highlight and F9, especially for a large script because of the delay probably due to printing and executing every line of code individually. This argument supports allowing syntax like examples 1, 3, and 4 below, but not of 2. (consistency)

2) This is one place where I feel that octave syntax is far better than Matlab, and it would be disappointing to lose some of its benefit. In these cases I am basically using the repeated function declarations as multi-line anonymous functions.
For example:

if  true
    function computation()
        disp('compute 1.1')
        disp('compute 1.2')
    endfunction
else
    function computation()
        disp('compute 2.1')
        disp('compute 2.2')
    endfunction
end

computation()


 is analogous to:


if  true
    computation = @() disp('compute 1');
else
    computation = @() disp('compute 2')
end

computation()


Marshall <marsian>
Thu 11 Jan 2018 11:38:50 PM UTC, comment #1: 

Not commenting on whether this behavior should be supported or not, but this is a result of the fix for bug #50014. When the m-file is a function file, not a script, Octave is now correctly making sure that there are no duplicate subfunctions defined in the same file.

Mike Miller <mtmiller>
Group Member
Wed 10 Jan 2018 02:41:37 AM UTC, original submission:  

In running some scripts in dev octave that worked before in 4.2.1, I ran into a new parse error: "duplicate subfunction or nested function name". I've reduced my code to a couple examples, with increasing complexity in order to show both the minimal example of what doesn't work but used to, and to show closer to my current usage that should still work given any potential fixes to this problem.

All of these work in 4.2.1, whether copied and pasted directly in the command line, (or highlight and F9 in a script), or whether they are in a script and the whole script is run (F5). None of these work in the dev version on F5, but some work if the selection is executed (F9 or copy/paste).

The a=1 in each is only there in the case it is ran as a script (F5) to differentiate it from a function (e.g. avoid the "warning: function name ... does not agree with function filename...'".


a=1;%script identifier
function computation()
    disp('compute 1')
endfunction
computation()

function computation()
    disp('compute 2')
endfunction
computation()




%doesn't work with either F5 or F9
if  true
    function computation()
        disp('compute 1')
    endfunction
    computation()
else
    function computation()
        disp('compute 2')
    endfunction
    computation()
end




a=1;%script identifier
function caller(fun)
    fun()
endfunction
function computation()
    disp('compute 1')
endfunction

caller(@computation)

function computation()
    disp('compute 2')
endfunction

caller(@computation)




a=1;%script identifier
function caller(fun,num)
    persistent funarray
    if isempty(fun)
        funarray(num).fun();
    else
        if isempty(funarray)
            funarray(1).fun = fun;
        else
            funarray(num).fun = fun;
        end
    end
endfunction

function computation()
    disp('compute 1')
endfunction

caller(@computation,1)
caller([],1)

function computation()
    disp('compute 2')
endfunction
caller(@computation,2)
caller([],2)
caller([],1)


These all work in 4.2.1 both in windows and linux, but not in either in mxe-octave dev.



Marshall <marsian>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by marsian (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-09-09 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2020-09-09 jwe StatusConfirmed Ready For Test
    2018-12-31 mtmiller Carbon-CopyRemoved 80942 -
    2018-01-10 siko1056 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code