bugGNU Octave - Bugs: bug #67348, Cell array construction of...

 
 

bug #67348: Cell array construction of anonymous functions fails without comma delimiting

Submitter:  Thomas <kolmanthomas>
Submitted:  Tue 22 Jul 2025 08:49:34 PM UTC
   
 
Category:  Interpreter Severity:  2 - Minor
Priority:  2 Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Thu 31 Jul 2025 06:37:41 AM UTC, comment #3: 

I had to go back to version 9.4 of Octave, but I have a backtrace for the parser executing the problem expression.


octave:1> { @(x) sin(x) @(y) cos(y) }
Starting parse
Entering state 0
Stack now 0
Reading a token
Next token is token '{' ()
Shifting token '{' ()
Entering state 8
Stack now 0 8
Return for a new token:
Reading a token
Next token is token '@' ()
Shifting token '@' ()
Entering state 9
Stack now 0 8 9
Return for a new token:
Reading a token
Next token is token '(' ()
Shifting token '(' ()
Entering state 92
Stack now 0 8 9 92
Reducing stack by rule 182 (line 1342):
   $1 = token '(' ()
-> $$ = nterm param_list_beg ()
Entering state 93
Stack now 0 8 9 93
Return for a new token:
Reading a token
Next token is token NAME ()
Shifting token NAME ()
Entering state 15
Stack now 0 8 9 93 15
Reducing stack by rule 24 (line 540):
   $1 = token NAME ()
-> $$ = nterm identifier ()
Entering state 106
Stack now 0 8 9 93 106
Return for a new token:
Reading a token
Next token is token ')' ()
Reducing stack by rule 148 (line 1067):
   $1 = nterm identifier ()
-> $$ = nterm decl_elt ()
Entering state 177
Stack now 0 8 9 93 177
Reducing stack by rule 192 (line 1421):
   $1 = nterm decl_elt ()
-> $$ = nterm param_list_elt ()
Entering state 180
Stack now 0 8 9 93 180
Reducing stack by rule 190 (line 1411):
   $1 = nterm param_list_elt ()
-> $$ = nterm param_list2 ()
Entering state 179
Stack now 0 8 9 93 179
Next token is token ')' ()
Reducing stack by rule 189 (line 1394):
   $1 = nterm param_list2 ()
-> $$ = nterm param_list1 ()
Entering state 178
Stack now 0 8 9 93 178
Next token is token ')' ()
Shifting token ')' ()
Entering state 271
Stack now 0 8 9 93 178 271
Reducing stack by rule 183 (line 1360):
   $1 = token ')' ()
-> $$ = nterm param_list_end ()
Entering state 272
Stack now 0 8 9 93 178 272
Reducing stack by rule 186 (line 1377):
   $1 = nterm param_list_beg ()
   $2 = nterm param_list1 ()
   $3 = nterm param_list_end ()
-> $$ = nterm param_list ()
Entering state 94
Stack now 0 8 9 94
Reducing stack by rule 293 (line 2267):
-> $$ = nterm anon_fcn_begin ()
Entering state 181
Stack now 0 8 9 94 181
Return for a new token:
Reading a token
Next token is token NAME ()
Shifting token NAME ()
Entering state 15
Stack now 0 8 9 94 181 15
Reducing stack by rule 24 (line 540):
   $1 = token NAME ()
-> $$ = nterm identifier ()
Entering state 75
Stack now 0 8 9 94 181 75
Reducing stack by rule 46 (line 663):
   $1 = nterm identifier ()
-> $$ = nterm primary_expr ()
Entering state 50
Stack now 0 8 9 94 181 50
Reducing stack by rule 63 (line 735):
   $1 = nterm primary_expr ()
-> $$ = nterm oper_expr ()
Entering state 51
Stack now 0 8 9 94 181 51
Return for a new token:
Reading a token
Next token is token '(' ()
Shifting token '(' ()
Entering state 122
Stack now 0 8 9 94 181 51 122
Return for a new token:
Reading a token
Next token is token NAME ()
Shifting token NAME ()
Entering state 15
Stack now 0 8 9 94 181 51 122 15
Reducing stack by rule 24 (line 540):
   $1 = token NAME ()
-> $$ = nterm identifier ()
Entering state 75
Stack now 0 8 9 94 181 51 122 75
Reducing stack by rule 46 (line 663):
   $1 = nterm identifier ()
-> $$ = nterm primary_expr ()
Entering state 50
Stack now 0 8 9 94 181 51 122 50
Reducing stack by rule 63 (line 735):
   $1 = nterm primary_expr ()
-> $$ = nterm oper_expr ()
Entering state 51
Stack now 0 8 9 94 181 51 122 51
Return for a new token:
Reading a token
Next token is token ')' ()
Reducing stack by rule 107 (line 929):
   $1 = nterm oper_expr ()
-> $$ = nterm simple_expr ()
Entering state 53
Stack now 0 8 9 94 181 51 122 53
Next token is token ')' ()
Reducing stack by rule 133 (line 997):
   $1 = nterm simple_expr ()
