bugGNU Octave - Bugs: bug #62111, scope resolution operator addition...

 
 

bug #62111: scope resolution operator addition to Octave language

Submitter:  None
Submitted:  Thu 24 Feb 2022 10:18:10 PM UTC
   
 
Category:  Interpreter Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Wont Fix Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 09 Apr 2022 01:11:31 PM UTC, comment #2: 

Two more ways are to use +DIR packages or static classdef methods.  Both are also compatible with Matlab.

Many Matlab features have been added to address the namespace issues of the language.  We don't need to introduce any more separate ones in Octave.

I'm closing this as "won't fix".

John W. Eaton <jwe>
Group administrator
Mon 28 Feb 2022 01:24:51 AM UTC, comment #1: 

Re-titling report and changing release to the development branch.  This would be a major addition to the Octave language.  This is not a feature Matlab implements and web searches show that this issue has come up from time to time, but that Matlab has made no changes to their language.

There are various ways to workaround the issue with the current language.

Method #1 : function handles

Function handles store a pointer to a function and that pointer is recorded at the time of creation of the function handle and doesn't change thereafter.  One can use the fact that the current directory is the first item on the path() to ensure that a function handle stores the version of the m-file you want.  The sample code below assumes that the function with a duplicate filename is named "fname.m", dir1 is the directory of the first m-file instance and dir2 is the directory of the second mfile instance.


old_pwd = pwd;
cd dir1
fcn1 = @fname;
cd dir2
fcn2 = @fname;
cd (old_pwd)


Once the function handles are defined you can call whichever one you want with ordinary function handle syntax such as "fcn1 (x, y, z)".

Method #2 : rmpath / addpath

If there are two m-files with the same name then Octave or Matlab will execute the one that occurs first in the load path.  Assume that the first function is in dir1 which occurs before dir2 in the search path.  In that case, there is no problem executing fcn1 whenever you want.  However, to execute fcn2 do this


rmpath (dir1)
fname (...)  # Call fcn2
addpath (dir1)  # Restore fcn1 to be earlier in the loadpath



Rik <rik5>
Group administrator
Thu 24 Feb 2022 10:18:10 PM UTC, original submission:  

Some Octave packages have functions that override core functions. If the user needs to call both functions at the same time, the only way is to repeatedly call pkg load and pkg unload which takes time. Octave is missing a scope resolution operator so ::foo() is a core function but pkgname::foo() is the overriding function in the package.

Anonymous

 

(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)
  •  

    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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-09 jwe CategoryNone Interpreter
        StatusNone Wont Fix
        Open/ClosedOpen Closed
    2022-02-28 rik5 Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low
        Item GroupNone Feature Request
        Release6.4.0 dev
        Operating SystemMicrosoft Windows Any
        Summarymissing scope resolution operator scope resolution operator addition to Octave language

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code