Basic module

formatStruct

procedureSource

Wraps a struct for print with its own layout instead of the default one.

formatStruct :: (
    value: Any,
    use_long_form_if_more_than_this_many_members := 5,
    use_newlines_if_long_form := false
) -> FormatStruct

Parameters

value: Any
use_long_form_if_more_than_this_many_members := 5
structs with more members than this print as name = value; ..., shorter ones as {a, b}.
use_newlines_if_long_form := false
put each member of a long form on its own line.

Returns

Example↗
Pair :: struct { a: int; b: int; }
pair := Pair.{ 1, 2 };
text := tprint("%", formatStruct(pair, use_long_form_if_more_than_this_many_members = 1));
assert(text == "{a = 1; b = 2; }");

See also