"size(foo)" vs "size foo" (octave-3.4.3)

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

"size(foo)" vs "size foo" (octave-3.4.3)

Sergei Steshenko
Hello,

here is a screen session excerpt:

"
octave:18> size(foo)
ans =

   8192      1

octave:19> size foo
ans =

   1   3

octave:20>

".

I have no problem with
"

   8192      1
"
output - it is the way it is supposed to be.

OTOH, I do not understand the
"

   1   3
"
output. I don't understand it even more since:

"
octave:25> size(a234567)
ans =

   8192      1

octave:26> size a234567
ans =

   1   7
",

i.e. it looks like the second number ("3" in case of "size foo" and "7" in case of "size a234567" is the variable name length in characters.

And what does the first "1" mean in the "size foo" case ?


Is "size foo" output displayed the way it is supposed to be ?

If "size foo" is illegal, I'd prefer to see an error message. If it is legal, why the result is different from "size(foo)" ?



Thanks,
  Sergei.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

Sergei Steshenko




----- Original Message -----
> From: Sergei Steshenko <[hidden email]>
> To: "[hidden email]" <[hidden email]>
> Cc:
> Sent: Friday, February 3, 2012 5:39 PM
> Subject: "size(foo)" vs "size foo" (octave-3.4.3)
>
[snip]

Octave version is actually 3.4.2.

Regards,
  Sergei.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

Ismael Diego Nunez-Riboni
In reply to this post by Sergei Steshenko
> octave:18>  size(foo)
> ans =
>
>     8192      1

A matrix with 8192 rows and 1 column (i.e., a column vector)

>
> octave:19>  size foo
> ans =
>
>     1   3

A matrix with 1 row and 3 columns, i.e., the string "foo".

It seems that if you use "size" without the parenthesis it interpretes
the argument as a string...
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

Bård Skaflestad
In reply to this post by Sergei Steshenko
On Fri, 2012-02-03 at 16:39 +0100, Sergei Steshenko wrote:
> octave:18> size(foo)
> ans =
>
>    8192      1
>
> octave:19> size foo
> ans =
>
>    1   3

Of course.  Why does this surprise you?  Seriously.  You should learn
about the difference between function and command syntax.

A good place to start is

http://www.gnu.org/software/octave/doc/interpreter/Commands.html#Commands


Sincerely,
--
Bård Skaflestad <[hidden email]>
SINTEF ICT, Applied Mathematics

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

Jordi Gutiérrez Hermoso-2
In reply to this post by Ismael Diego Nunez-Riboni
On 3 February 2012 11:03, Ismael Núñez-Riboni <[hidden email]> wrote:
> It seems that if you use "size" without the parenthesis it interpretes the
> argument as a string...

This is true of *all* Octave functions.

    foo a b c d;

is *exactly the same* as

    foo("a", "b", "c", "d");

See here:

    http://www.gnu.org/software/octave/doc/interpreter/Commands.html

HTH,
- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

lukshuntim
On 02/04/2012 12:10 AM, Jordi Gutiérrez Hermoso wrote:

> On 3 February 2012 11:03, Ismael Núñez-Riboni <[hidden email]> wrote:
>> It seems that if you use "size" without the parenthesis it interpretes the
>> argument as a string...
>
> This is true of *all* Octave functions.
>
>     foo a b c d;
>
> is *exactly the same* as
>
>     foo("a", "b", "c", "d");
>
> See here:
>
>     http://www.gnu.org/software/octave/doc/interpreter/Commands.html
>
> HTH,
> - Jordi G. H.

Is there any (help) command/function to show whether a name is a
function or a command?

Regards,
ST
--
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

Jordi Gutiérrez Hermoso-2
On 3 February 2012 22:06,  <[hidden email]> wrote:

> On 02/04/2012 12:10 AM, Jordi Gutiérrez Hermoso wrote:
>> On 3 February 2012 11:03, Ismael Núñez-Riboni <[hidden email]> wrote:
>>> It seems that if you use "size" without the parenthesis it interpretes the
>>> argument as a string...
>>
>> This is true of *all* Octave functions.
>>
>>     foo a b c d;
>>
>> is *exactly the same* as
>>
>>     foo("a", "b", "c", "d");
>>
>> See here:
>>
>>     http://www.gnu.org/software/octave/doc/interpreter/Commands.html
>
>
> Is there any (help) command/function to show whether a name is a
> function or a command?

All functions are also commands. If a function only accepts string
arguments, it can be called with command syntax. But it's syntactical
to do, say,

    eig foo

even though it will fail because the eig function doesn't know what to
do with a string.

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

Carnë Draug-2
In reply to this post by lukshuntim
On 4 February 2012 03:06,  <[hidden email]> wrote:
> Is there any (help) command/function to show whether a name is a
> function or a command?

As Jordi as said, all functions are also commands.

Still, about your question, the usage line of functions and commands
help text will have the word "function" or "command" respectively
(although the first line says functino for both)

> help chdir
`chdir' is a built-in function

 -- Command:  cd dir
 -- Command:  chdir dir

> help plot
`plot' is a function from the file
/usr/local/share/octave/3.4.3-rc0/m/plot/plot.m

 -- Function File:  plot (Y)
 -- Function File:  plot (X, Y)
 -- Function File:  plot (X, Y, PROPERTY, VALUE, ...)
 -- Function File:  plot (X, Y, FMT)
 -- Function File:  plot (H, ...)
 -- Function File: H = plot (...)

Carnë
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

lukshuntim
In reply to this post by Jordi Gutiérrez Hermoso-2
On 02/04/2012 12:10 PM, Jordi Gutiérrez Hermoso wrote:

> On 3 February 2012 22:06,  <[hidden email]> wrote:
>> On 02/04/2012 12:10 AM, Jordi Gutiérrez Hermoso wrote:
>>> On 3 February 2012 11:03, Ismael Núñez-Riboni <[hidden email]> wrote:
>>>> It seems that if you use "size" without the parenthesis it interpretes the
>>>> argument as a string...
>>>
>>> This is true of *all* Octave functions.
>>>
>>>     foo a b c d;
>>>
>>> is *exactly the same* as
>>>
>>>     foo("a", "b", "c", "d");
>>>
>>> See here:
>>>
>>>     http://www.gnu.org/software/octave/doc/interpreter/Commands.html
>>
>>
>> Is there any (help) command/function to show whether a name is a
>> function or a command?
>
> All functions are also commands. If a function only accepts string
> arguments, it can be called with command syntax. But it's syntactical
> to do, say,
>
>     eig foo
>
> even though it will fail because the eig function doesn't know what to
> do with a string.
>
> - Jordi G. H.
>  

Thanks for a very clear explanation.

It seems then a command is in fact implemented as a function except that
this function can be called in the command *form* and behave correctly.
So just a convenience.

If this understanding is correct, then the command form of call should
be discouraged so as to avoid surprised results like "size foo". Maybe
the manual can be modified slightly to make it a bit clearer.

The beginning of "11.11 Commands" may look like

"If functions accept only strings as arguments, they can also be called
in the command form. That is, without the parenthesis and quotes. For
example, ..."

and adding a paragraph like

"While it is syntactical correct to call all functions in the command
form, a function which require an argument other than a string will fail
as it does not know what to do with a string. For example,

    eig hello

fails with the error message

    error: eig: wrong type argument `sq_string'"

at the end.

Regards,
ST
--

--
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: "size(foo)" vs "size foo" (octave-3.4.3)

lukshuntim
In reply to this post by Carnë Draug-2
On 02/04/2012 10:00 PM, Carnë Draug wrote:

> On 4 February 2012 03:06,  <[hidden email]> wrote:
>> Is there any (help) command/function to show whether a name is a
>> function or a command?
>
> As Jordi as said, all functions are also commands.
>
> Still, about your question, the usage line of functions and commands
> help text will have the word "function" or "command" respectively
> (although the first line says functino for both)
>
>> help chdir
> `chdir' is a built-in function
>
>  -- Command:  cd dir
>  -- Command:  chdir dir
>
>> help plot
> `plot' is a function from the file
> /usr/local/share/octave/3.4.3-rc0/m/plot/plot.m
>
>  -- Function File:  plot (Y)
>  -- Function File:  plot (X, Y)
>  -- Function File:  plot (X, Y, PROPERTY, VALUE, ...)
>  -- Function File:  plot (X, Y, FMT)
>  -- Function File:  plot (H, ...)
>  -- Function File: H = plot (...)
>
> Carnë
>

I think I now understand the help message. :-)

Thanks very much,
ST
--

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave