help-octave
[Top][All Lists]
Advanced

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

Re: equivalent for C-style init: structname varname[] = {...} ?


From: Sergei Steshenko
Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
Date: Thu, 15 Nov 2012 09:50:12 -0800 (PST)




----- Original Message -----
> From: Jordi Gutiérrez Hermoso <address@hidden>
> To: Sergei Steshenko <address@hidden>
> Cc: Yury T. <address@hidden>; "address@hidden" <address@hidden>
> Sent: Thursday, November 15, 2012 7:27 AM
> Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
> 
> On 14 November 2012 12:10, Sergei Steshenko <address@hidden> wrote:
>>  However, if the field is not known in advance or is not a bareword, one 
> needs to use 'setfield', 'getfield' - you saw them in my 
> example.
> 
> This is a lie:
> 
>    fieldname = "foo";
>    varname = 42;
>    s = struct();
>    s.(fieldname) = varname
> 
> - Jordi G. H.
>

It is still a truth in the sense for non-barewords one need parentheses while 
for barewords one doesn't need them.

I.e. there are three possible forms of syntax.

...

And how about this:

"
octave:3> s = struct();
octave:4> s.("foo bar") = "doo"
error: invalid structure field name `foo bar'
"

- why am I getting an error here ?

Now:

"
octave:5> s = struct();
octave:6> setfield(s, "foo bar", "doo")
ans =

  scalar structure containing the fields:

    foo bar = doo
"

- no error.

Tell me again how consistent struct behavior in Octave is.

Regards,
  Sergei.



reply via email to

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