pow2(x), which would return 2x.
You have two choices: first, you could create a library of
SPL-coded functions that would always be loaded into the
interpreter. It might contain a definition like this:
new pow2 := lambda x{ if (x = 0) { res := 1; } else { res := 2*pow2(x-1); } };
In this scenario, a user can use pow2 as if
they'd coded it themselves, without the hassle of actually
having to code it.
However, the above approach may not be efficient enough. If we put C++ code into the interpreter that computed pow2, it would be lots faster, because it wouldn't have the overhead of the interpretation process ... and because you can use some hardware tricks to compute pow2 extra fast. Thus, our second approach is to actually implement pow2 in C++ as part of our interpreter code, and have that executed whenever the SPL-programmer uses pow2. This is a builtin function.