Small_Page (3) - Linux Manuals
Small_Page: Brief Introduction to Small
NAME
Small_Page - Brief Introduction to Small This section describes the basics of Small, as compiled and interpreted with Embryo.
For the full documentation, of which this is a summary, see
This summary assumes that you are familar with C. For a full list of differences between C and Small, again, see the full documentation.
Variables
Types
There is only one type, known as the 'cell', which can hold an integer.Scope
The scope and usage of a variable depends on its declaration.
- *
- A local variable is normally declared with the new keyword. E.g.
new variable
Remember that the keywords above are to be used on their own. That is, for example:
Note:
A typical function declaration is as follows:
You can pass by reference. That is, the parameter you pass is changed outside of the function. For example:
To pass an array:
Note:
Small has the following control structures, which similar to their C counterparts:
The following preprocessor directives are available:
public testvar
new public testvar
Constants
You can declare constants in two ways:
new const var1 = 2
Arrays
To declare an array, append square brackets to the end of the variable name. The following examples show how to declare arrays. Note the use of the ellipsis operator, which bases the array based on the last two declared values:
new msg[] = 'A message.'
new ints[] = {1, 3, 4}
new ints2[20] = {1, 3} // All other elements 0.
new ints3[10] = {1, ... } // All elements = 1
new ints4[10] = {10, 20, ... } // Elements = 10 -> 100.
// The difference can be negative.
new ints5[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
Function Calls
testfunc(param) {
// Do something ...
// over a couple of lines.
}
testfunc(¶m) {
param = 10
// The passed variable will be set to 10 outside of the function.
}
testfunc(param[]) {
// Do something to the array
}
Control Structures.
if (expression) statement1 else statement2
switch (expression) {
case 0:
statement1 // Can only be one statement. Look Ma, no breaks!
case 1..3: // For values between 1 and 3 inclusive.
statement2
default: // Optional
statement3
}
while(expression) statement
do statement while (expression)
for (init_expression; before_iter_test_expression; after_iter_expression) statement
Preprocessor
#assert constant_expression
#define pattern replacement
#define pattern(%1,%2,...) replacement
#include filename
#if constant_expression
// Various bits of code
#else
// Other bits of code
#endif
#undef pattern