Caterpillar

Daily Thought - 2024-06-22

< back to list

Caterpillar has postfix operators and a stack-based evaluation model, but it isn't a stack-based language. It doesn't use a single data stack to pass arguments and return values between functions. Instead, it works much more like a conventional language, with named arguments and local scopes.

In Caterpillar, every function defines a number of named arguments. The following pseudocode (Caterpillar still does not have a syntax) shows what that could look like:

fn add ( a b ) { a b + }

The arguments are bound to the specified names, a and b, which can then be used as operands. The result of the + could be used as an operand for another operation, but in this case, since the function ends there, the unused operand is returned to the caller.

In a stack-based language, you could write the same function in a more compact way:

fn add { + }

Here, the same global stack is available to all functions, enabling this more compact representation. This has desirable properties, but since I found it too error-prone, it's out for now.

<< previous thoughtnext thought >>