Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Margin (inline) comments allow hanging closing parentheses? #258

Open
shaunlebron opened this issue Sep 11, 2024 · 2 comments
Open

Margin (inline) comments allow hanging closing parentheses? #258

shaunlebron opened this issue Sep 11, 2024 · 2 comments

Comments

@shaunlebron
Copy link
Contributor

shaunlebron commented Sep 11, 2024

I think the rules for margin comments are causing some confusion in the related Standard Clojure Style discussion:

Problem

The Clojure Style Guide’s rules for margin comments states:

  1. Write margin comments with one semicolon.
  2. Avoid using those in situations that would result in hanging closing parentheses.

But the given example seems to break the second rule:

(defn foo [x]
  x ; I'm a line/code fragment comment.
  )

Proposal

The example below from @yuhan0 follows these rules— by not expecting an inline comment to directly follow its referent expression (AST-wise):

(defn classify-squares [n]
  (->> (range n)          ; generate a bunch of numbers
       (map #(* % %))     ; calculate their squares
       (group-by even?))) ; and sort them by parity

This seems more conventional than the other example, which I actually haven’t seen before.

Rationale

One way to formalize this is to treat margin comments as actual sidenotes:

  1. Treat anything after an inline semicolon ; as “in the margin”.
  2. Gather trailing parentheses by ignoring anything in the margin.
@imrekoszo
Copy link

For visibility, here is a potential counter-example:

(comment
  (foo 1) ;;=> :foo
  (foo 2) ;;=> :bar
 )

@seancorfield
Copy link
Collaborator

See also #259 (specifically related to @imrekoszo example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants