UNPKG

petcarescript

Version:

PetCareScript - A modern, expressive programming language designed for humans

135 lines (107 loc) 2.63 kB
# PetCareScript Syntax Guide ## Keywords PetCareScript uses unique keywords that make it different from other languages: ### Variable Declaration - `store` - instead of `let`/`var` ### Control Flow - `when` - instead of `if` - `otherwise` - instead of `else` - `repeat` - instead of `while` - `loop` - instead of `for` ### Functions and Classes - `build` - instead of `function` - `give` - instead of `return` - `blueprint` - instead of `class` - `self` - instead of `this` - `parent` - instead of `super` ### Logical Operators - `also` - instead of `&&`/`and` - `either` - instead of `||`/`or` ### Literals - `yes` - instead of `true` - `no` - instead of `false` - `empty` - instead of `null` ### I/O - `show` - instead of `print`/`console.log` ### Error Handling - `attempt` - instead of `try` - `catch` - catch errors - `finally` - finally block - `throw` - throw errors ### Flow Control - `break` - break from loops - `continue` - continue to next iteration ## Examples ### Complete Program Example ```pcs // Calculator blueprint blueprint Calculator { init() { self.result = 0; } add(a, b) { self.result = a + b; give self.result; } divide(a, b) { when (b == 0) { throw "Division by zero!"; } self.result = a / b; give self.result; } getResult() { give self.result; } } // Main program build main() { store calc = Calculator(); attempt { store sum = calc.add(10, 5); show "Sum: " + sum; store division = calc.divide(10, 2); show "Division: " + division; // This will throw an error calc.divide(10, 0); } catch (error) { show "Error: " + error; } finally { show "Calculation complete"; } } main(); ``` ### Array Processing ```pcs build processArray(arr) { store result = []; loop (store i = 0; i < size(arr); i = i + 1) { store item = arr[i]; when (typeOf(item) == "number") { when (item > 0) { push(result, item * 2); } } } give result; } store numbers = [1, -2, 3, -4, 5]; store doubled = processArray(numbers); show "Doubled positive numbers: " + join(doubled, ", "); ``` ### Object Manipulation ```pcs build createPerson(name, age, city) { give { name: name, age: age, city: city, greet: build() { give "Hello, I'm " + self.name; } }; } store person = createPerson("Alice", 25, "Boston"); show person.greet(); ```