Skip to content

show renders to a string instead of printing - #94

Merged
ademar merged 1 commit into
masterfrom
print-show-fix
Aug 22, 2026
Merged

show renders to a string instead of printing#94
ademar merged 1 commit into
masterfrom
print-show-fix

Conversation

@ademar

@ademar ademar commented Aug 22, 2026

Copy link
Copy Markdown
Member

The bug

(print (show x)) — the idiom everyone reaches for — printed the value and then failed with Expected 1 args, found values #inert, blamed on the whole form. Root cause: show was a printing primitive wearing a renderer's name. It wrote showVal to the console itself and returned #inert; print then correctly rejected #inert. The output people saw came from show, not print. It was also redundant: write already prints machine-readable representations, and the language had no way to render a value to a string.

The fix

show now returns the printed representation as a string and writes nothing:

  • Rendering grants no host authority, so the HostIO gate is removed — show exists under every profile, including minimal. (The CLR fault sweep reflects this: its four (show value) cases move from capability errors to returned values, 172/47 → 168/51, with faulted: 0 unchanged.)
  • It carries a certified contract: (show any) → string, pure — visible in contract-of, LSP hover, and completion detail.
  • Strict arity: (show) and extra arguments are NumArgs errors (it previously ignored extras).

Call-site migration (all five in-repo uses were show-as-printer; each becomes (print (show …)), preserving output byte for byte): Examples/zipper.ikr ×2, Examples/contracts.ikr, Examples/vau-dotnet.ikr, lib/IronKernel.Test's show-line, and the website's trace sample. The operators reference now documents the rendering semantics.

Breaking change, deliberately: external code using bare (show x) to print will now compute and discard the string. The old semantics were unreachable through the name (Haskell's show, and the docs' own "printed representation" framing, both promise rendering), and pre-1.0 is when this gets fixed.

Verification

  • Clean --no-incremental rebuild: zero warnings. Full suite: 454/454 (3 new: rendering + the exact regression idiom via evalSessionKernel; show under minimal with print still denied as the control; a script-level two-form regression asserting the captured output equals (1 2)(3 4)).
  • All examples run with unchanged output (zipper's tree walk verified by eye); CLR fault sweep: faulted (process aborted): 0 with the four-case shift fully accounted for.
  • Benchmarks deliberately skipped: a primitive body and a registration-time list/contract entry; the evaluation machinery is untouched.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

(print (show x)) -- the natural idiom -- failed with "Expected 1 args,
found values #inert": show wrote showVal to the console itself and
returned inert, so print then rejected show's return value. A printing
primitive wearing a renderer's name, and redundant with write besides.

show now returns the printed representation as a string and writes
nothing. Rendering grants no host authority, so the HostIO gate is
gone: show exists under every profile (the CLR fault sweep's four
(show value) cases move from capability errors to values). It carries
a certified contract, (show any) -> string, pure.

The five in-repo call sites that used show as a printer -- zipper,
contracts, and vau-dotnet examples, IronKernel.Test's show-line, and
the website's trace sample -- become (print (show ...)), preserving
their output byte for byte. The operators reference now documents the
rendering semantics.
@ademar
ademar merged commit 3d180ce into master Aug 22, 2026
2 checks passed
@ademar
ademar deleted the print-show-fix branch August 22, 2026 18:58
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