// SPDX-License-Identifier: Apache-2.0
; specs/widgets/basics-if-and-else.t27 -- the infographic of lesson 14 of the t27 basics course (specs/course/t27-basics.t27)
; Source of truth for public/widgets/basics-if-and-else/ (gHashTag/trinity): scripts/widget-pages-from-spec.mjs compiles
; this file, checks its constants, evaluates the tests below and writes the page. tool.js is one import of
; ../infographic.js, which draws SAY_TABLE_* as a real
and SAY_FLOW_* as an SVG diagram with a
; , black and white, and holds no words of its own. ASCII only (L3), English only (LANG-EN).
; The lesson spec it illustrates: public/t27/files/specs/basics/14_if_and_else.t27.
; phi^2 + 1/phi^2 = 3 | TRINITY
module widget_basics_if_and_else;
pub const KIND : str = "widget-tool";
pub const ID : str = "basics-if-and-else";
pub const TITLE : str = "t27 basics 14: the shapes of a choice";
pub const DESCRIPTION : str = "Every form of if and switch the t27 compiler accepts, each checked with the real compiler. Lesson 14 of the t27 basics course.";
pub const IMAGE_ALT : str = "A black and white table of choice forms in t27: if with parentheses and else, if without parentheses, if as an expression, and switch with an else case, each with the compiler verdict; a diagram shows a value going down one of two paths.";
pub const HOOK : str = "if with or without parentheses, if as a value, switch with else: all four compile.";
pub const CATEGORY : str = "compiler";
pub const DATA_SOURCES : [2]str = ["The lesson spec public/t27/files/specs/basics/14_if_and_else.t27, compiled clean on 7 backends by public/t27/t27_compiler.wasm, whose tests pass in the site test runner", "Compiler verdicts, error lines, code and counts quoted on this page are what the same wasm answered in node 22 when the course was authored; words without a run behind them are said to be read, not run"];
pub const READS_LOCAL_FILES : bool = false;
pub const SENDS_NOTHING : bool = true;
; --- The table -----------------------------------------------------------------------------
pub const SAY_TABLE_CAPTION : str = "Choice forms, as the compiler answered";
pub const SAY_TABLE_HEAD : [2]str = ["Form", "Verdict"];
pub const SAY_TABLE_CELLS : [8]str = ["if (a > b) { } else { }", "Compiles on all 7 backends", "if a > b { }", "Compiles on all 7 backends", "return if (a > b) a else b;", "Compiles on all 7 backends", "switch (m) { 0 => 10, else => 20 }", "Compiles on all 7 backends"];
pub const K_TABLE_COLS : u8 = 2;
pub const K_TABLE_ROWS : u8 = 4;
pub const K_TABLE_CELLS : u16 = 8;
; --- The diagram and the note ----------------------------------------------------------------
pub const SAY_FLOW_TITLE : str = "if (a > b)";
pub const SAY_FLOW_STEPS : [3]str = ["Compare a and b", "True: return a", "False: return b"];
pub const K_FLOW_STEPS : u8 = 3;
pub const SAY_NOTE : str = "Each verdict is what t27_compiler.wasm answered for a function with that form.";
test the_cells_fill_whole_rows {
assert K_TABLE_ROWS * K_TABLE_COLS == K_TABLE_CELLS;
}
test the_table_has_a_body {
assert K_TABLE_ROWS > 0;
assert K_TABLE_COLS > 0;
}
test the_diagram_has_every_step {
assert K_FLOW_STEPS == 3;
assert K_FLOW_STEPS > 1;
}