-> $$ = nterm expression ()
Entering state 89
Stack now 0 8 9 94 181 51 122 89
Reducing stack by rule 56 (line 700):
   $1 = nterm expression ()
-> $$ = nterm arg_list ()
Entering state 210
Stack now 0 8 9 94 181 51 122 210
Next token is token ')' ()
Shifting token ')' ()
Entering state 297
Stack now 0 8 9 94 181 51 122 210 297
Reducing stack by rule 67 (line 752):
   $1 = nterm oper_expr ()
   $2 = token '(' ()
   $3 = nterm arg_list ()
   $4 = token ')' ()
-> $$ = nterm oper_expr ()
Entering state 51
Stack now 0 8 9 94 181 51
Return for a new token:
Reading a token
Next token is token '@' ()
Reducing stack by rule 107 (line 929):
   $1 = nterm oper_expr ()
-> $$ = nterm simple_expr ()
Entering state 53
Stack now 0 8 9 94 181 53
Next token is token '@' ()
Reducing stack by rule 133 (line 997):
   $1 = nterm simple_expr ()
-> $$ = nterm expression ()
Entering state 275
Stack now 0 8 9 94 181 275
Reducing stack by rule 44 (line 639):
   $1 = token '@' ()
   $2 = nterm param_list ()
   $3 = nterm anon_fcn_begin ()
   $4 = nterm expression ()
-> $$ = nterm anon_fcn_handle ()
Entering state 49
Stack now 0 8 49
Reducing stack by rule 135 (line 1019):
   $1 = nterm anon_fcn_handle ()
-> $$ = nterm expression ()
Entering state 89
Stack now 0 8 89
Reducing stack by rule 56 (line 700):
   $1 = nterm expression ()
-> $$ = nterm arg_list ()
Entering state 88
Stack now 0 8 88
Next token is token '@' ()
Reducing stack by rule 39 (line 609):
   $1 = nterm arg_list ()
-> $$ = nterm cell_or_matrix_row ()
Entering state 91
Stack now 0 8 91
Reducing stack by rule 35 (line 583):
   $1 = nterm cell_or_matrix_row ()
-> $$ = nterm cell_rows ()
Entering state 90
Stack now 0 8 90
Next token is token '@' ()
Error: popping nterm cell_rows ()
Stack now 0 8
Error: popping token '{' ()
Stack now 0
Shifting token error ()
Entering state 1
Stack now 0 1
Reducing stack by rule 296 (line 2286):
   $1 = token error ()
-> $$ = nterm parse_error ()
Entering state 72
Stack now 0 72
Reducing stack by rule 3 (line 437):
   $1 = nterm parse_error ()
Cleanup: discarding lookahead token '@' ()
Stack now 0
error: parse error:

  syntax error

>>> { @(x) sin(x) @(y) cos(y) }




Rik <rik5>
Group administrator
Wed 30 Jul 2025 03:14:47 PM UTC, comment #2: 

Interestingly, the interpreter correctly works with function handles.  See below:


x = { @sin @cos }
x =
{
  [1,1] = @sin
  [1,2] = @cos
}


It doesn't work with anonymous functions that have parameter lists.


{@(x) sin(x) @(x) cos(x)}
error: syntax error

>>> {@(x) sin(x) @(x) cos(x)}
                 ^


The ^ character shows that the interpreter doesn't recognize an '@' symbol in this position.  I'm adding jwe to the CC list for this because he understands this better.  Is it the lexer or the parser that isn't comprehending that an '@' symbol marks the end of the previous token (lexer) or expression (parser)?

Rik <rik5>
Group administrator
Wed 23 Jul 2025 09:50:01 AM UTC, comment #1: 

Confirmed.

I'm lowering the Priority and Severity since there is a simple workaround: use a delimiter such as ',' or ';' or '<RETURN>'.

Rik <rik5>
Group administrator
Tue 22 Jul 2025 08:49:34 PM UTC, original submission:  

The following way of constructing a cell array works in MATLAB R2024b


>> {@(x) sin(x) @(x) cos(x)}

ans =

  1x2 cell array

    {@(x)sin(x)}    {@(x)cos(x)}


but fails in Octave


octave> {@(x) sin(x) @(x) cos(x)}
error: syntax error

>>> {@(x) sin(x) @(x) cos(x)}



Thomas <kolmanthomas>

 

Attached Files

This item currently has no attached files.

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

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

Carbon-Copy List
  • -email is unavailable- added by rik5
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by kolmanthomas (Submitted the item)
  •  

    Votes

    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.

     

    History

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-07-30 rik5 Carbon-Copy- Added jwe
    2025-07-23 rik5 Priority5 - Normal 2
        StatusNone Confirmed
        Operating SystemMac OS Any
    2025-07-23 rik5 Severity3 - Normal 2 - Minor

    Back to the top

    Powered by Savane 3.16-8b18.
    Corresponding source code