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: Sun, 18 Nov 2012 09:52:50 -0800 (PST)




----- Original Message -----
> From: Jordi Gutiérrez Hermoso <address@hidden>
> To: address@hidden
> Cc: address@hidden
> Sent: Sunday, November 18, 2012 7:10 PM
> Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
> 
> On 18 November 2012 11:53, Dimitri Maziuk <address@hidden> wrote:
>>  On 11/17/2012 7:48 PM, Sergei Steshenko wrote:
>> 
>>>  In Octave structs are associative arrays.
>> 
>> 
>>  Is that documented somewhere or is it lie the rest of octave 
> "documentation"
>>  -- you're supposed to already know matlab?
> 
> Octave structs are not associative arrays. Part of their
> implementation detail is that C++'s std::map is used to implement
> them, and this is casually mentioned in the manual. SS has latched on
> to this statement and concluded Octave is like Perl, or it's buggy
> because it's not like Perl.
> 
> Octave's structs are supposed to look a lot more like C structs than
> like Python dictionaries or Perl hashes or PHP arrays.
> 
>>  Because it certainly explains why I can't have mixed-type fields in a
>>  struct.
> 
> The fieldnames in a struct are subject to the same constraints that
> variable names are. In essence, they have to start with a letter, no
> spaces, and may only contain letters, numbers, and underscores.
> 
> - Jordi G. H.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>


"The fieldnames in a struct are subject to the same constraints that variable 
names are" - no they are not:

octave:3> s = {}
s = {}(0x0)
octave:4> setfield(s, "foo bar", 123)
ans =

  scalar structure containing the fields:

    foo bar =  123

octave:5>          
.

And
 if you limited the fields to be just identifiers, you have introduced a
 show stopper bug because Octave is now deprived of normally working 
associative arrays.


Regards,
  Sergei.


reply via email to

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