Functions/procedures
From dis-Emi-A
While programming there are two rather distinct types of subroutines that one rights:
- A function, which simply calculates a result without side-effects
- A procedure, which performs a series of operations
While in theory distinct, in actual practice it starts to become rather unclear, due to cacheing, mutable variables, remote calls, prompts, and whatnot. It is undecided as to whether a special mechanism is actually needed to distinguish these types -- we already know that a compiler will be able to determine the side-effects on its own and determine the best optimization strategy, but perhaps letting the user indicate the type may find more errors.
Given:
c = 0;
function sum( a, b )
{
c += 1;
return a + b;
}
The compile would be forced to just accept this, regardless of what the user intended, had a special flag been available the compiler could indicate the error.
c = 0;
function sum( a, b ) <pure>
{
c += 1;
return a + b;
}
ERROR: Cannot modify c in <pure> function.
