[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: struct weirdness
From: |
Sergei Steshenko |
Subject: |
Re: struct weirdness |
Date: |
Sun, 2 Sep 2012 13:26:26 -0700 (PDT) |
--- On Sun, 9/2/12, Jordi Gutiérrez Hermoso <address@hidden> wrote:
> From: Jordi Gutiérrez Hermoso <address@hidden>
> Subject: Re: struct weirdness
> To: "Sergei Steshenko" <address@hidden>
> Cc: "address@hidden" <address@hidden>, "Przemek Klosowski" <address@hidden>
> Date: Sunday, September 2, 2012, 8:35 AM
> On 1 September 2012 19:54, Sergei
> Steshenko <address@hidden>
> wrote:
> > 26 samples =
> consistent_struct\
> > 27
> (
> > 28
> "patient", {"Bob", "Kevin", "Bob" ,
> "Andrew"},
> > 29
> "age", [
> 45 , 52 ,
> 45 , 23 ],
> > 30
> "protein", {"H2B", "CDK2" , "CDK2",
> "Tip60" },
> > 31
> "tube" , [
> 3 , 5 ,
> 2 , 18 ]
> > 32
> );
>
> Btw, since you don't seem to understand how struct is
> optimised for
> the array case (since, y'know, Octave is an array-oriented
> language),
> the scalar struct you want to create can be created with
> struct like
> so:
>
> samples = struct
> (
>
> "patient", {{"Bob, "Kevin", "Bob", "Andrew"}},
>
> "age", [45, 52, 45, 23],
>
> "protein", {{"H2B", "CDK2", "CDK2", "Tip60"}},
>
> "tube", [3, 5, 2, 18]
> );
>
> The part you don't understand is that the cell arguments of
> struct are
> turned into dimensions of the resulting struct array. When
> there is no
> cell argument (e.g. when it's an ordinary array instead of a
> cell),
> it's treated as a single element of a cell array. If you
> want to have
> cells inside the resulting struct, you have to nest them
> inside
> another cell, by doubling up the curly braces. The struct
> function is
> intended for struct arrays, but you hate struct arrays
> because you get
> confused when they give you cs-lists because you don't
> understand
> cs-lists, because you don't understand how cs-lists work
> inside other
> functions such as the size() function.
>
> Thank you for your guidance, however. Your efforts continue
> to improve
> Octave every day.
>
> - Jordi G. H.
>
"by doubling up the curly braces" - you still don't get.
I am lazy, and laziness, according to Larry Wall, is a programmer's virtue.
If I create the struct field by field, i do not need to double the curly
braces, and if I use you solution, I have to, and it sucks.
My function doesn't require doubling of curly braces.
I still suggest to implement my function in C++ in order to get rid of 'eval'
which is slow and "suspicious".
As I said, I want _consistency_ - I do not use double curly braces when filling
the struct field by field, and I do not want to use double curly braces when I
create the struct in one shot.
Regards,
Sergei.