
Posterity doesn’t last very long in slack unfortunately


@ryanc Would it make sense to add a #:thousands-sep
option to ~r
(defaulting to ""
) to be able to print numbers like 10 000 000
or 10_000_000
or is there a good reason against this?


Indian numbers are not grouped every 3 digits, so I think this #:thousands-sep
is too narrow.

This is mostly for base 10 of course. For other bases there could be an additional #:digit-group
to say how many digits should be grouped together

That said, since it’s backward compatible, I think it’s also okay to not provide full flexibility (and include for example only #:thousands-sep
) and leave a more full-featured digit-separator as future work

@sorawee There could be an 'indian
option to #:thousands-sep
, grouping by 3 then 2, since it’s specific?

The problem is that once you add #:thousands-sep
, then any “future work” needs to keep #:thousands-sep
to keep it backward compatible.

But that’s no longer “thousands”

True. #:digit-group-sep
?

I think the feature is a good idea. I think it should be generalized (maybe #:left-grouping
) and support a little language of arguments kind of like #:precision
. For example, a plain string means separate groups of three “digits”; a list like (list group-size group-sep)
lets you override the grouping size.

Sounds good to me.
@sorawee Though to be fair, keywords make it easy to modify features while keeping backward compatibility, by adding new keywords and deprecating other ones. The only real risk is keyword-pollution I guess, but things could be worse.

@ryanc The Indian system is more complicated: Digits are grouped first by 3, then by 2 (see WP link above) But a (list 'indian ",")
option could work I guess

This may lead to needing a #:decimal-sep
option too I guess?

How about (list '(3 2) ",")
for the Indian convention?

works for me

Loosely related: One of my frustrations with racket/pretty
is that it only lets you specify indentations for new symbols based on “standard” indentations, rather than letting you say something like “big-indent 2 elements in list-of-clause-style, then small-indent the rest in expression-style”.

Also related: text-table has a style that allows some repetition such as (a b ... c d)
but doesn’t allow (yet?) to specify something like (a (b 4) c (b 5) d)
which I’ve found desirable recently. (although in truth one can always use append
and make-list
, but it’s a little cumbersome)
Maybe we need a common and full-featured style
list/tree format to subsume them all?

@ryanc Can you illustrate that style? I hope to make fmt
flexible enough to support that style (I think it does already, but just want to make sure)

Like this? (foo
bar
baz
1
2
3)

It’s how I would describe for/fold. Like what you posted, but probably 4 and 2 spaces instead of 2 and 1. And the first two things are lists of binding-like clauses, so they (maybe) should be treated differently from application expressions.

Oh, I see. Then it already supports it (since it already supports the for/fold
style) :slightly_smiling_face:

I haven’t thought through a general-purpose indentation DSL. It should probably account somehow for the principle that if there is no newline before the first “argument”, then the second should indent under the first, but the third resets to 2 spaces.

Another thing I find annoying with the default formatter is that quoted lists are treated like function applications. I want to be able to write '(qwerty qwerty qwerty
qwerty qwerty)
and not '(qwerty qwerty qwerty
qwerty qwerty)

But can you indent something like for/fold but with three special initial arguments instead of two?

Yep

[("syntax-case" "instantiate")
(format-uniform-body/helper 2 #:body-formatter (format-clause-2/indirect) #:require-body? #f)]
[("syntax/loc" "quasisyntax/loc") (format-uniform-body/helper 1)]
[("when" "unless") (format-uniform-body/helper 1)]
[("mixin") (format-uniform-body/helper 2)]
[("for/fold" "for*/fold")
(format-uniform-body/helper 2 #:arg-formatter format-binding-pairs/indirect)]
[("for" "for*") (format-uniform-body/helper 1 #:arg-formatter format-binding-pairs/indirect)]
[("for/list" "for*/list")
(format-uniform-body/helper 1 #:arg-formatter format-binding-pairs/indirect)]
[("for/and" "for*/and" "for/or" "for*/or")
(format-uniform-body/helper 1 #:arg-formatter format-binding-pairs/indirect)]

Nice!

@laurent.orseau Yes, that irritates me too. I discovered (in racket-mode, anyway), the following indentation hack: '(;; Group one
one two three
;; Group two
abc xyz)
That helps sometimes.

Doesn’t work with DrRacket unfortunately. I’m using '(#;_
one two three
four)
as a similar hack, but it’s ugly

fmt
would format like the status quo in this case, because I do want:
'(#;_
module a racket
four)
to be formatted like so.

Even quoted?

Yeah. It’s just unfortunate that lists are printed in the quoted form by default. I really like that in Rhombus, it no longer does that.

I will add a capability to allow you to format quoted list differently from non-quoted list though. Might be tricky, but should be doable.