|
spudplate
Template scaffolding compiler for spudlang .spud files
|
let declares a new variable. A bare <name> = <expression> line replaces the value of an existing let binding.
Binds a fresh name to the value of an expression. The variable's type is inferred from the right-hand side and is fixed for the lifetime of the binding.
let declarations cannot collide with any visible binding (ask answers, other let names, repeat iterators, path aliases). Shadowing is rejected; see Scoping.
A let value is purely a derivation. There is no prompt, no side effect, no filesystem activity.
A bare <name> = <expression> line replaces the value of an existing let binding.
Rules:
let and visible in the current scope. Reassigning an undeclared name is a validation error.let bindings are mutable. ask answers, path aliases (as <name> on a mkdir or file), and repeat iterators are read-only.repeat body that targets an outer let mutates the outer binding. This is the basis of the accumulator pattern.The interpreter captures values at the moment each statement runs. Two reads of the same variable across a reassignment see the new value:
Each mkdir resolves its path before the next statement runs.
| If you want to... | Use |
|---|---|
Derive a value from earlier ask answers | let |
| Build up a value across loop iterations | let outside the loop, reassign inside |
| Give a name to a path you will reuse | as clause on mkdir or file |
Compute a default for an ask | default <expression> on the ask |
A let is preferable to inlining the same expression repeatedly: let dir = ... once, then refer to dir everywhere, gives a single point to change.
let-bound string can be used as a path root.