Variables
Variables are the fundamental building blocks used to store and manage data in TinyPanda.
TinyPanda discards generic keywords like var or let and uses bamboo keyword for variable declaration.
Declaration and Assignment
To create a variable, use the bamboo keyword followed by the variable name, an assignment operator (=), and the value you want to store.
syntax: bamboo <identifier> = <value>;
bamboo color = "green"; // string
bamboo number = 7; // integer
bamboo pi = 3.14; // float
bamboo isPandaHungry = true; // boolean
Storing Functions
Functions are first-class citizens, meaning they can be bound to variables just like strings or integers.
bamboo greet = fn(name) {
return "Hello, " + name + "!";
};
echoln(greet("Panda")); // Outputs: Hello, Panda!
Storing Conditional Results
Conditionals (iff statements) return the value of their executed block, allowing you to assign their outcome directly to a variable.
bamboo age = 15;
bamboo isAdult = iff (age > 18) {
true;
} otherwise {
false;
};
echoln(isAdult); // Outputs: false
Key Rules for Identifiers
When naming your variables (identifiers), keep these standard naming rules in mind:
- Must start with a letter (a-z, A-Z) or an underscore (
_) - Can contain numbers after the initial character
- Cannot use reserved language keywords (like
bamboo,fn,iff,otherwise) or builtins (likelength,num,string,string,echo,echoln)
Mutability
By default, variables declared with bamboo are mutable. This means you can overwrite their contents later in your program without re-declaring the keyword.
syntax: <identifier> = <new_value>;
// Initial assignment
bamboo state = "Panda Awake";
echoln(state); // Outputs: Panda Awake
// Re-assigning the variable
state = "Panda Sleeping";
echoln(state); // Outputs: Panda Sleeping
Scoping
TinyPanda uses block scoping. Variables declared inside curly braces {...} like inside a function fn or a conditional statement's block iff or otherwise are isolated inside those braces and cannot be accessed from outside of the block.
Lexical Scope
Think of scopes like nested boxes. Inner blocks can look "out" to read parent variables, but outer environments have no visibility into what happens inside an inner block.
bamboo global = "This is global scope";
iff (true) {
bamboo local = "This is local/block scope";
echoln(global);
}
// Resources created inside a block scope vanish once the block exits.
echoln(local); // Runtime Error: identifier not found: local