Basic types

One important element of making a program efficient, is to use correct types for your variables. When you've programmed for a while, type selection becomes natural, and you don't think much about it.

Some languages try to help the user by using automatic types. This is supposed to make it easier to write. P* does allow implicit converting between primitive types, but no variables can be typeless.

It is not much work to write int or string in front of a variable. A good thing about this is that it helps make programs more readable, and it's an easy way for developers to make programs efficient.

Variables in P* are stored in memory as their C/C++ equalient type. Size of the type depends on the platform the interpreter is compiled on.

Table 3.1. List of P* primitive types

NameDescriptionExampleC-equalient
intSigned integerint a = "-10";long int
uintUnsigned integeruint a = 10;long unsigned int
llintLong long signed integerllint a = "-10";long long int
lluintLong long unsigned integerlluint a = 10;long long unsigned int
floatSingle precision floating pointfloat a = "2.00003";float
doubleDouble precision floating pointdouble a = "2.00003";double
boolBoolean true or false (1 or 0)bool a = 1;bool
stringString valuestring text = "P* Web Programming Language";Uses <string> from C++

Example of usage of different data types

SCENE main {
	int base = 2;
	int exp = 1;
	int exp_max = 20;
	lluint result = 1;

	while (exp <= exp_max) {
		result *= base;
		echo "$base exp $exp is $result\n";
		exp++;
	}

}

/* This program will output: 
2 exp 1 is 2
2 exp 2 is 4
2 exp 3 is 8
2 exp 4 is 16
2 exp 5 is 32
2 exp 6 is 64
2 exp 7 is 128
2 exp 8 is 256
2 exp 9 is 512
2 exp 10 is 1024
2 exp 11 is 2048
2 exp 12 is 4096
2 exp 13 is 8192
2 exp 14 is 16384
2 exp 15 is 32768
2 exp 16 is 65536
2 exp 17 is 131072
2 exp 18 is 262144
2 exp 19 is 524288
2 exp 20 is 1048576
*/