Skip to content

Docs: program arguments after --, sort idioms, channels of different types, equality and order idioms - #151

Merged
rendro merged 6 commits into
w2/language-cardfrom
w2/docs-and-idioms
Oct 24, 2026
Merged

rendro merged 6 commits into
w2/language-cardfrom
w2/docs-and-idioms

Conversation

@rendro

@rendro rendro commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Lane D, PR 3 of 4 (wave 2). Stacked on #149.

  1. CLI: arguments after -- are the program's, --help included. Three places scanned every argument for --help: run, disasm and the watcher. One helper, cli::help::asks_for_help, now looks only before --. The run subcommand's help names -- <args>... and has an example. Tests that fail on the base: goldens cli/run/program_args__a_help_flag_after_the_separator_is_the_program_s, cli/disasm/program_args__*, cli/run/run_help__names_the_program_arguments; cli test run_watch_with_help_after_separator_watches_and_forwards_arg.
  2. list.md: descending sort (|> list.reverse), sort_by stable with tuple keys and a negated key, sort_with with Compare.compare(b, a).
  3. concurrency.md: a new section, receiving from channels of different types (an enum, stream.map, stream.merge and one match), linked from channel.select. Also removed two promises of features silt decided against: stream.md's "Forward compatibility" section and bytes.md's last note.
  4. traits.md: a new section, Equality and order idioms, with six idioms and one runnable program. The sealed rule links to it.
  5. The sealed Equal/Compare/Hash error gains a help line pointing at that section. Golden typecheck/traits/sealed_traits__the_help_points_at_the_idioms fails on the base.

New texts await the owner's approval before merge.

Checks: whole suite, clippy both ways, fmt, rustdoc, no-default-features check.

@rendro
rendro added this pull request to stack #150 October 24, 2026 04:28
`silt run main.silt -- --help` printed silt's run help instead of
running the program with `--help`: run (and disasm) looked for a help
flag among all their arguments, past the `--` too. So did the watcher:
`silt run -w main.silt -- --help` ran the program once and stopped
watching. All three now look before `--` only (cli::help::asks_for_help).
`check` and `test` were right already: check stops reading its flags at
`--`, and test rejects `--` (it takes no program arguments).

`silt run --help` names the separator: the usage line ends in
`[-- <args>...]`, an option line says what it does, and an example
passes an argument. getting-started's tooling block shows it too.

Tests: goldens cli/run/program_args__a_help_flag_after_the_separator_is_the_program_s
(package case, `silt run -- --help -h` prints both),
cli/disasm/program_args__... (disassembles), cli/run/run_help__names_the_program_arguments
(the help text); tests/cli watch_double_dash_separator_tests::run_watch_with_help_after_separator_watches_and_forwards_arg.
All fail on the base.
list.sort says how to sort descending (`|> list.reverse`); list.sort_by
says that it is stable, that a tuple key sorts by its parts in turn, and
that a negated number key sorts descending, with an example that ranks
players by score, highest first, then by name; list.sort_with that
`Compare.compare(b, a)` sorts descending by any key. Each example runs,
and its `--` comments are its output.
concurrency.md gains "Receiving from channels of different types": the
operations of one channel.select and the channels of one stream.merge
are of one type, so declare an enum with a variant for each kind of
message, stream.map each channel into it and stream.merge them; one
match handles them all, and the merged channel closes when its inputs
have. Its example runs (`3 events`). channel.select's reference section
points to it.

Two notes promised what silt has decided against: stream.md's "Forward
compatibility" (method-form dispatch `s.map(f)` once silt grows a Stream
trait) and bytes.md's last note (a future `Bytes` literal and
method-form access, with programs "forward-compatible"). A dot after a
value names a field, and silt makes no compatibility promises: both are
gone.
traits.md gains "Equality and order idioms", at the end of Built-in
Traits, and the sealed rule points to it: what to write when a type
should compare by something other than its structure. Normalise once
in a constructor function; key a map by an id; key records that hold a
function by their names; sort by a key (tuple keys, `|> list.reverse`,
`list.sort_with`); find duplicates by a key with `list.unique_by`;
order versions as records, field by field. One example program shows
each; it runs, and its `--` comments are its output.
A hand-written `trait Equal for T`, `trait Compare for T` or `trait
Hash for T` is an error that says to remove the impl; now it also says
where the ways to compare by something else are:

  = help: to compare, order or hash by something else (a key, a
    normalised value), see "Equality and order idioms" in
    docs/language/traits.md

(`Number`'s error has no such line.) The one change in src/typechecker
is in reject_sealed_trait_impls (lane E told first). traits.md's
example of the error shows the line.

Tests: golden typecheck/traits/sealed_traits__the_help_points_at_the_idioms
(fails on the base: no help); number__sealed now pins that Number's
error does not point there.
`silt test x_test.silt -- a` said "unknown flag '--'". It is refused
still (a test is called with no arguments, so nothing could read them),
but the message says so: "silt test takes no program arguments: '--'
passes arguments to a program run by 'silt run'", then the usual
"Run 'silt test --help' for usage."

Test: golden cli/test/program_args__the_separator_is_refused (fails on
the base: the old message).
@rendro
rendro force-pushed the w2/docs-and-idioms branch from 80cd770 to c8280b4 Compare October 24, 2026 06:27
@rendro
rendro marked this pull request as ready for review October 24, 2026 12:06
@rendro
rendro merged commit 1cba622 into main Oct 24, 2026
23 of 46 checks passed
@rendro
rendro deleted the w2/docs-and-idioms branch October 24, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant