The Dream language¶
Dream is statically typed and compiles ahead of time to a native binary or to WebAssembly. Memory is managed automatically by reference counting. Each page below covers one feature, with examples you can run.
Badges show where a feature works: Native for desktop executables, Browser and Node for WebAssembly output. New to Dream? Take the language tour first.
Basics
Variables, operators, control flow, and the everyday building blocks.
- VariablesName values with
letandconst, with types inferred for you. - OperatorsArithmetic, comparison, logical, and assignment operators.
- Control flowChoose with
ifandswitch, repeat with loops. - Names, types, and sizesInspect a name, type description, or storage size with
nameof,typeof, andsizeof. - CommentsLeave notes for readers and document public declarations.
Functions
Declare functions, pass arguments, use closures, and produce lazy sequences.
- FunctionsDeclare reusable work with
fun, parameters, and return types. - Function parametersDefaults, named arguments, repeated arguments, and borrowing.
- Function valuesStore and pass functions, and capture surrounding values in closures.
- Yield and iteratorsProduce lazy sequences one element at a time with
yield.
Types
Primitives, arrays, ranges, tuples, options, classes, structs, enums, and casts.
- PrimitivesIntegers, decimals, booleans, characters, and their methods.
- ArraysFixed-size, ordered values of one type.
- RangesReusable integer range values with exclusive ends.
- SpansViews into part of a string, array, or list without copying.
- Enums and unionsNamed choices, optionally carrying data, handled with
switch. - Classes and structsGroup fields and methods into shared objects or copied values.
- The object typeHold a value of any type and check it before use.
Abstraction
Generics, interfaces, and custom operators for reusable code.
Concurrency
Async functions, tasks, structured scopes, cancellation, and worker pools.
- Async / AwaitWrite work that waits without blocking, using futures and
await. - TasksRun CPU work in parallel on runtime workers.
- Structured concurrencyOwn concurrent work with
Task.scopeso nothing outlives its parent. - Task cancellationGive long-running work a way to stop cleanly.
- Task sharingShare values between tasks and protect changes with locks.
- Task poolsReuse a fixed set of workers for parallel CPU jobs.
Memory
Automatic reference counting, ownership, safety rules, and cleanup timing.
- OwnershipWhat happens when you assign a value or pass it to a function.
- Memory safetyThe rules that prevent invalid memory access in ordinary code.
- Reference cyclesBreak strong cycles with
weakandunownedlinks. - Raw buffersManual memory operations for custom containers.
- Cleanup timingDefer cleanup to avoid pauses during sensitive work.
Metaprogramming
Generate or rewrite Dream code while your program builds.
Interop
Call JavaScript with ordinary Dream syntax.
- The js typeRead, call, and change live JavaScript values with ordinary syntax.
- CallbacksPass functions across the Dream and JavaScript boundary.
- CCall C and C++ sources and system libraries from Dream.
- Native callbacksLet a native library call a Dream function safely.
- C++ librariesWrap a C++ library: accepted types, ownership, callbacks, and errors.
- Standalone WASICompile command components and grant filesystem and network access.
Language rules
Modules, imports, panics, and the rules behind compiler errors.