Skip to content

Latest commit

 

History

History
180 lines (148 loc) · 2.74 KB

File metadata and controls

180 lines (148 loc) · 2.74 KB

ProXPL Cheatsheet

A quick reference guide for the ProX Programming Language (ProXPL).

1. Basics

Comments

// Single-line comment
/* Multi-line
   comment */

Variables

ProXPL uses let for mutable variables and const for constants.

let x = 10;
x = 20;

const PI = 3.14;
// PI = 3.14159; // Error: Assignment to constant

Data Types

  • Primitive: int, float, bool, string, null.
  • Composite: List, Dictionary (Map).
let isDone = true;
let count = 42;
let price = 19.99;
let name = "ProX";
let empty = null;
let list = [1, 2, 3];
// let map = {"key": "value"}; // (Syntax supported in some contexts)

2. Control Flow

If-Else

if (score > 90) {
    print("Excellent");
} else if (score > 50) {
    print("Pass");
} else {
    print("Fail");
}

Loops

// While Loop
let i = 0;
while (i < 5) {
    print(i);
    i = i + 1;
}

// For Loop
for (let j = 0; j < 5; j = j + 1) {
    print(j);
}

3. Functions

Declaration

func add(a, b) {
    return a + b;
}

let sum = add(5, 3);

Arrow Functions (Short syntax)

func square(x) => x * x;

4. Object-Oriented Programming

Classes

class Animal {
    func speak() {
        print("Generic sound");
    }
}

class Dog extends Animal {
    func speak() {
        print("Woof!");
    }
}

Instantiation

let d = new Dog();
d.speak(); // Output: Woof!

Usage of this

class Person {
    func setAge(a) {
        this.age = a;
    }
}

5. Context-Oriented Programming (COP)

Context & Layers

context MobileMode {
    layer Display {
        func render() {
            print("Mobile UI");
        }
    }
}

Dynamic Activation

activate(MobileMode) {
    render(); // Dispatches to MobileMode.Display.render
}

6. Standard Library

IO (std.io)

print("Hello World");       // Native print
// or
use std.io;
IO.println("Hello World");
let name = IO.readLine();

Math (std.math)

use std.math;

let maxVal = Math.max(10, 20);
let rand = Math.random(); 
let root = Math.sqrt(16);

Native Functions

Built-in global functions available without imports:

  • print(msg)
  • input(prompt)
  • to_string(value)
  • clock() - Returns current time
  • random(min, max) (If available in specific implementations)

7. Operators

  • Arithmetic: +, -, *, /, %
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: &&, ||, !

8. Example Program

// fib.prox
func fib(n) {
    if (n <= 1) return n;
    return fib(n - 1) + fib(n - 2);
}

func main() {
    print(fib(10));
}

main();