octave-maintainers
[Top][All Lists]
Advanced

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

Re: problems to be fixed before next snapshot


From: John W. Eaton
Subject: Re: problems to be fixed before next snapshot
Date: Tue, 22 Oct 2002 22:33:40 -0500

On 22-Oct-2002, Paul Kienzle <address@hidden> wrote:

| I don't know if it is a problem, but the new behaviour of 
|       for [key,val] = struct
| is a bit disturbing to old code (or is it [val,key] --- I never remember).
| 
| val is now a cell array whereas old code expected it to be a octave value.
| 
| I understand why it has changed (how else can you process key,val pairs
| when struct is an array?), but I would rather that it didn't make
| the common case more awkward.  I don't have anything better to suggest
| in its place.

OK, this prompted me to find a couple more bugs in structs.  I've just
checked in some fixes to CVS.  Now we have

  octave:1> x(1).a = 1; x.a
  ans = 1
  octave:2> for [val, key] = x, val, key, end
  val = 1
  key = a
  octave:3> x(2).a = 2; x.a
  ans =
  (
    [1] = 1
    [2] = 2
  )
  octave:4> for [val, key] = x, val, key, end
  val =
  (
    [1] = 1
    [2] = 2
  )
  key = a

This makes the single-element structure array special.  I'm not sure
that's the best choice, but it is backward compatible and somewhat
convenient.

The only trouble is writing code that must work when the number of
elements in the struct array is sometimes one and sometimes more than
one...

Suggestions?

jwe



reply via email to

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