Strange syntax

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

Strange syntax

bigmealy
Hi,

I am currently trying to understand what is happening in line 59 of the file delaunayn.m
Firstly, I can't find any documentation around "__delaunayn__" as a seperate function, so I can only assume that it's some special syntax relating to the function itself. Can anyone shed any light?
I've also tried applying the curly braces modifier to my data to see what the effect there is, but it tells me "matrix cannot be indexed with {". Again, can anyone shed any light?

Many thanks,

Bigmealy

    53 function T = delaunayn (pts, varargin)
    54
    55   if (nargin < 1)
    56     print_usage ();
    57   endif
    58
    59   T = __delaunayn__ (pts, varargin{:});
Reply | Threaded
Open this post in threaded view
|

Re: Strange syntax

Sergei Steshenko




----- Original Message -----

> From: bigmealy <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Wednesday, November 28, 2012 12:55 PM
> Subject: Strange syntax
>
> Hi,
>
> I am currently trying to understand what is happening in line 59 of the file
> delaunayn.m
> Firstly, I can't find any documentation around "__delaunayn__" as
> a seperate
> function, so I can only assume that it's some special syntax relating to the
> function itself. Can anyone shed any light?
> I've also tried applying the curly braces modifier to my data to see what
> the effect there is, but it tells me "matrix cannot be indexed with
> {".
> Again, can anyone shed any light?
>
> Many thanks,
>
> Bigmealy
>
>     53 function T = delaunayn (pts, varargin)
>     54
>     55   if (nargin < 1)
>     56     print_usage ();
>     57   endif
>     58
>     59   T = __delaunayn__ (pts, varargin{:});
>
>
>
> --
> View this message in context:
> http://octave.1599824.n4.nabble.com/Strange-syntax-tp4647311.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

Regarding '{:}' - look up cell arrays in Octave documentation.

Regarding '__delaunayn__' - it's a "private" function not intended to be used directly by end user, that's why it is not documented.

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: Strange syntax

bigmealy
Sergei Steshenko-2 wrote
----- Original Message -----
> From: bigmealy <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Wednesday, November 28, 2012 12:55 PM
> Subject: Strange syntax
>
> Hi,
>
> I am currently trying to understand what is happening in line 59 of the file
> delaunayn.m
> Firstly, I can't find any documentation around "__delaunayn__" as
> a seperate
> function, so I can only assume that it's some special syntax relating to the
> function itself. Can anyone shed any light?
> I've also tried applying the curly braces modifier to my data to see what
> the effect there is, but it tells me "matrix cannot be indexed with
> {".
> Again, can anyone shed any light?
>
> Many thanks,
>
> Bigmealy
>
>     53 function T = delaunayn (pts, varargin)
>     54
>     55   if (nargin < 1)
>     56     print_usage ();
>     57   endif
>     58
>     59   T = __delaunayn__ (pts, varargin{:});
>
>
>
> --
> View this message in context:
> http://octave.1599824.n4.nabble.com/Strange-syntax-tp4647311.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

Regarding '{:}' - look up cell arrays in Octave documentation.

Regarding '__delaunayn__' - it's a "private" function not intended to be used directly by end user, that's why it is not documented.

Regards,
  Sergei.
Hi Sergei,

Many thanks for the information. A great help to me.

BM
Reply | Threaded
Open this post in threaded view
|

Re: Strange syntax

Juan Pablo Carbajal-2
In reply to this post by bigmealy
On Wed, Nov 28, 2012 at 11:55 AM, bigmealy
<[hidden email]> wrote:
> T = __delaunayn__ (pts, varargin{:});

__delaunayn__ is an private function and are usssually not doucmented.
In this case it doesn't matter casue the .m fuction is just a wrapper
for it, so the help in the .m function is describing the private
function.

Now, there is not such a thing as curly braces modifier. The curly
braces are used to index (i.e. access the elements) of cells, which
are a type of general container in Octave (like vector from the C++
STL). Wehn a function can take an undefined number of input arguments
we use the varargin (variable input arguments) in its signature. The
variable varargin, inside a function, contains the arguments that were
passed to the function. For example, assme that a function foo was
defined with "function foo (x,varargin)" then

foo (1)

will have x==1 and varargin empty inside foo.

foo (1,"bar",3)

will have x==1 and varargin == {"bar", 3} inside foo.

When a cell is indexed with the colon operator ":", it gives all its
elements. Assume that foo as defined before calls, in its body, a
function bar with signature "function bar (x,y)". The call

bar (varargin{:})

is equivalent to

bar ("bar", 3)

To know more about cells read the Octave manual.
http://www.gnu.org/software/octave/doc/interpreter/Indexing-Cell-Arrays.html

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

Re: Strange syntax

bigmealy
Juan Pablo Carbajal-2 wrote
On Wed, Nov 28, 2012 at 11:55 AM, bigmealy
<[hidden email]> wrote:
> T = __delaunayn__ (pts, varargin{:});

__delaunayn__ is an private function and are usssually not doucmented.
In this case it doesn't matter casue the .m fuction is just a wrapper
for it, so the help in the .m function is describing the private
function.

Now, there is not such a thing as curly braces modifier. The curly
braces are used to index (i.e. access the elements) of cells, which
are a type of general container in Octave (like vector from the C++
STL). Wehn a function can take an undefined number of input arguments
we use the varargin (variable input arguments) in its signature. The
variable varargin, inside a function, contains the arguments that were
passed to the function. For example, assme that a function foo was
defined with "function foo (x,varargin)" then

foo (1)

will have x==1 and varargin empty inside foo.

foo (1,"bar",3)

will have x==1 and varargin == {"bar", 3} inside foo.

When a cell is indexed with the colon operator ":", it gives all its
elements. Assume that foo as defined before calls, in its body, a
function bar with signature "function bar (x,y)". The call

bar (varargin{:})

is equivalent to

bar ("bar", 3)

To know more about cells read the Octave manual.
http://www.gnu.org/software/octave/doc/interpreter/Indexing-Cell-Arrays.html

Cheers
Many thanks for taking the time to reply JP, things are becoming more apparent to me v-quickly. I've never seen/heard of Octave till a few days ago. Fantastic!
Reply | Threaded
Open this post in threaded view
|

Re: Strange syntax

Jordi Gutiérrez Hermoso-2
In reply to this post by Juan Pablo Carbajal-2
On 28 November 2012 06:15, Juan Pablo Carbajal <[hidden email]> wrote:
> Now, there is not such a thing as curly braces modifier. The curly
> braces are used to index (i.e. access the elements) of cells, which
> are a type of general container in Octave (like vector from the C++
> STL).

A cell array consists of cells (I think the Mathworks took the name
inspired by cells in spreadsheets) which can contain any data type.
Cell arrays are always at least two dimensional, like every other
Octave type, including structs and strings and ordinary numerical
arrays.

Unlike a C++ vector, a single cell array can contain different types.
The type that a C++ vector contains is part of the vector's type, so
std::vector<int> and std::vector<char> are different and generally
incompatible types.

> When a cell is indexed with the colon operator ":", it gives all its
> elements.

To be clear, when a cell array is indexed with curly braces and a {},
the cells get "unpacked" into comma-separated lists (cs-lists).
When a cell array is indexed with (), you get a subcell array. Compare

    {1, [1 2; 3 4], "hello}{1:2}

with

    {1, [1 2; 3 4], "hello}(1:2)

As Juan Pablo explains below, the unpacked cells in cs-lists usually
have semantics equal to syntactically typing out each of the cells
individually.

> Assume that foo as defined before calls, in its body, a function bar
> with signature "function bar (x,y)". The call
>
>      bar (varargin{:})
>
> is equivalent to
>
>      bar ("bar", 3)
>
> To know more about cells read the Octave manual.
> http://www.gnu.org/software/octave/doc/interpreter/Indexing-Cell-Arrays.html

I am working on improving the Octave manual to give a better overview
of the basic Octave types.

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