dryLang
docsplaygrounddownloadgithub

Getting Started

  • Home
  • Getting Started
  • Setup

Language Basics

  • Variables
  • Types
  • Operators
  • Comments
  • Strings

Control Flow

  • Control Flow
  • Loops

Advanced Concepts

  • Functions
  • Structs
  • Collections
  • Modules
  • HTTP Server
  • Database

Reference

  • Built-ins
  • Error Handling
  • Errors

Examples

  • Hello
  • Variables
  • Functions
  • Control Flow
  • Structs
  • Arrays Maps
  • Try Err
  • Imports
  • Math
  • Strings
  • Http Server
  • Database
  • File Io

Templates

  • Automation
  • Cli Tool
  • Crud
  • Fetch Json
  • File Server
  • Hello
  • Html Render
  • Rest Api
Docs Menu

Getting Started

  • Home
  • Getting Started
  • Setup

Language Basics

  • Variables
  • Types
  • Operators
  • Comments
  • Strings

Control Flow

  • Control Flow
  • Loops

Advanced Concepts

  • Functions
  • Structs
  • Collections
  • Modules
  • HTTP Server
  • Database

Reference

  • Built-ins
  • Error Handling
  • Errors

Examples

  • Hello
  • Variables
  • Functions
  • Control Flow
  • Structs
  • Arrays Maps
  • Try Err
  • Imports
  • Math
  • Strings
  • Http Server
  • Database
  • File Io

Templates

  • Automation
  • Cli Tool
  • Crud
  • Fetch Json
  • File Server
  • Hello
  • Html Render
  • Rest Api

Structs

Structs are user-defined data types with named fields.

Declaration

Declare a struct by naming it followed by field names in {}:

drylang
user {
  name
  age
  email
}

Or on one line:

drylang
user { name age email }

No types. dryLang is dynamically typed — fields accept any value.

Instantiation

Create an instance by providing the variable name, struct type, and field values:

drylang
user { name age email }

u user {
  name "Zaky"
  age 17
  email "zaky@example.com"
}

Accessing Fields

Use dot notation:

drylang
pt u.name     // Zaky
pt u.age      // 17
pt u.email    // zaky@example.com

Or bracket notation:

drylang
pt u["name"]    // Zaky

Modifying Fields

drylang
u.age = 18
u["email"] = "new@example.com"

Structs in Arrays

drylang
player { name score }

players [
  player { name "Zaky" score 100 },
  player { name "Andi" score 85 }
]

// Note: struct instances inside arrays work like maps
// Access via regular array indexing + dot notation:

.lp len(players) {
  pt players[i].name
.}

Under the Hood

Structs are internally represented as maps. A struct instance is a map with field names as keys. This means all map functions work on struct instances:

drylang
user { name age }
u user { name "Zaky" age 17 }

pt key(u)     // shows fields
pt len(u)     // 2 (plus __struct__ meta key)

Struct vs Map

FeatureStructMap
Declarationuser { name age }—
Creationu user { name "Zaky" }u {"name": "Zaky"}
Type identityYes (__struct__ meta)No
Dot access✅✅
Bracket access✅✅
Dynamic keys❌✅

Use structs when you want a named type with a fixed set of fields. Use maps when you need dynamic keys.

PreviousFunctionsNextCollections