This page documents the extra commands from Small Calculator. These were taken from source code, pretty much as is, but styled to suite the web, and any spelling mistakes fixed. These were retrievable from the application itself by typing "help" follow by the command.
Available Commands
The list of available commands are as follows
BLOCK <statements> Executes a block of statements HELP [topic] Display help on topic DEFFNC <function> Defines a new function ECHO <text> Displays text on the line ECHOEXPR <cmd> Executes a command and displays the result EXEC <file> Executes a file of commands FUNCTIONS Displays all predefined functions IF <pred> Does a command on condition RETURN <val> Sets the return value RETURNEXPR <cmd> Sets the return value to the result of <cmd> Type "HELP <command>" to see infomation on a command
BLOCK
BLOCK {<cmd1>} {<cmd2>} ...
Executes a block of commands. The commands can be any statement including other block statements.
DEFFNC
DEFFNC <fnname>(<parameters>) = <command>
Defines a new function. The function name can only consist of letters and numbers. Only a maximum of 4 parameters can be used in the parameter list. Parameters are required to be referred to using $<par> in the function due to the interpretation of parameters.
Example:
deffnc test(x) = $x + 2 -- Adds two to any number deffnc sign(k) = if ($k < 0} {-1} {if {$k > 0} {1} {0}} -- Returns -1 if k is negative, 1 if k is positive and 0 if k is 0.
Functions can be recursive if using the "if" command.
ECHO
ECHO <string>
Displays a string on the console.
ECHOEXPR
ECHOEXPR <command>
Executes a command and displays the result on the console.
EXEC
EXEC <filename>
Executes a file of commands. Lines starting with ";" are considered comments. Lines ending with "" are considered incomplete and the next line is appended (after trimming) to the end of that line.
FUNCTIONS
functions
Displays all predefined functions. No user functions are included.
IF
IF {<cond>} {<truepart>} {<falsepart>}
If the result of <cond> is not zero, executes <truepart> which could be any statement, otherwise executes <falsepart>. If statements can be nested.
HELP
HELP [topic]
Displays a help topic on the console window. Use "HELP <command>" to find help on a particular command.
RETURN
RETURN <val>
Sets the return value to <val>.
RETURNEXPR
RETURNEXPR <cmd>
Sets the return value to the return value of <cmd>.