Waddle_Language/README.md

5.3 KiB

Waddle Programming Language

Overview

Waddle is a modern, expressive programming language designed to be intuitive, readable, and powerful. It combines elements of object-oriented and functional programming with a focus on clarity and developer productivity.

Key Features

Language Characteristics

  • Strong, static typing
  • Object-oriented with interface support
  • Functional programming constructs
  • Explicit error handling
  • Concise syntax

Core Design Principles

  • Readability first
  • Explicit over implicit
  • Minimal cognitive overhead
  • Flexible type system

Basic Syntax

Type Declaration

Basic type definition

Animal {
    // Type implementation
}

Inheritance

Animal/Dog {
    // Dog-specific implementations
}

Interface definition

@Mammal {
    // Interface methods
}

Interface implementation

Animal/Dog -> [Mammal, Domesticated] {
    // Multiple interface support
}

Functions

Function declaration

Public function (+fn)
+fn calculateArea(Integer width, Integer height) -> [Integer] {
    rtn width.multiply(height);
}
Protected Function (fn)
fn calculateArea(Integer width, Integer height) -> [Integer] {
    rtn width.multiply(height);
}
Private Function (-fn)
-fn calculateArea(Integer width, Integer height) -> [Integer] {
    rtn width.multiply(height);
}

Default Values

fn calculateArea(Integer width.default(0), Integer height.default(0)) -> [Integer] {
    rtn width.multiply(height);
}
Lambda expression
areaCalculator = fn(Integer width, Integer height) -> [Integer] {
    rtn width.multiply(height);
}

Concurrency Function (async)

+proc fetchData(String url) -> [String] {
    rtn my.network.get(url);
}

proc fetchData(String url) -> [String] {
    rtn my.network.get(url);
}

-proc fetchData(String url) -> [String] {
    rtn my.network.get(url);
}

Error Handling

Try/Catch (attempt->[ok, error])

result = riskyOperation().attempt {
    ok {
        // Successful execution
        my.output.print("Operation successful");
    }
    
    ValueError {
        // Handle specific value errors
        my.logger.log(error.getMessage());
    }
    
    error {
        // Catch-all error handling
        my.criticalLogger.alert("Unexpected error");
    }
}

Custom error type declaration

MathError {
    message: String;
    errorCode: Integer;
}

Function with explicit error handling

+fn divide(Integer a, Integer b) -> [Decimal] fails with MathError {
    if (b.eq(0)) {
        my.error.fail(MathError("Division by zero", 1));
    }
    rtn a.divide(b);
}

Resource Management / Context Management

using DatabaseConnection db.set(connectionString) {
    db.execute(query);
}

Iteration

Forward iteration

loop(i, 0->10) {
    my.output.print(i);
}

Foward iteration, with step

loop(i, 0->10, 2) {
    my.output.print(i); // outputs 0, 2, 4, 6, 8, 10
}

Reverse iteration

rloop(i, 10->0) {
    my.output.print(i);
}

Reverse iteration, with step

rloop(i, 10->0, 2) {
    my.output.print(i); // outputs 10, 8, 6, 4, 2, 0
}

Foreach loop on arrays

Integer<> nums.set(<1, 2, 3, 4>);

nums.each(
    i -> {
        if(i.mod(2).eq(0)){
            my.output.print(i); // outputs 2, 4
        }
    }
);

Boolean Expressions

Explicit Boolean Checks

result = Boolean.and(
    my.age.gt(18), 
    my.status.is(Verified)
);

Object Method Boolean Checks

if(my.age.gt(18).and(my.status.is(Verified))){
    my.age.gt(18), 
    my.status.is(Verified)
}

If conditionals

Plain If
if (x.gt(0).and(y.gt(0))) {
    rtn True;
}
If/Otherwise
if (x.gt(0).and(y.gt(0))) {
    rtn True;
} otherwise {
    rtn False;
}
If/Orif
if (x.gt(0).and(y.gt(0))) {
    rtn True;
} orif (x.lt(0).and(y.lt(0))) {
    rtn False;
}
If/Orif/Otherwise
if (x.gt(0).and(y.gt(0))) {
    rtn True;
} orif (x.lt(0).and(y.lt(0))) {
    rtn False;
} otherwise {
    rtn False;
}

Explicit Type Conversion

String myString.set(my.number.set(42).as(String));

Type System

Primitive Types

  • String
  • Integer
  • Decimal
  • Boolean

Advanced Types

  • Arrays: Type<>
  • Custom types
  • Interface types

Unique Language Constructs

Dot Notation Methods

  • All objects have built-in methods
  • Chainable method calls
  • Explicit operations
my.text.set("Hello")
    .concat(" World")
    .length();

Object Lifecycle

  • Explicit constructors: on_create
  • Explicit destructors: on_destroy

Planned Features

  • Enhanced concurrency support
  • Expanded standard library
  • Advanced module system

Installation

Detailed installation instructions will be added as the language develops

Contribution

Interested in contributing to Waddle?

  • Report issues on this repository
  • Submit pull requests
  • Provide feedback and suggestions

License

Read the LICENSE.md file

Current Status

Waddle is currently in active development. The language specification and implementation are evolving.