bugGNU Octave - Bugs: bug #60541, Copying a returned variable from...

 
 

bug #60541: Copying a returned variable from regexp results in an error message

Submitter:  Robert Fries <rwf1>
Submitted:  Fri 07 May 2021 01:32:52 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 6.2.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 07 May 2021 09:51:42 AM UTC, comment #1: 

Confirmed with Octave 6.2.0 on Windows.

Fwiw, with Matlab R2021a:

>> [S, E, TE, M, T, NM, SP] = regexp('YYYx', 'x(?<vvv>[^x]*)x');
>> xx=NM.vvv
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.

>>


So Octave seems to be compatible with this respect.

IIUC, `NM.vvv` returns an empty comma-separated-list if `NM` is empty. Hence, it cannot be assigned to a variable.
See also: https://octave.org/doc/v6.2.0/Comma-Separated-Lists.html

The following is valid syntax:

[S, E, TE, M, T, NM, SP] = regexp('YYYx', 'x(?<vvv>[^x]*)x');
xx = {NM.vvv}


The braces in the last assignment convert the cs-list to a cell which is allowed to be empty in an assignment.

Markus Mützel <mmuetzel>
Group administrator
Fri 07 May 2021 01:32:52 AM UTC, original submission:  

This call to regexp in octave-6.2 does not find a match (as it should) and returns OK


[S, E, TE, M, T, NM, SP] = regexp('YYYx', 'x(?<vvv>[^x]*)x');


But copying a component of the returned variable NM results in an error message:


xx=NM.vvv
error: invalid number of elements on RHS of assignment


The correct result is available under octave-4.2.2


[S, E, TE, M, T, NM, SP] = regexp('YYYx', 'x(?<vvv>[^x]*)x');
xx=NM.vvv
xx = {}(1x0)


This problem exists on octave releases 4.4.0, 4.4.1, 5.2, 6.1.0, and 6.2.0 although the exact error message varies.

A workaround could be


if (length(M)==0)
  xx=cell(1,0);
else
  xx=NM.vvv;
end


Note that when the problem happens that any checks to see if the variable is really there do not flag the problem.


exist("NM")
ans = 1
isstruct(NM)
ans = 1
isfield(NM,"vvv")
ans = 1



Robert Fries <rwf1>

 

(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 mmuetzel (Posted a comment)
  • -email is unavailable- added by rwf1 (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-05-07 mmuetzel StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
        Operating SystemGNU/Linux Any

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code