Skip to content

feat(format): REPL pretty-printing + distinct list/vector brackets#258

Merged
singaraiona merged 1 commit into
masterfrom
feat/repl-pretty-print-formatter
Jun 13, 2026
Merged

feat(format): REPL pretty-printing + distinct list/vector brackets#258
singaraiona merged 1 commit into
masterfrom
feat/repl-pretty-print-formatter

Conversation

@singaraiona

Copy link
Copy Markdown
Collaborator

Problem

In the REPL, a generic LIST was indistinguishable from a typed vector — homogeneous-atom lists collapsed to [...], so (list null null) printed [null null]. And dicts/nested structures always rendered on a single line, hard to read once nested.

Changes (REPL display / mode 1 only)

1. Distinct list vs vector brackets. A generic list now renders with parens, distinct from a vector:

(list null null) -> (null null)     ;; was [null null]
(list 1 2 3)     -> (1 2 3)
[1 2 3]          -> [1 2 3]

The homogeneous-atom → [..] collapse is kept for mode 0 (round-trippable), where fmt_eq and the whole suite rely on list/vector display equivalence. (Removing it for all modes broke 48 tests; gating to mode 1 is the correct scope.)

2. Width-triggered pretty-printing (ray_fmt_pp / ray_fmt_pp_print, wired into repl_print_result). Dicts/lists render on one line if they fit the row width (80); otherwise they break JSON-style with 2-space indent, and each nested child stays compact if it fits:

{
  name: "alice anderson"
  age: 30
  tags: ("engineer" "climber" "baker")
  address: {city:"springfield" zipcode:12345 country:"wonderland"}
}

Breaking is recursive; the broken form caps at FMT_PP_MAX_ROWS (20) then ...; vectors stay single-line (truncated at width). REPL-onlyray_fmt, mode 0, and table/vector cells keep their current single-line output, so tables and the test suite are unaffected.

Refactor. Extracted fmt_dict_key / fmt_dict_val from fmt_dict so the pretty-printer reuses the per-type key/value synthesis instead of duplicating it.

Tests

Added to test_format.c (TDD): the bracket fix (format/list/homogeneous_parens) and five pretty-printer cases — fits / breaks / nested-stays-compact / list-fits / scalar+vector passthrough. Updated one incidental existing assertion (empty_strs) to the new mode-1 list form.

Full suite passes under the sanitizer build (3447 passed, 0 failed, 3 pre-existing skips); REPL verified manually.

🤖 Generated with Claude Code

REPL display changes (mode 1 only — mode 0 / cells / tables unchanged):

1. A generic LIST now renders with parens, distinct from a typed vector:
   (list null null) -> (null null) (was [null null]); [1 2 3] stays [1 2 3].
   The homogeneous-atom -> [..] collapse is kept for mode 0, where the suite
   and fmt_eq rely on list/vector display equivalence.

2. Width-triggered pretty-printing (ray_fmt_pp / ray_fmt_pp_print): dicts and
   lists that exceed the row width (80) break JSON-style with 2-space indent;
   nested children stay compact if they fit their line. Recursive; broken form
   caps at FMT_PP_MAX_ROWS rows then "...". Wired into repl_print_result only,
   so ray_fmt/mode 0/table+vector cells keep single-line output.

Refactor: extracted fmt_dict_key / fmt_dict_val from fmt_dict so the
pretty-printer reuses the per-type key/value synthesis.

Tests: bracket fix + five pretty-printer cases (fits, breaks, nested-compact,
list-fits, scalar/vector passthrough) in test_format.c.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@singaraiona singaraiona merged commit a2ff73b into master Jun 13, 2026
4 checks passed
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