feat(format): REPL pretty-printing + distinct list/vector brackets#258
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the REPL, a generic
LISTwas 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 1only)1. Distinct list vs vector brackets. A generic list now renders with parens, distinct from a vector:
The homogeneous-atom →
[..]collapse is kept for mode 0 (round-trippable), wherefmt_eqand 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 intorepl_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:Breaking is recursive; the broken form caps at
FMT_PP_MAX_ROWS(20) then...; vectors stay single-line (truncated at width). REPL-only —ray_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_valfromfmt_dictso 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