[ANN] fmt: a Racket code formatter

203 views
Skip to first unread message

Sorawee Porncharoenwase

unread,
Sep 28, 2021, 2:03:28 PM9/28/21
to Racket list

Announcing the pre-alpha version of fmt, a Racket code formatter. Code formatter is a tool that reformats your code so that it conforms to a style consistently.

As a part of this work, I implemented Jean-Philippe Bernady’s non greedy pretty printer (ICFP’17) and extended it so that it is practical for actual use.

Hope you find these useful, and let me know if you have any feedback.

Sorawee (Oak)

David Storrs

unread,
Sep 28, 2021, 2:30:22 PM9/28/21
to Sorawee Porncharoenwase, Racket list
This is very cool, Sorawee.  Thank you for sharing.

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CADcueguOiOBK4vE3kCfvWYkb2Eaz-JfM5_Yd%3DGct-6umSUEG6w%40mail.gmail.com.
Message has been deleted

Diego Crespo

unread,
Oct 18, 2021, 9:14:50 PM10/18/21
to Racket Users
This is really cool. Between this, a Racket linter, and an LSP, Racket is seriously looking a lot better for larger teams. I ran it through some of my code and I'm curious about the decision to use brackets more liberally. I was surprised when it changed my methods in my classes to be bracketed, as well as the init, and field expressions. I could probably get used to it given enough time, but I haven't seen that style in other Racket code before.

Sorawee Porncharoenwase

unread,
Oct 18, 2021, 10:06:55 PM10/18/21
to Diego Crespo, Racket Users
Don't get used to it. It's a bug!


--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.

Hendrik Boom

unread,
Oct 19, 2021, 9:34:04 AM10/19/21
to Racket Users
When I read this:

> On Mon, Oct 18, 2021 at 6:14 PM Diego Crespo <
> mycontributi...@gmail.com> wrote:
>
> > This is really cool. Between this, a Racket linter, and an LSP, Racket is
> > seriously looking a lot better for larger teams. I ran it through some of
> > my code and I'm curious about the decision to use brackets more liberally.
> > I was surprised when it changed my methods in my classes to be bracketed,
> > as well as the init, and field expressions. I could probably get used to it
> > given enough time, but I haven't seen that style in other Racket code
> > before.

I thought, great! This will ameilorate the perennial parenthesis problem by using
different kinds of brackets for different uses.

THen I read this:

On Mon, Oct 18, 2021 at 07:06:41PM -0700, Sorawee Porncharoenwase wrote:
> Don't get used to it. It's a bug!
>
> Fixed in
> https://github.com/sorawee/fmt/commit/e056aee1e9a3ea0a72a4c85075426fa76f037852.
> Thanks for the report!

and was disappointed.

The I started wondering -- just what did it look like, that the use of different
brackets would be considered a problem?

-- hendrik

Diego Crespo

unread,
Oct 19, 2021, 10:00:45 AM10/19/21
to Racket Users
If you are curious about what the output looked like before, here is the pasterack link of some of my code http://pasterack.org/pastes/23639. Racket supports using brackets instead of parenthesis, but you typically only see it used in things like cond and let expressions. This was adding them to far more expressions. Other than looking odd, there was nothing wrong with the code (other than my own errors :)) 

Sorawee Porncharoenwase

unread,
Oct 19, 2021, 2:08:13 PM10/19/21
to Diego Crespo, Racket Users

On Tue, Oct 19, 2021 at 7:01 AM Diego Crespo mycontributi...@gmail.com wrote:

If you are curious about what the output looked like before, here is the pasterack link of some of my code http://pasterack.org/pastes/23639. Racket supports using brackets instead of parenthesis, but you typically only see it used in things like cond and let expressions. This was adding them to far more expressions. Other than looking odd, there was nothing wrong with the code (other than my own errors :)) 

FWIW, here’s what the tool would output now (provided that the input code’s paren shapes are not yet compromised): http://pasterack.org/pastes/21352

raco fmt will usually keep paren shape intact, but it can convert paren shape in some positions. Right now, the only conversion is from parenthesis to bracket, and it’s enabled for:

  • cond, case-lambda, match, case body
  • syntax-case, syntax-rules body
  • syntax-parse (including syntax-parser and define-syntax-parser) body.
  • for bindings (including for/... and for*/...)
  • let bindings (including letrec, let-syntax, let-values, …)
  • parameterize, with-syntax, shared bindings
  • and a few more

What happened earlier was that class was erroneously configured to have this paren shape conversion, even though it should not.

On Tuesday, October 19, 2021 at 9:34:04 AM UTC-4 hen...@topoi.pooq.com wrote:
and was disappointed.

I would not recommend this, but if you strongly feel that the class body should use brackets, you are free to write your own formatting rules.
(Though I have not documented how to do so.)


Hendrik Boom

unread,
Oct 19, 2021, 9:47:58 PM10/19/21
to Racket Users
On Tue, Oct 19, 2021 at 11:07:58AM -0700, Sorawee Porncharoenwase wrote:
> On Tue, Oct 19, 2021 at 7:01 AM Diego Crespo
> mycontributi...@gmail.com
> <http://mailto:mycontributi...@gmail.com> wrote:
>
> If you are curious about what the output looked like before, here is the
> > pasterack link of some of my code http://pasterack.org/pastes/23639.
> > Racket supports using brackets instead of parenthesis, but you typically
> > only see it used in things like cond and let expressions. This was adding
> > them to far more expressions. Other than looking odd, there was nothing
> > wrong with the code (other than my own errors :))
> >
> FWIW, here’s what the tool would output now (provided that the input code’s
> paren shapes are not yet compromised): http://pasterack.org/pastes/21352
>
> raco fmt will usually keep paren shape intact, but it can convert paren
> shape in some positions. Right now, the only conversion is from parenthesis
> to bracket, and it’s enabled for:
>
> - cond, case-lambda, match, case body
> - syntax-case, syntax-rules body
> - syntax-parse (including syntax-parser and define-syntax-parser) body.
> - for bindings (including for/... and for*/...)
> - let bindings (including letrec, let-syntax, let-values, …)
> - parameterize, with-syntax, shared bindings
> - and a few more
>
> What happened earlier was that class was erroneously configured to have
> this paren shape conversion, even though it should not.

I find the layout of the second version more readable,
but find the choice of parenthesis shape in the first version more readable.

-- hendrik

>
> On Tuesday, October 19, 2021 at 9:34:04 AM UTC-4 hen...@topoi.pooq.com
> > wrote:
> >
> >> and was disappointed.
> >>
> > I would not recommend this, but if you strongly feel that the class body
> should use brackets, you are free to write your own formatting rules.
> (Though I have not documented how to do so.)
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CADcuegs%2BepCLAXHzjXxPdq%3DR6su0heHOJRBYgWL7_tLj5J%3Db2A%40mail.gmail.com.

P&E Schmurr

unread,
Oct 20, 2021, 11:26:38 AM10/20/21
to Racket Users
When creating an executable distribution, the resulting zip file has no contents.  I have updated to the most recent Racket release. 

Diego Crespo

unread,
Oct 20, 2021, 11:55:30 AM10/20/21
to Racket Users
When creating an executable after using raco fmt? Or in general? If it's the second situation, I think it belongs in a separate topic.
Reply all
Reply to author
Forward
0 new messages