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

Multi Arity functions in Indent mode #118

Closed
ashercoren opened this issue Aug 25, 2016 · 4 comments
Closed

Multi Arity functions in Indent mode #118

ashercoren opened this issue Aug 25, 2016 · 4 comments

Comments

@ashercoren
Copy link

When writing a multi arity functions, the regular way of writing it is:

(def f
  ([a]
    (+ a 3))
  ([a b]
    (+ a b)))

Where each arity option has a list of parameters, followed by the function implementation. The function implementation is indented one level further than the list of parameters.

With indent mode, this automatically gets changed, since the function implementation is nested inside the variable list, so it gets changed to:

(def f
  ([a
    (+ a 3)])
  ([a b
    (+ a b)]))
@shaunlebron
Copy link
Collaborator

shaunlebron commented Aug 25, 2016

Thanks for reporting! This is a known issue, and is the only irreconcilable inconsistency with the clojure indentation standards. When designing parinfer, I ran it against all clojure core repos to be sure that this was the only thing that had to go.

If it's any consolation, Parinfer is actually still compatible with the Clojure Style Guide, since it has a strict stance against indenting multi-arities that way. I brought up how this contradicts real-world usage to the style guide author here. You can read his response there.

So, from the perspectives of everyone involved:

  • Users want it because it helps readability by separating arities from the bodies.
  • I can't fix it because it would make my automation rules inconsistent.
  • The style guide author doesn't like it because it's inconsistent with how single-arity functions are written.

@facundoolano
Copy link

I use the same indentation suggested in the style guide you mentioned. I always run into problems, though, when converting a function of single arity into a multiple arity one. I can't seem to find a way to wrap the old body around a new set of parenthesis without breaking the code:

(defn foo
  "What I have."
  [x]
  (bar x))

(defn foo
  "What I'd like next (before adding the other arity definition)."
  ([x]
   (bar x)))

(defn foo
  "What I actually get."
  ([x
    (bar x)]))

I can't tell if it's parinfer or the editor -sublime- causing it. If it's parinfer, I wonder if that's a behaviour that could be changed.

@facundoolano
Copy link

Actually, nevermind, I just noticed I can avoid that by changing to paren mode before adding the new parentheses.

@shaunlebron
Copy link
Collaborator

@facundoolano yeah, it's a common enough hiccup. still thinking on alternate resolutions

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