[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 12:19:32 -0800 (PST) |
----- Original Message -----
> From: Sergei Steshenko <address@hidden>
> To: Jordi Gutiérrez Hermoso <address@hidden>; "address@hidden"
> <address@hidden>
> Cc: "address@hidden" <address@hidden>
> Sent: Sunday, November 18, 2012 7:52 PM
> Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
>
>
>
>
>
> ----- 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.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
Furthermore, this is what 'doc struct' says:
"
...
More realistically, all of the functions that operate on strings can
be used to build the correct field name before it is entered into the
data structure.
names = ["Bill"; "Mary"; "John"];
ages = [37; 26; 31];
for i = 1:rows (names)
database.(names(i,:)) = ages(i);
endfor
database
=> database =
{
Bill = 37
Mary = 26
John = 31
}
",
so, is Octave supposed to be limited to "Mary" and should not be able to use
"Last dance with Mary Jane" (
http://www.metrolyrics.com/last-dance-with-mary-jane-lyrics-tom-petty.html ) ?
Regards,
Sergei.
>
- Re: equivalent for C-style init: structname varname[] = {...} ?, (continued)
- Re: equivalent for C-style init: structname varname[] = {...} ?, Yury T., 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/15
- Re: equivalent for C-style init: structname varname[] = {...} ?, Sergei Steshenko, 2012/11/15
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/15
- Re: equivalent for C-style init: structname varname[] = {...} ?, Sergei Steshenko, 2012/11/16
- Re: equivalent for C-style init: structname varname[] = {...} ?, Ben Abbott, 2012/11/17
- Re: equivalent for C-style init: structname varname[] = {...} ?, Sergei Steshenko, 2012/11/17
- Re: equivalent for C-style init: structname varname[] = {...} ?, Dimitri Maziuk, 2012/11/18
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/18
- Re: equivalent for C-style init: structname varname[] = {...} ?, Sergei Steshenko, 2012/11/18
- Re: equivalent for C-style init: structname varname[] = {...} ?,
Sergei Steshenko <=
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/18
- Re: equivalent for C-style init: structname varname[] = {...} ?, Judd Storrs, 2012/11/19
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/19
- Re: equivalent for C-style init: structname varname[] = {...} ?, Judd Storrs, 2012/11/19
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/19
- Re: equivalent for C-style init: structname varname[] = {...} ?, Judd Storrs, 2012/11/19
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/19
- Re: equivalent for C-style init: structname varname[] = {...} ?, Judd Storrs, 2012/11/19
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/19
- Re: equivalent for C-style init: structname varname[] = {...} ?, Judd Storrs, 2012/11/19