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".
|
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.
|
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.
|
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.
|
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)
|
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.
|
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.
|
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.
|
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.
|
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.
|
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:
|