bugGNU Octave - Bugs: bug #48064, for-loop over structure elements...

 
 

bug #48064: for-loop over structure elements behaves differently from document

Submitted by:  None
Submitted on:  Tue 31 May 2016 09:34:06 AM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Documentation
Status: FixedAssigned to: None
Originator Name: Wang SOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 4.0.2
Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Fri 17 Jun 2016 01:17:21 AM UTC, comment #10:

No, it is probably better just to delete it. Short is good :)

I'll close this as "fixed".

Lachlan Andrew <lachlan>
Project Member
Thu 16 Jun 2016 05:36:46 PM UTC, comment #9:

Ok, I deleted the entire paragraph on the stable branch, then came back here and noticed/remembered Lachlan's patch to reword it instead, sorry about that.

http://hg.savannah.gnu.org/hgweb/octave/rev/42929c66846d

If you think it's useful to add this back in to remind people about omitting output arguments for this syntax, we can do that.

Mike Miller <mtmiller>
Project Administrator
Sat 04 Jun 2016 01:11:54 PM UTC, comment #8:

I think that it currently does iterate over columns, as shown below.

It seems to be only the documentation that needs updating.

Lachlan Andrew <lachlan>
Project Member
Fri 03 Jun 2016 01:59:14 PM UTC, comment #7:

I'm guessing that the documented behavior was correct at some point, probably before struct arrays had been implemented and structures had to be scalars. It was also long before the "~ syntax" for omitting results or arguments.

I agree with comment #5. Iteration should work column-wise, the same as for other loops involving arrays.

John W. Eaton <jwe>
Project Administrator
Fri 03 Jun 2016 02:37:29 AM UTC, comment #6:

The attached patch updates the documentation. Feel free to suggest better wording.

(file #37364)

Lachlan Andrew <lachlan>
Project Member
Thu 02 Jun 2016 11:08:52 PM UTC, comment #5:

For other types of "x", such as a cell or an ordinary matrix of double,int*,char,logical,..., all of "for val=x", "for [val]=x" and "for [~]=x" iterate over x(:,1),x(:,2),...
Therefore, for a struct "x", all of the above for-loop should also iterate on x(:,1),x(:,2),... consistently.
Only "for [val,key]=x", "for [~,key]=x", "for [val,~]=x" and "for [~,~]=x" should iterate over x.a,x.b,...

So the current behavior does not need to change.
Only the document should be changed.

Anonymous
Thu 02 Jun 2016 01:31:15 PM UTC, comment #4:

I agree with you all.
a straightforward for loop with a struct array on the right hand side should iterate over the array (e.g. x(1), x(2), x(3), ...), not the struct key (e.g. x.a, x.b, x.c, ...).
Because if not so, there would be no way to distinguish which to iterate over.

Anonymous
Thu 02 Jun 2016 01:12:23 PM UTC, comment #3:

I agree with you all.
a straightforward for loop with a struct array on the right hand side should iterate over the array (e.g. x(1), x(2), x(3), ...), not the struct key (e.g. x.a, x.b, x.c, ...).
Because if not so, there would be no way to distinguish which to iterate over.

Anonymous
Thu 02 Jun 2016 02:51:20 AM UTC, comment #2:

I agree with Lachlan, eliminate any mention of the simplifications, except to remind users that an element of the array can be omitted with the ~ placeholder.

This doesn't work in any version of Octave I have access to, back to 3.6.4, not sure when it ever worked, if at all, or why it was documented or implemented as this special case. I think it's clear that a straightforward for loop with a struct array on the right hand side should just iterate over the elements of the struct array.

Mike Miller <mtmiller>
Project Administrator
Thu 02 Jun 2016 12:32:06 AM UTC, comment #1:

Matlab (R32013b) doesn't implement this feature, so we are not bound by compatibility issues.

My preference would be to change the documentation to
"Either the key or val variable may be replaced by a tilde."
or perhaps allowing only "[val]", but still making the brackets mandatory.

The alternative (making brackets optional) would require run-time processing to determine whether the RHS is a structure or an array, which would slow down the common case for a minor syntactic advantage in the (very?) rare case.

Lachlan Andrew <lachlan>
Project Member
Tue 31 May 2016 09:34:06 AM UTC, original submission:

PDF documentation says that
"The key variable may also be omitted. If it is, the brackets are also optional."
in section 10.5.1 Looping Over Structure Elements, page 168.

But the behavior is as follow
OK
OK
OK
cannot loop over elements
cannot loop over elements

Which is correct, the behavior or the document?

System information:
and Debian package status:

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by lachlan (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 10 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 17 Jun 2016 01:17:21 AM UTClachlanCategoryNone=>Interpreter
      Item GroupNone=>Documentation
      StatusPatch Submitted=>Fixed
      Open/ClosedOpen=>Closed
    Sat 04 Jun 2016 01:11:54 PM UTClachlanStatusConfirmed=>Patch Submitted
    Fri 03 Jun 2016 01:59:14 PM UTCjweStatusPatch Submitted=>Confirmed
    Fri 03 Jun 2016 02:37:29 AM UTClachlanAttached File-=>Added bug_48064_for_over_struct.cset, #37364
      StatusConfirmed=>Patch Submitted
    Thu 02 Jun 2016 02:33:39 PM UTCmtmillerDependencies-=>bugs #48089 is dependent
    Thu 02 Jun 2016 12:33:16 AM UTClachlanStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1