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

Collections

Arrays

Arrays are ordered lists of values. They can hold mixed types.

Creating Arrays

drylang
numbers [1, 2, 3, 4, 5]
names ["Zaky", "Andi", "Budi"]
mixed [42, "hello", t, [1, 2]]
empty []

Accessing Elements

Use bracket notation with a 0-based index:

drylang
colors ["red", "green", "blue"]

pt colors[0]    // red
pt colors[1]    // green
pt colors[2]    // blue

Modifying Elements

drylang
colors[0] = "crimson"
pt colors[0]    // crimson

Array Functions

FunctionDescriptionExample
len(arr)Get lengthlen([1,2,3]) → 3
add(arr, item)Append itemadd(arr, 4)
sort(arr)Sort (returns new)sort([3,1,2]) → [1,2,3]
pop(arr)Get last elementpop([1,2,3]) → 3
rm(arr, idx)Remove by indexrm([1,2,3], 1) → [1,3]
drylang
nums [3, 1, 4, 1, 5]

pt len(nums)       // 5
pt sort(nums)      // [1, 1, 3, 4, 5]
pt pop(nums)       // 5
pt rm(nums, 0)     // [1, 4, 1, 5]

Iterating Arrays

drylang
fruits ["apple", "banana", "cherry"]

lp len(fruits) {
  pt "${i}: ${fruits[i]}"
}
.Output:
  0: apple
  1: banana
  2: cherry
/*

Maps

Maps are key-value collections. Keys are strings.

Creating Maps

drylang
person {"name": "Zaky", "age": 17}
config {"host": "localhost", "port": 8080}
empty_map {}

Accessing Values

Two syntaxes are supported:

drylang
person {"name": "Zaky", "age": 17}

*/Dot access.
pt person.name     // Zaky

// Bracket access
pt person["name"]  // Zaky

Dot access is shorter and preferred for known keys. Bracket access is useful for dynamic keys:

drylang
field "name"
pt person[field]    // Zaky

Modifying Values

drylang
person.age = 18
person["email"] = "zaky@email.com"

Map Functions

FunctionDescriptionExample
len(map)Count entrieslen({"a": 1}) → 1
key(map)Get all keyskey({"a": 1}) → ["a"]
val(map)Get all valuesval({"a": 1}) → [1]
has(map, key)Check key exists—
drylang
config {"host": "localhost", "port": 8080}

pt len(config)     // 2
pt key(config)     // ["host", "port"]
pt val(config)     // ["localhost", 8080]

Iterating Maps

drylang
data {"a": 1, "b": 2, "c": 3}
keys key(data)

lp len(keys) {
  k keys[i]
  pt "${k}: ${data[k]}"
}

Nested Collections

Arrays and maps can be nested:

drylang
users [
  {"name": "Zaky", "age": 17},
  {"name": "Andi", "age": 20}
]

pt users[0].name       // Zaky
pt users[1]["age"]     // 20

matrix [[1, 2], [3, 4], [5, 6]]
pt matrix[0][1]        // 2
pt matrix[2][0]        // 5
PreviousStructsNextModules