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: Wed, 14 Nov 2012 09:10:15 -0800 (PST)




----- Original Message -----
> From: Jordi Gutiérrez Hermoso <address@hidden>
> To: Yury T. <address@hidden>
> Cc: address@hidden
> Sent: Wednesday, November 14, 2012 5:46 PM
> Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
> 
[snip]
> 
> Look at the ingredients in there. First strfind to get the indices
> where that "Buffat" string appears,
[snip]
> 
> - Jordi G. H.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

Jordi, it appears you have difficulties understanding why and what for humans 
invented hash tables (AKA structs in Octave), and IMO it's a much bigger 
problem than my unwillingness to understand how struct arrays (do I name them 
correctly) work.

...

For Yuri. One of nuisances in Octave is "non-uniform" access to data in structs 
in Octave.

In Perl the following is valid:

my %hash = 
  (
  a_bareword => 1, # no quotes are necessary for 'a_bareword'
  'another_bareword' => 2, # but one use quotes if he/she wishes
  'number three' => 3 # but one must use quotes around strings which are not 
single bareword
  );

Correspondingly, access by single key is all the time using '{...}':

$hash{a_bareword} or $hash{'a_bareword'}, $hash{'number three'} - quotes are a 
must here.

In Octave if you have a known in advance bareword, i.e. literal one, things are 
easy - assuming 's' is a structure, the following:

s.some_field = 1;
foo = s.some_field;

are legal.

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.

My point is that syntactically in Octave access is variable (literal field or 
through functions), while in Perl it's uniform (through {<key>}).

Another rake to step on learning Octave. Another entry for the proposed "Octave 
traps".


Regards,
  Sergei.



reply via email to

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