|
spudplate
Template scaffolding compiler for spudlang .spud files
|
Declares a variable <name> and prompts the user at run time. The answer is the value bound to <name> and is read-only for the rest of the run.
| Clause | Effect |
|---|---|
options | Restrict valid answers to a fixed list, presented as a numbered menu |
default | Value used when the user submits an empty response |
when | Skip the prompt entirely if the condition is false; the default is bound instead |
Clause order is fixed: options first, then default, then when. The parser rejects other orderings.
| Type | Accepted input |
|---|---|
string | Any text |
bool | y, yes, true, n, no, false (case-insensitive). The hint shows [Y/n] for default true, [y/N] for default false, and [y/n] otherwise |
int | Decimal integer |
The declared type is fixed and enforced for default, options, and any later use of the bound value.
A question is required unless it has a default. A required question with empty input re-prompts.
Restricts the answer to a fixed list. The prompt is rendered as a numbered menu, and the user can type either the literal value or the menu index.
When both options and default are present, the default value must equal one of the listed options. The parser rejects mismatches.
default accepts any expression of the matching type, including references to earlier variables and function calls.
Type mismatches between the declared type and a literal default are caught at parse time. Mismatches against an identifier or expression default are caught at validate time.
Skips the prompt when the condition is false. A when-gated question must have a default. The default is bound when the gate is false, so later code always sees a real value.
If use_tests is false, num_weeks is bound to 0 without ever prompting.
ask is allowed inside a repeat body. Each iteration prompts afresh and binds a fresh value scoped to that iteration. The binding is gone at the next iteration, so the same ask cannot bind two values at once.
Prompts inside repeat are indented two spaces per nesting level. The static (N/M) counter sits next to an iteration K of L indicator, for example (3/7, iteration 2 of 4).
The no-shadowing rule still applies: an ask inside the body cannot reuse a name visible from the surrounding scope.
An ask inside an if body that has no inner when clause does not need a default: the if is the gate.
An ask inside if that also carries its own when clause still needs a default, because the inner gate can be false while the outer if is true.