|
|
Purpose
To declare a user-defined function.
A user-defined function must be stored in a file, with an extension of ".fun".
The "function" statement must appear right at the beginning of the file to let Noobeed know what is the name of the function, how many arguments, what type of argument and what type of the returning value of the function.
A function can have zero argument or it can have one or more arguments. Likewise a function can have one return variable or it can return nothing.
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
FUNCTION type ret = function_name(type argm1, type argm2, ...)
OR
FUNCTION function_name(type argm1, type argm2, ...)
function name = any valid function name
type = type of variable e.g. double, Matrix, etc.
ret = variable for function returning value
argm1, argm2,... = variables for function arguments
Example:
The following is a user-defined function program. It is going to be saved as a file, named "add.fun". Here is the content of the function.
/ This function takes two
arguments, both are of type double. / It adds them up, and return the result function double c = add(double a, double b) c = a + b return |
As shown above, the first line is to declare a function, by using command "FUNCTION". This is the function declaration statement, and it must come right at the beginning of the program. The name of the function, "add", must be used as the name of the external file name with an extension ".fun".
It is seen that a, b, and c are variable, whose type are "double". Variable a and b are argument variable, while variable c is the returning variable, a variable whose value is passed to the calling program.
Now, to call a user-defined function, we need command"CALL", as follows.
->x = 8 ->y = 9 ->call z = add(x,y) ->print z 17.00000 |
See also
call, return
Purpose
To call a user-defined function. Casting is provided for some data type, for example Matrices and basic numerical data types (double, float, int, etc.). However, casting is ONLY applicable for argument parsing, there is no casting provided for the returning variable. In other words, the type of returning variable must be the same as that is declared in the function prototype (Function statement).
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
Yes |
Usage
CALL {type} ret = function_name({type} argm1, {type} argm2, ...)
OR
CALL function_name({type} argm1, {type} argm2, ...)
function name = an existing user-defined function
type = type of variable e.g. double, Matrix, etc.
ret = variable for storing the function returning value
argm1, argm2,... = variables for function arguments
Example:
See the
example of the “function” command.
See also
function, return
Purpose
To end a
user-defined function.
Values of all arguments are passed back to the calling “call” statement and the execution will then jump back to the next statement of the last call command.
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
Function_statement
...
...
...
RETURN
Example:
See the
example of the “function” command.
See also
call, function
Purpose
To conditionally execute a statement or a block of statements. The command "if" will evaluate a logical expression next to it. Then, if the result is true, the program will execute all statements following the "if" statement. If it is false, the statement following the command "else" is executed.
In Noobeed, a logical expression is an expression that return a value of type "bool". Most relational operators make results of type "bool", e.g. a > 3, !(b==6). Some functions may also give results of type "bool", e.g. function "is_cover" of class Image.
It should be aware that Noobeed purposely does not provide a casting of a numeric result to type "bool" in this situation. This is to prevent an numerical expression to accidentally enter the "if" command.
All "if" statements must end with an "end" statement. This is actually the so-called "block-if" style. Even there is only one single statement, still an "end" statement is required.
The command "else" is optional. The program will jump to the statement next to the "end" statement, if an "else" statement is not present.
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
IF logical expression
...
...
ELSE
...
...
END
Example:
Example 1 |
Example 2 |
if a > 10 & c == 9 x = 5 y = 10 else x = -5 y = -10 end |
if a > 10 & c == 9 x = 5 y = 10 end
|
See also
Purpose
To repeat statements for a specific number of times. This is the so-called "for loop".
The command creates a counter variable, whose name is given by the user. The counter variable will be of type integer, "int". If the given variable already exists, it will be reset.
Then, the program will keep executing all statements between the "for" and the "end" command. Each time of execution, depending on the incremental value, the program will keep increasing, or decreasing the counter value until its value reaches a specific value, then the program will get out from the loop, and continue to execute the statement next to the "end" statement.
The last parameter, the incremental value, is an optional parameter. If not given, its default value is 1. In general, it may be a positive or negative number. If it is positive, the starting value, the first parameter, must be smaller than the ending value, the second parameter, otherwise there will be no execution inside the "for" loop. Similarly, when the incremental value is negative, the starting value must be larger than the ending value, or there will be no execution in the "for" loop.
All "for" statements must have an "end" statement associated with them, otherwise an error will be reported.
IMPORTANT try to not alter the counter of For Loop, unless really really needed. The user should be acknowledged that the counter of For loop is an integer. In case there is a need to change the value of the counter, the type of the counter should stay with the integer type. For example:
For i = 0, n-1
... do something
i = i + int(1)
...
The above example increases the value of the variable "i", the For loop counter, by one. To make sure that the type of the variable "i" is still interger, the INT function is used to cast the constant 1, which is usually considered as a double precision, to an interger constant. Therefore the result of the right hand side expression is integer, and so is the variable "i".
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
FOR counter = para1 , para2 [, para3]
...
...
END
counter = a variable
para1 = starting value of the counter
para2 = ending value of the counter
para3 = incremental value of the counter (default = 1)
Example:
Example 1 |
Example 2 |
/ This will execute 10 times n = 10 for i = 0, n-1 ... ... end |
for i = n1, n2, -10 ... ... end
|
See also
while
Purpose
To repeat a block of statements while a given condition is true. This is the so-called "while loop".
First of all the command evaluates an e logical expression following the "while" command. If it is true, the program will keep executing all statements between the "while" and the "end" command. Each time of execution, it will re-evaluate the condition again, and keep repeating this until the condition is false. Then the control will resume at the statement following the "end" statement.
In Noobeed, a logical expression is an expression that returns a value of type "bool". Most relational operators make results of type "bool", e.g. a > 3, !(b==6). Some functions may also give results of type "bool", e.g. function "is_cover" of class Image.
It should be aware that Noobeed purposely does not provide a casting of a numeric result to type "bool" in this situation. This is to prevent an numerical expression to accidentally enter the "while" command.
All "while" statements must have an "end" statement associated with them, otherwise an error will be reported.
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
WHILE logical expression
...
...
END
Example:
while stop == 0 sum = sum + 1 if sum > 100 stop = 1 end end |
See also
for
Purpose
To unconditionally exit the current loop, either "for loop" or "while loop".
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
WHILE_loop / FOR_loop
...
BREAK
...
end
Example:
while stop == 0 sum = sum + 1 if sum > 100 break end end |
See also
continue
Purpose
To unconditionally go to the top of the current loop, either "for loop" or "while loop". Hence it forces the program to reevaluate the condition of the loop again.
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
WHILE_loop / FOR_loop
...
CONTINUE
...
end
Example:
while stop == 0 sum = sum + 1 if sum < 100 continue else ... ... end end |
See also
break
Purpose
To temporary quit the current running program, and return to the Noobeed prompt. This provides an opportunity to debug a program, or to check values of variables in a program, or to alter values of variable in the program, or to make a temporary analysis in an interactive mode before resuming the program.
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
...
STOP
...
See also
resume
Purpose
To continue running the program at the point previously stopped by command "stop".
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
No |
Usage
RESUME
Example:
->resume
|
See also
stop
Purpose
To unconditionally quit the current running program, and return to the Noobeed prompt.
Please note that using command "exit" inside a function is not permitted, use command "return" instead.
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
...
EXIT
...
See also
stop, resume
Purpose
To prompt for a user input from the keyboard. The command needs at least one parameter, a variable name, to which an input value is stored. If desired, a text string prompt wanted to be printed out can be included in the command.
It should be noted that only variables of numerical type, e.g. double, float, int, etc. and "string" can be input by this command. Also, the type of variable must be explicitly declared by using the command "input". The reason that other types of data are not supported because it is not an efficient way due to complexity of data. However, most data type, classes, do have their own "load" and "save" functions, which are more efficient than keying data at the keyboard.
Where
Mode |
Yes/No |
at the interactive prompt |
No |
inside a program |
Yes |
Usage
INPUT {para1] para2
para1 = printout text prompt, must be a text constant or a string variable
para2 = variable name
Example:
Example 1 |
Example 2 |
Example 3 |
n = int() input "max no of point " n
|
x = double() text = "starting x coordinate = " input text x |
y = double() input y
|
See also
print, fprint
Purpose
To printout the value of a variable on the screen. The command needs at least one parameter, a variable name, of which its value will be printed out on the screen. If desire, a text string wanted to be printed out in front of the variable value can be included in the command.
It is possible to force Noobeed not to print a line-feed at the end of the print command. To do so, the user need to put a semi-colon sign, ";", right at the end of the command "print".
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
Yes |
Usage
PRINT [para1] para2
para1 = printout text, must be a text constant or a string variable
para2 = variable name
Example:
Example 1 |
Example 2 |
print "index = " ind
|
print "x = " x; print " y = " y |
See also
fprint
Purpose
To printout the value of a variable on the file. This command is almost the same as command "print", except that it writes the same output to the file, specified by command "set fout". The content is in ASCII format. The default file name is "RPT.txt", but the user can use command "set fout" to set the name to something else. This report file is in the current working directory, set by command "set path". If the file does not exist, Noobeed will create one.
The "fprint" command does not erase the previous content in the file, rather it appends the new output context to the end of the existing file. Once in a while, the user should go and clean up the file because Noobeed does not do it.
The command needs at least one parameter, a variable name, of which its value will be printed out to the report file. If desire, a text string wanted to be printed out in front of the variable value can be included in the command.
It is possible to force Noobeed not to print a line-feed at the end of the print command. To do so, the user need to put a semi-colon sign, ";", right at the end of the command "print".
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
Yes |
Usage
FPRINT [para1] para2
para1 = printout text, must be a text constant or a string variable
para2 = variable name
Example:
Example 1 |
Example 2 |
fprint "index = " ind
|
fprint "x = " x; fprint " y = " y |
See also
Purpose
To load a Noobeed program, in order to run it. The program must be store as a file.
If the given filename has no extension in it, Noobeed will assume an extension of ".prg". If the path name is not include in the filename, Noobeed will search the program in the current working directory, set by command "set path".
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
No |
Usage
LOAD para1
para1 = program file name, must be a string or a string variable
Example:
->load "hello_world" -> |
See also
run
Purpose
To load variables into Noobeed memory from a file. The file is created by command "save var", and it is an ASCII file.
If the given filename has no extension in it, Noobeed will assume an extension of ".txt". If the path name is not include in the filename, Noobeed will search the program in the current working directory, set by command "set path".
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
Yes |
Usage
LOADVAR para1
para1 = variable file name, must be a string or a string variable
Example:
->loadvar
"my_variable" -> |
See also
save var
Purpose
To run a Noobeed program. Before a program can be run, it must be loaded, by using command "load".
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
No |
Usage
RUN
Example:
->load "hello_world" ->run -> |
See also
load
Purpose
To save current variables, working history, or working path in a file.
The command "save" must follow immediately by either "var", or "hist" or "init", then followed by an output filename.
If the given filename has no extension in it, Noobeed will assume an extension of ".txt" for "save var" and save "iniit", and it will assume an extension of ".prg" for "save hist". If the path name is not include in the filename, Noobeed will create the file in the current working directory, set by command "set path".
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
Yes |
Usage
SAVE para1 para2
para1 = save option, must be VAR or HIST or INIT
para2 = output file name, must be a string or a string variable
Example 1 (for save var):
->a = 67 |
The above will craete a file, "my_variable.txt". Its contents, which is in ASCII format, are as follows.
a
DOUBLE 6.700000000000000e+001 |
Example 2 (for save hist):
->a = 67 |
The above will craete a file, "my_history.prg". Its contents, which are in ASCII format, are as follows.
Vector size : 50
|
Example 3 (for save init):
->set path
"d:\" |
The above will craete a file, "my_init.txt". Its contents, which is in ASCII format, are as below. This is the initialize file for Noobeed. Every time Noobeed is run, it will look for the file "nb.ini", in the same directory where the Noobeed program is. If it exists, the information about the working path, program path and function path will be read and set by Noobeed. If the initialize file does not exist, it will set all the three path to the same directory where the Noobeed program is.
nb.ini |
See also
loadvar, set
Purpose
To clear one or more variables.
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
Yes |
Usage
CLEAR ALL
OR
CLEAR var1 var2 var3 ...
var1, var2, var3... = variable names
Example:
Example 1 |
Example 2 |
clear all |
clear a b c Mat_1 Mat2 |
See also
list var
Purpose
To quit Noobeed and return to the system.
Where
Mode |
Yes/No |
at the interactive prompt |
Yes |
inside a program |
No |
Usage
QUIT
Example:
->quit
|
See also