Previous section To contents Next section

8.4 How to write a module

Here is an example of a simple module:
constant PI = 3.14159265358979323846264338327950;
float cos2(float f) { return pow(cos(f),2.0); }
if we save this short file as Trig.pmod we can now use this module like this:
int main()
{
    write(sprintf("%f\n",.Trig.cos2(.Trig.PI));
}
or like this:
import .Trig;

int main()
{
    write(sprintf("%f\n",cos2(PI));
}

Previous section To contents Next section