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 11:33:28 -0700 (PDT)


--- On Mon, 8/8/11, John W. Eaton <address@hidden> wrote:

> From: John W. Eaton <address@hidden>
> Subject: Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, 
> sizeof(foo{:})
> To: "Sergei Steshenko" <address@hidden>
> Cc: "marco atzeri" <address@hidden>, "address@hidden" <address@hidden>
> Date: Monday, August 8, 2011, 11:04 AM
> On  8-Aug-2011, Sergei Steshenko
> wrote:
> 
> | comma separated list is _not_ converted when 'sizeof' is
> called, but
> | some _deafault_ conversion is called in case of
> | 
> | "
> | octave:4> foo_cs = foo{:}
> | foo_cs = a
> 
> The expression
> 
>   foo = {a, b, c}
>   foo{:}
> 
> behaves as if you had typed
> 
>   foo = {a, b, c}
>   a, b, c
> 
> In other words, a "comma-separated list" is a set of
> independent expressions, not a single expression.
> 
> If you write
> 
>   foo = {a, b, c}
>   x = foo{:}
> 
> This is equivalent to
> 
>   foo = {a, b, c}
>   x = foo{1}, foo{2}, foo{3}
> 
> but the results of the expressions foo{2} and foo{3} are
> not printed.

I doubt the correctness because of its incompleteness. Again, here is
the screen session:

"
octave:1> foo{1,1} = "a"
foo =
{
  [1,1] = a
}
octave:2> foo{1,2} = "b"
foo =
{
  [1,1] = a
  [1,2] = b
}
octave:3> foo{2,1} = [1 2]
foo =
{
  [1,1] = a
  [2,1] =

     1   2

  [1,2] = b
  [2,2] = [](0x0)
}
octave:4> foo_cs = foo{:}
foo_cs = a
octave:5> class(foo_cs)
ans = char
octave:6> type("foo_cs")
foo_cs is a variable
a

octave:7> numel(foo_cs)
ans =  1
octave:8> sizeof(foo_cs)
ans =  1
octave:9>   
".

Based on the above session I disagree with your statement in question:

"
> This is equivalent to
> 
>   foo = {a, b, c}
>   x = foo{1}, foo{2}, foo{3}
> 
> but the results of the expressions foo{2} and foo{3} are
> not printed.
",

base on what I _observe_ I claim:

This is equivalent to:

foo = {a, b, c}
x = foo{1} # _here_ is the difference with John's statement
# the above is just taking _only_ the first element from the list.

Because I see your statement (based on my observation) as wrong/disproved,
I claim that for the 'x' in your statement example, and for 'foo_cs'
in my example it is possible to be used as argument of 'sizeof', which
it is in practice.

I.e. according to my observations, the simplest conversion for comma
separated list is taking its first element, and that is proved/shown by

"
octave:4> foo_cs = foo{:}
foo_cs = a
octave:5> class(foo_cs)
ans = char
octave:6> type("foo_cs")
foo_cs is a variable
a

octave:7> numel(foo_cs)
ans =  1
octave:8> sizeof(foo_cs)
ans =  1
"

sequence, and 'sizeof' could have performed exactly the same conversion.

If Matlab doesn't allow "sizeof(foo{:})", it's a different story.

But from my observations there is no logical prohibition for
"sizeof(foo{:})" to work as "sizeof(foo{1})" _exactly_ because
"foo_cs = foo{:}" works as "foo_cs = foo{1}".


[snip]
> jwe
> 

Anyway, all this Matlab-like illogical behavior should be clearly
explained in documentation.

...

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
address@hidden:~/junk>
"

- my point is that converting a list into a scalar variable typically
happens by assigning to that variable the very first list element.

Behavior of "foo_cs = foo{:}" seems to follow the same pattern, that's
why I have that implicit conversion (taking the very first list element) in
mind also with respect to "sizeof(foo{:})" - take the first element from
'foo' and return number of bytes in it.


Regards,
  Sergei.


reply via email to

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