Docs / Statements

6. Functions & Classes

Regular functions in Dryad are Hoisted (can be invoked in the file before their syntactic declaration) and support optional named parameters and rest collectors (...rest). Dryad classes offer object-oriented programming with single inheritance (extends) and scope control (public, private, and protected).

Practical Example of Object-Oriented Programming
 1 class Retangulo {
 2   public largura = 0;
 3   private altura = 0;
 4 
 5   constructor(l: number, a: number) {
 6     this.largura = l;
 7     this.altura = a;
 8   }
 9 
10   public area(): number {
11     return this.largura * this.altura;
12   }
13 }
14 
15 class Quadrado extends Retangulo {
16   constructor(tamanho: number) {
17     super(tamanho, tamanho); // Chama construtor do pai
18   }
19 }
20 
21 let q = new Quadrado(5);
22 let area = q.area(); // Retorna 25

Use of encapsulated properties and private scope for local memory safety.

Concurrent Execution with OS Threads
 1 // Thread functions execute truly isolated in the OS
 2 let mu = mutex();
 3 let valorCompartilhado = 0;
 4 
 5 thread function processarParalelo(id: number) {
 6   mu.lock();
 7   valorCompartilhado++;
 8   mu.unlock();
 9   return id * 10;
10 }
11 
12 let handle1 = thread processarParalelo(1);
13 let handle2 = thread processarParalelo(2);
14 
15 // Async retrieval of return handles
16 let resultado = await handle1;

Control of critical sections accessed by multiple simultaneous OS threads through built-in Mutex primitives.

Found an error in the spec? Open a PR.
Official Version: 1.0 · May 2026