FUNCTION

 

| HOME |

There are 4 types of functions in Noobeed, namely

  • global function
  • class function
  • L function
  • user defined function

All function must immediately followed by a parenthesis, in which a set of arguments separated by a comma is given, if any.  A function might not have any argument at all, still a parenthesis is always required.

Global function

A global function is a stand alone function and it is the most well-known function being around since the inception of computer language.  An example is a global function to calculate an absolute value of a number, e.g.

                 ->a = abs(x)
 

At the Noobeed prompt, a user can list all available global functions by typing

                 ->list gfun
 

or

                 ->flist gfun

The first command lists the results on the screen, while the later lists them in an ASCII file, as a name "RPT.txt" in the current working directory.

 

Class function

A class function is not a stand alone function and it is called by an object.  This type of function only exists in object-oriented language.   A class function is called by first type the name of an object, followed by a dot sign, ".", then a class function name.  A parenthesis always comes at the end as usual.  An example is a class function is when a matrix object calls to an inverse function, "inv", to make another matrix.

                ->B = A.inv()
 

Here variable "A" is a Matrix object.  Since the "inv" class function will return the result as another matrix, therefore B is a matrix object.

At the Noobeed prompt, a user can list all available class functions by typing list cfun followed by a string containing the class name, of which its class function wanted to be listed.  for example,

                ->list cfun "matrix"

or

                ->flist cfun "matrix"

The first command list the results on the screen, while the later lists them in an ASCII file, as a name "RPT.txt" in the current working directory.

 

L function

An L function is not a stand alone function and it is called by an object.  In addition they are able to appear on the left hand side of an equal sign, "=".   Please be noted that an ordinary function, either global function, or class function, can only show up at the right hand side of the equal sign, "=", if any.

They are basically having the same name as those of member data of a class.  We use L function to change content or value of member data of an object.   An L function is called by first type the name of an object, followed by a dot sign, ".", then an L function name.  A parenthesis always comes at the end as usual.  An example is an L function is to assign a new coordinate of the lower left corner of an Image object, as follows.

                ->pt_new = Pt2D(100,300)
                ->Img.lower_left() = pt_new
 

Here "lower_left" is an L function of class image.  Now object "Img" will have its new coordinate of the lower left corner point at a coordinate (100,300).

At the Noobeed prompt, a user can list all the available L functions by typing list lfun followed by a string containing the class name, of which its class function wanted to be listed.  for example,

                ->list lfun "Image"

or

                ->flist lfun "Image"

The first command list the results on the screen, while the later lists them in an ASCII file, as a name "RPT.txt" in the current working directory.

 

User defined function

A user defined function consists of a collection of Noobeed statements, and very much looks like a program, with one exception that it always starts the first line with a command "Function" and ends with a "Return" command.  User defined functions must be saved on disk as files, before they can be used.

Here is an example of a user defined function to calculate the summation from one to any given number. 

                 Function double result = SUM(double n)
                     result = n/2*(n+1)
                 return
 

The above function is saved as a file called, "sum.fun".  Moreover it must be saved in the directory set by the command "set pathfun".  To see what is the current path for function, just type "set pathfun" followed by nothing.  Please note that the function file name extension is ".fun".  To use the function, we use a command "call".  Here is the way.

                 ->call a = sum(10)
                 ->print a
                      55.000


| HOME |