octave-maintainers
[Top][All Lists]

## RE: structure discussion

 From: John W. Eaton Subject: RE: structure discussion Date: Wed, 12 Oct 2005 14:51:36 -0400

```On 12-Oct-2005, Andy Adler wrote:

| On Tue, 11 Oct 2005, Paul Billings wrote:
|
| > Perhaps a more concise example: with version 2.1.71,
| >    clear g; g(1).a = g(2).a = 1;
| >    g(:).a = 2;  % does what you'd expect (both .a values are changed)
| >    g(:).b = 1   % does NOT do what I would expect
|
| FYI, Here is what the competition gives:
|
| >> clear g; g(1).a =1; g(2).a = 1;
| >> g(:).a = 2;  % does what you'd expect (both .a values are changed)
| ??? Insufficient outputs from right hand side to satisfy comma separated
| list expansion on left hand side.  Missing [] are the most likely cause.
|
| >> g(:).b = 1   % does NOT do what I would expect
| ??? Insufficient outputs from right hand side to satisfy comma separated
| list expansion on left hand side.  Missing [] are the most likely cause.

Both S(:).FIELD and S.FIELD produce comma-separated lists, which
cannot appear by themselves on the left side of an assignment.  In
Matlab, you can put a comma-separated list inside brackets to do an
assignment.  For example,

[S.FIELD] = RHS

where RHS is some expression that produces the same number of values
as appear in the comma-separated list produced by S.FIELD.  It's as if

[S(1).FIELD, S(2).FIELD, ... S(end).FIELD] = RHS

(Note that there is no magic assignment of a scalar value to all
elements of the comma-separated list.)

This construct does not work in Octave.  Doing it right does not seem
trivial.  Note that the expression inside the brackets can be
arbitrarily complex, so it seems that you have to partially evaluate
it to find out how many output arguments are expected so you can set
NARGOUT for the evaluation of the RHS.  This all has to happen before
the evaluation of a function call on the RHS of the assignment.

Yes, it appears there are some other bugs in Octave, apart from the
missing feature.  There should be some additional errors, since
assignment to a comma-separated list should fail.

jwe

```