// SPDX-License-Identifier: Apache-2.0 ; specs/widgets/basics-local-names.t27 -- the infographic of lesson 13 of the t27 basics course (specs/course/t27-basics.t27) ; Source of truth for public/widgets/basics-local-names/ (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/13_local_names.t27. ; phi^2 + 1/phi^2 = 3 | TRINITY module widget_basics_local_names; pub const KIND : str = "widget-tool"; pub const ID : str = "basics-local-names"; pub const TITLE : str = "t27 basics 13: let, var and const"; pub const DESCRIPTION : str = "Where let, var and const live in a t27 spec and whether the name may change. Lesson 13 of the t27 basics course."; pub const IMAGE_ALT : str = "A black and white table comparing three kinds of names: const at the module level never changes, let inside a function is set once, var inside a function may be updated, each with an example line from the lesson spec."; pub const HOOK : str = "const, let and var: where each lives and which one may change."; pub const CATEGORY : str = "compiler"; pub const DATA_SOURCES : [2]str = ["The lesson spec public/t27/files/specs/basics/13_local_names.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 = "Three kinds of names"; pub const SAY_TABLE_HEAD : [4]str = ["Keyword", "Where", "May change", "Example"]; pub const SAY_TABLE_CELLS : [12]str = ["const", "Module level", "No", "pub const SIDE : u16 = 12;", "let", "Inside a function", "No", "let a = w * h;", "var", "Inside a function", "Yes", "var i : u8 = 0;"]; pub const K_TABLE_COLS : u8 = 4; pub const K_TABLE_ROWS : u8 = 3; pub const K_TABLE_CELLS : u16 = 12; ; --- The diagram and the note ---------------------------------------------------------------- pub const SAY_NOTE : str = "All three examples come from the lesson spec, which compiles clean on 7 backends."; 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; }