Computation Model¶
Graphcal programs describe a directed acyclic graph (DAG) of computations. This page covers the core model: declaration kinds, the @ sigil, evaluation semantics, and naming conventions.
Declaration Kinds¶
Every top-level declaration belongs to one of four kinds:
| Kind | Keyword | Semantics | In DAG? |
|---|---|---|---|
| Parameter | param |
User-supplied input, optionally with a default value | Yes |
| Node | node |
Computed value derived from other values | Yes |
| Constant | const node |
Compile-time immutable value | No |
| Assertion | assert |
Post-evaluation boolean check | No |
Parameters¶
param dry_mass: Mass = 1200.0 kg; // optional param (has default)
param fuel_mass: Mass; // required param (no default)
Parameters are the inputs to your computation graph. A param with a default value (= expr) can be overridden at runtime via --set or --input; params not overridden keep their defaults. A param without a default value is required — it must be provided via --set, --input, or a parameterized import binding. Evaluating a file with an unsatisfied required param is a compile error.
Parameters (and nodes) can carry domain constraints that declare valid value ranges, checked at runtime:
See Type System — Domain Constraints for details.
Nodes¶
Nodes are computed values. Their expressions can reference parameters, other nodes, and constants. Graphcal evaluates nodes in topological order determined by the dependency graph.
Constants¶
Constants are evaluated at compile time before the DAG is built. They cannot reference parameters or nodes (the @ sigil is prohibited in const node expressions).
Assertions¶
Assertions are post-evaluation checks. They can reference parameters and nodes but are not part of the DAG -- no other declaration can reference an assert. Assertions are always evaluated last, after the entire graph. See Assertions and Attributes for full details.
The @ Sigil¶
The @ prefix is the central scoping mechanism:
| Reference | Meaning | Allowed in |
|---|---|---|
@name |
Parameter, node, or const node in the graph | node expressions, dag block bodies |
@dag(args).out |
Inline DAG invocation projecting one output | Same as above |
NAME |
Built-in constant (PI, E, TAU, etc.) |
Everywhere |
name |
Local variable (loop variable, match binding) | Expression bodies |
Where @ Is Allowed¶
| Context | @ Allowed? |
|---|---|
node expression |
Yes |
param default value |
No |
const node expression |
No |
dag block body (inside node expressions) |
Yes |
Evaluation Order¶
- Parse -- Source files are parsed into an AST
- Resolve -- Names are resolved, imports are loaded
- Dimension check -- All expressions are checked for dimensional consistency
- Const evaluation -- Constants are evaluated in dependency order
- DAG construction -- A dependency graph is built from
paramandnodedeclarations - Topological evaluation -- Nodes are evaluated in topological order
- Assertion checking -- Assert declarations are evaluated and reported
Cycle Detection¶
Circular dependencies between nodes are detected at compile time:
Call-Site Identity¶
When a dag is instantiated — whether via top-level include or via the
inline @dag(args).out expression form — each syntactic call site is a
fresh instantiation. Two textually distinct occurrences with identical
arguments denote two distinct sub-graphs in the underlying DAG, not a shared
sub-graph. Programs must not rely on sharing across call sites.
An eval engine is free to detect structurally identical sub-graphs and reuse their computation as an internal optimization, but this is not part of the language semantics.
Fault Isolation¶
If a node's evaluation fails (e.g., division by zero), only that node and its dependents are affected. Independent nodes still evaluate successfully.
Naming Conventions¶
Graphcal recommends the following naming conventions:
| Declaration | Recommended Convention | Example |
|---|---|---|
param |
lower_snake_case |
dry_mass |
node |
lower_snake_case |
total_dv |
const node |
lower_snake_case |
g0, margin_factor |
assert |
lower_snake_case |
fuel_positive |
dag |
lower_snake_case |
orbital_velocity |
type |
PascalCase |
TransferResult |
dim |
PascalCase |
Velocity |
index |
PascalCase |
Maneuver |
unit |
(various) | km, kN, MPa |
These conventions are not enforced by the compiler, but following them is strongly recommended for consistency and readability.
Comments¶
Graphcal supports line comments: