dryLang
docsplaygrounddownloadgithub

Welcome

  • Home

Getting Started

  • Overview
  • Installation
  • CLI Usage

Basics

  • Overview
  • Variables
  • Data Types
  • Operators
  • Comments

Control Flow

  • Overview
  • Conditionals
  • Loops
  • Error Handling

Functions

  • Overview
  • Definition
  • Scope & Closures

Data Structures

  • Overview
  • Structs & Classes
Docs Menu

Welcome

  • Home

Getting Started

  • Overview
  • Installation
  • CLI Usage

Basics

  • Overview
  • Variables
  • Data Types
  • Operators
  • Comments

Control Flow

  • Overview
  • Conditionals
  • Loops
  • Error Handling

Functions

  • Overview
  • Definition
  • Scope & Closures

Data Structures

  • Overview
  • Structs & Classes

Structs & Classes

Structs

Declare a struct by name followed by fields in braces. No struct keyword needed.

drylang
User {
    name
    age
}

Instantiate like a function call — no new keyword:

drylang
p = User("Zaky", 25)
pt(p.name) // "Zaky"
pt(p.age)  // 25

Classes

Use cl to define a class with fields and methods. Methods use fn.

drylang
cl Calculator {
    fn add(a, b) {
        rev a + b
    }
}

calc = Calculator()
pt(calc.add(100, 50)) // 150

Inheritance

Classes can extend other classes using <-.

drylang
cl Animal {
    name
    fn speak() {
        rev "..."
    }
}

cl Dog <- Animal {
    fn speak() {
        rev "Woof!"
    }
}

Private Members

Use pv to mark fields or methods as private.

drylang
pv cl Internal {
    fn secret() {
        rev "hidden"
    }
}
PreviousOverview