help-octave
[Top][All Lists]
Advanced

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

Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{


From: Sergei Steshenko
Subject: Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:})
Date: Mon, 8 Aug 2011 22:20:08 -0700 (PDT)


--- On Mon, 8/8/11, Przemek Klosowski <address@hidden> wrote:

> From: Przemek Klosowski <address@hidden>
> Subject: Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, 
> sizeof(foo{:})
> To: "Sergei Steshenko" <address@hidden>, "address@hidden" <address@hidden>
> Date: Monday, August 8, 2011, 1:04 PM
> On 08/08/2011 02:33 PM, Sergei
> Steshenko wrote:
> 
> > FWIW, here is an example from Perl:
> >
> > "
> > address@hidden:~/junk>  perl -e 'my @x = (1, 2,
> 3); my ($y) = @x; print "\$y=$y\n"'
> > $y=1
> 
> I'm glad you brought up Perl because it clearly
> distinguishes those two 
> statements:
> 
> @a=1,2,3
> @a=(1,2,3)
> 
> Octave's cs-list is like the first expression.
> 

No, it is not. Or, rather, your statement is imprecise.

If you look at

@x = 1, 2, 3

, '@x' is still a _list_. But just of one element:

"
perl -e 'my @x = 1, 2, 3; my $n = scalar(@x); print "\$n=$n address@hidden@x\n"'
$n=1 @x=1
".

In Octave:

"
octave:1> foo = {1, 2, 3}
foo =
{
  [1,1] =  1
  [1,2] =  2
  [1,3] =  3
}
octave:2> foo_cs = foo{:}
foo_cs =  1
octave:3> numel(foo_cs)
ans =  1
octave:4> size(foo_cs)
ans =

   1   1

octave:5> sizeof(foo_cs)
ans =  8
octave:6>
",

foo_cs is by no means a list, it is a plain _scalar_ variable, i.e. it just
_one_ self-contained entity having no internal structure, it can _not_ be
indexed.


Back to Perl:

"
perl -e 'my @x = 1, 2, 3; my $n = scalar(@x); print "\$n=$n address@hidden@x 
\$x[0]=$x[0]\n"'
$n=1 @x=1 $x[0]=1
"
- '@x' _can_ be indexed, which proves is is still a list.

And you can push onto that '@x' list:

"
perl -e 'my @x = 1, 2, 3; my $n = scalar(@x); print "\$n=$n address@hidden@x 
\$x[0]=$x[0]\n"; push @x, 2; $n = scalar(@x); print "\$n=$n address@hidden@x 
\$x[0]=$x[0] \$x[1]=$x[1]\n"'
$n=1 @x=1 $x[0]=1
$n=2 @x=1 2 $x[0]=1 $x[1]=2
".

So, my point, as it was, still is: in Octave "foo_cs = foo{:}" takes the very 
first element of "foo{:}" and assigns it to LHS ("foo_cs: in this
case); LHS becomes a scalar variable, _not_ a list.

Regards,
  Sergei.





reply via email to

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