|
| 1 | +# ProXPL Cheatsheet |
| 2 | + |
| 3 | +A quick reference guide for the ProX Programming Language (ProXPL). |
| 4 | + |
| 5 | +## 1. Basics |
| 6 | + |
| 7 | +### Comments |
| 8 | +```javascript |
| 9 | +// Single-line comment |
| 10 | +/* Multi-line |
| 11 | + comment */ |
| 12 | +``` |
| 13 | + |
| 14 | +### Variables |
| 15 | +ProXPL uses `let` for mutable variables and `const` for constants. |
| 16 | +```javascript |
| 17 | +let x = 10; |
| 18 | +x = 20; |
| 19 | + |
| 20 | +const PI = 3.14; |
| 21 | +// PI = 3.14159; // Error: Assignment to constant |
| 22 | +``` |
| 23 | + |
| 24 | +### Data Types |
| 25 | +- **Primitive**: `int`, `float`, `bool`, `string`, `null`. |
| 26 | +- **Composite**: `List`, `Dictionary` (Map). |
| 27 | + |
| 28 | +```javascript |
| 29 | +let isDone = true; |
| 30 | +let count = 42; |
| 31 | +let price = 19.99; |
| 32 | +let name = "ProX"; |
| 33 | +let empty = null; |
| 34 | +let list = [1, 2, 3]; |
| 35 | +// let map = {"key": "value"}; // (Syntax supported in some contexts) |
| 36 | +``` |
| 37 | + |
| 38 | +## 2. Control Flow |
| 39 | + |
| 40 | +### If-Else |
| 41 | +```javascript |
| 42 | +if (score > 90) { |
| 43 | + print("Excellent"); |
| 44 | +} else if (score > 50) { |
| 45 | + print("Pass"); |
| 46 | +} else { |
| 47 | + print("Fail"); |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +### Loops |
| 52 | +```javascript |
| 53 | +// While Loop |
| 54 | +let i = 0; |
| 55 | +while (i < 5) { |
| 56 | + print(i); |
| 57 | + i = i + 1; |
| 58 | +} |
| 59 | + |
| 60 | +// For Loop |
| 61 | +for (let j = 0; j < 5; j = j + 1) { |
| 62 | + print(j); |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +## 3. Functions |
| 67 | + |
| 68 | +### Declaration |
| 69 | +```javascript |
| 70 | +func add(a, b) { |
| 71 | + return a + b; |
| 72 | +} |
| 73 | + |
| 74 | +let sum = add(5, 3); |
| 75 | +``` |
| 76 | + |
| 77 | +### Arrow Functions (Short syntax) |
| 78 | +```javascript |
| 79 | +func square(x) => x * x; |
| 80 | +``` |
| 81 | + |
| 82 | +## 4. Object-Oriented Programming |
| 83 | + |
| 84 | +### Classes |
| 85 | +```javascript |
| 86 | +class Animal { |
| 87 | + func speak() { |
| 88 | + print("Generic sound"); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +class Dog extends Animal { |
| 93 | + func speak() { |
| 94 | + print("Woof!"); |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +### Instantiation |
| 100 | +```javascript |
| 101 | +let d = new Dog(); |
| 102 | +d.speak(); // Output: Woof! |
| 103 | +``` |
| 104 | + |
| 105 | +### Usage of `this` |
| 106 | +```javascript |
| 107 | +class Person { |
| 108 | + func setAge(a) { |
| 109 | + this.age = a; |
| 110 | + } |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +## 5. Standard Library |
| 115 | + |
| 116 | +### IO (`std.io`) |
| 117 | +```javascript |
| 118 | +print("Hello World"); // Native print |
| 119 | +// or |
| 120 | +use std.io; |
| 121 | +IO.println("Hello World"); |
| 122 | +let name = IO.readLine(); |
| 123 | +``` |
| 124 | + |
| 125 | +### Math (`std.math`) |
| 126 | +```javascript |
| 127 | +use std.math; |
| 128 | + |
| 129 | +let maxVal = Math.max(10, 20); |
| 130 | +let rand = Math.random(); |
| 131 | +let root = Math.sqrt(16); |
| 132 | +``` |
| 133 | + |
| 134 | +### Native Functions |
| 135 | +Built-in global functions available without imports: |
| 136 | +- `print(msg)` |
| 137 | +- `input(prompt)` |
| 138 | +- `to_string(value)` |
| 139 | +- `clock()` - Returns current time |
| 140 | +- `random(min, max)` (If available in specific implementations) |
| 141 | + |
| 142 | +## 6. Operators |
| 143 | +- **Arithmetic**: `+`, `-`, `*`, `/`, `%` |
| 144 | +- **Comparison**: `==`, `!=`, `<`, `>`, `<=`, `>=` |
| 145 | +- **Logical**: `&&`, `||`, `!` |
| 146 | + |
| 147 | +## 7. Example Program |
| 148 | +```javascript |
| 149 | +// fib.prox |
| 150 | +func fib(n) { |
| 151 | + if (n <= 1) return n; |
| 152 | + return fib(n - 1) + fib(n - 2); |
| 153 | +} |
| 154 | + |
| 155 | +func main() { |
| 156 | + print(fib(10)); |
| 157 | +} |
| 158 | + |
| 159 | +main(); |
| 160 | +``` |
0 commit comments