octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: structure discussion


From: Paul Billings
Subject: RE: structure discussion
Date: Wed, 12 Oct 2005 09:05:13 -1000

This is one of those times that I appreciate Octave's syntax over ML:
  for(i=1:length(g)) g(i).a = 2; end;  % ML is plain *ugly*
  g(:).a = 2;  % Octave is nice!
  g.a = 2;  % Would be even nicer, see below

In an response, I said, "I disagree with your second point: I think the
notation "g.b = 1" is ambiguous and should be an error regardless of the
existance of .b.  "
I have to retract this now that I have thought about it.  I think "g.a"
should be equivalent to g(:).a.

In one sense, this agrees with the matrix precedent.  In that case, index
dereferencing is analogous to the structure referencing:
  a = reshape(1:9, [3 3]);
  a(6) is equivalent to a(:)(6)
  a.b should be equiv. to a(:).b, IMO.

Paul




> -----Original Message-----
> From: Andy Adler [mailto:address@hidden
> Sent: Wednesday, October 12, 2005 8:31 AM
> To: Paul Billings
> Cc: address@hidden
> Subject: RE: structure discussion
>
>
> 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.
>
> --
> Andy Adler <address@hidden> 1(613)562-5800x6218
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]