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: Jordi Gutiérrez Hermoso
Subject: Re: struct arrays and cs-lists
Date: Tue, 13 Nov 2012 13:57:25 -0500

On 13 November 2012 13:13, Olaf Till <address@hidden> wrote:
> On Tue, Nov 13, 2012 at 12:54:09PM -0500, Jordi Gutiérrez Hermoso wrote:
>> On 13 November 2012 12:40, Olaf Till <address@hidden> wrote:
>> > On Tue, Nov 13, 2012 at 09:42:54AM -0500, Jordi Gutiérrez Hermoso wrote:
>> >> ...
>> >> The point is that I think struct arrays are best interpreted as cell
>> >> arrays where one dimension is indexed with strings instead of
>> >> positive integers. Indeed, the struct2cell and cell2struct functions
>> >> perform the conversion this way, by changing the way that one
>> >> dimension is indexed, whether with strings or positive integers. The
>> >> problem is that there seems to be no way to index struct arrays along
>> >> their string dimension
>> >
>> > If I understand you right --- there is a way, in the struct package:
>> > fields2cell works as struct2cell but you can specify (a) field(s). But
>> > you have to permute() the result if you want the original dimensions
>> > with only one field. If you think its worth I could add a compiled
>> > function for only one field which preserves the original dimensions.
>>
>> This sounds nice, but is this really how things would need to be? Are
>> the cs-lists you get from s.foo just a weird wart in the language?
>
> IMHO its vain to discuss this, as Octave adhers to Matlab language. So
> using a function for this is probably the only way.

Not at all. Just because Matlab is stupid doesn't mean Octave has to
be as stupid as Matlab in all cases. In this situation, I think
extending struct array indexing seems to make sense, since we're not
stepping on the toes of existing Matlab syntax, and it seems like the
most reasonable extension of the syntax.

We already have tons of little areas where Octave syntax is slightly
nicer than Matlab, and I think jwe's suggestion here makes sense. Most
people won't see it, but if you ever want saner struct array indexing,
you can use Octave's!

As jwe pointed out to me privately, this is also a good opportunity to
clean up the struct array implementation (without affecting semantics,
of course).

- Jordi G. H.


reply via email to

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