octave-maintainers
[Top][All Lists]
Advanced

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

Re: struct arrays and cs-lists


From: John W. Eaton
Subject: Re: struct arrays and cs-lists
Date: Tue, 13 Nov 2012 13:26:39 -0500

On 13-Nov-2012, Jordi Gutiérrez Hermoso wrote:

| This sounds nice, but is this really how things would need to be?

Maybe not.

| Are the cs-lists you get from s.foo just a weird wart in the language?

I think they are.

You've said a number of times that a struct array is like a cell array
except that one index of the struct array is a character string.
That's a reasonable conceptual model, but as you see, the details
don't quite allow you to work with struct arrays in a way that fits
your conceptual model.

Currently, you can write

  s(i,j,k,...)

to index elements of a struct array for all fields.  Would it be
acceptable to extend this form of indexing to allow

  s(cellstr)

to index a struct array by fieldnames and

  s(cellstr, i, j, k, ...)

to index a struct array by fieldnames and element indices?  I haven't
given it a lot of thought, so maybe there are some problems with this
proposal that I'm not seeing.  But my first impression is that it
should be possible to make this form of indexing work and I think it
would give you the behavior that you want.

The cellstr index would have to contain a list of fieldnames contained
in the struct array S and the result would be another struct array.
As a special case, cellstr could also be a single character string if
you only need to index a single field.

jwe


reply via email to

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