laurent.orseau
2022-3-28 09:07:41

Posterity doesn’t last very long in slack unfortunately



laurent.orseau
2022-3-28 12:54:20

@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?



sorawee
2022-3-28 12:57:09

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


laurent.orseau
2022-3-28 12:57:38

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


laurent.orseau
2022-3-28 12:58:40

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


laurent.orseau
2022-3-28 13:00:33

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


sorawee
2022-3-28 13:00:46

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


sorawee
2022-3-28 13:01:00

But that’s no longer “thousands”


laurent.orseau
2022-3-28 13:02:55

True. #:digit-group-sep?


ryanc
2022-3-28 13:04:52

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.


laurent.orseau
2022-3-28 13:07:10

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.


laurent.orseau
2022-3-28 13:08:15

@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


laurent.orseau
2022-3-28 13:10:53

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


ryanc
2022-3-28 13:12:53

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


laurent.orseau
2022-3-28 13:15:40

works for me


ryanc
2022-3-28 13:17:25

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”.


laurent.orseau
2022-3-28 13:25:05

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?


sorawee
2022-3-28 13:25:44

@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)


sorawee
2022-3-28 13:26:34

Like this? (foo bar baz 1 2 3)


ryanc
2022-3-28 13:28:40

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.


sorawee
2022-3-28 13:30:06

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


ryanc
2022-3-28 13:31:01

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.


laurent.orseau
2022-3-28 13:31:30

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)


ryanc
2022-3-28 13:31:34

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


sorawee
2022-3-28 13:31:58

Yep


sorawee
2022-3-28 13:32:03

[("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)]


ryanc
2022-3-28 13:32:26

Nice!


ryanc
2022-3-28 13:35:37

@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.


laurent.orseau
2022-3-28 13:36:31

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


sorawee
2022-3-28 13:38:52

fmt would format like the status quo in this case, because I do want:

'(#;_ module a racket four) to be formatted like so.


laurent.orseau
2022-3-28 13:39:30

Even quoted?


sorawee
2022-3-28 13:40:07

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.


sorawee
2022-3-28 13:46:28

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.