-
Notifications
You must be signed in to change notification settings - Fork 47
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
do (doseq etc.) body should be newline seperated #3
Comments
Thanks for bringing this up! I'm on the fence for this one. Personally, I like to see as much as I can in an editor window, so I'm not wild about having my short (doseq [x xs]
(foo x)
(bar x)) Currently, you can not really get zprint to do that, unfortunately:
The last one looks like it worked, but it didn't really, as the binding form won't be handled as a vector of pairs. What we really need is a The remaining question is -- should all of the binding functions be converted to "let" :binding
"binding" :binding,
"with-redefs" :binding,
"with-open" :binding,
"with-local-vars" :binding,
"with-bindings" :arg1,
"with-bindings*" :arg1,
"when-some" :binding,
"when-let" :binding,
"when-first" :binding,
"loop" :binding,
"if-some" :binding,
"if-let" :binding,
"for" :binding,
"dotimes" :binding,
"doseq" :binding Certainly I've thought a lot about forcing I could be convinced to make Of course, you can only configure one style in an options map, say in |
Interestingly, when looking at a comment on the other issue you raised, I realized that you can, indeed, configure this: (doseq [x xs]
(foo x)
(bar x)) You would add zprint.zprint=> ffn
#{:force-nl :noarg1 :noarg1-body :force-nl-body :arg1-force-nl}
zprint.zprint=> ds
"(doseq [x xs] (foo x) (bar x))"
zprint.zprint=> (czprint ds {:parse-string? true :fn-force-nl (into #{} (concat ffn #{:binding}))})
(doseq [x xs]
(foo x)
(bar x)) My question for you: Do you need to configure this fn by fn (i.e., do I need to build a specific |
Thanks for your response! You're right, I prefer
to
I'll address the issue of why I want doseq (and other forms) to adhere to newline style first. I think the core of the issue is that typically
As a side-note, this is also common in clojure.core:
but that's a different discussion I think. As I understand it, people write
|
Empirically, looking at the clojure git repository ( I did find some |
I should add that these are all debatable and I may be wrong in my judgments about community conventions. Ideally all of this should be configurable (and making this possible is IMO the most powerful thing about zprint). Having said that, IMO a library like zprint (like a style guide) should aim to have defaults (or defaults easily accessible) that best reflect community conventions. Ideally we should be able to say, "If in doubt, just let zprint (lein-zprint, boot fmt) handle it", similar to how things work in the golang community. |
To your final question, I'll have to look more into how zprint configuration works to give a more informed answer. |
Thanks for the discussion! It is pleasure to have someone to discuss this with, actually. First, I totally agree that:
I'm completely on board with the idea that by zprint should be easily configurable in order to follow community conventions. That said, there are multiple communitiies. The community-style-guide has what are to me very strange conventions about the indent depth based on whether or not a function has "body parameters" or "arguments". Personally, I see them pretty much the same way, and I have found limited actual code doing this in practice, though it has been a while since I looked. I did implement this capability in zprint, because I thought it was important to be able to do it the way the style guide says, but I am not keen to make that the default. I tend to look at clojure.core as a large part of the community, though it is far from internally consistent. For defaults I tend to pick what I like from the various example "communities". Plus my own idiosyncratic issues, like indented second things in Enough philosophy, let's talk I found this function in zprint: (defn map-stop-on-nil
"A utility function to stop on nil."
[f out in]
(when out (let [result (f in)] (when result (conj out result))))) This must drive you crazy. I realize that an (defn map-stop-on-nil
"A utility function to stop on nil."
[f out in]
(when out
(let [result (f in)]
(when result
(conj out result))))) and I don't disagree. I have added, but not pushed to github, a (s/or :sym ::local-name
:seq ::seq-binding-form
:map ::map-binding-form)) [The reason you this the pairs is because of "constant-pairing", just FYI.] but you also get this: (s/or :sym ::local-name) as opposed to this: (s/or :sym
::local-name) which is what you would get if it were What I am thinking now is that instead of a (doseq [x xs] (dostuff x)) and this (doseq [x xs]
(stuff x)
(bother x)) If, on the other hand, (doseq [x xs]
(dostuff x))
(doseq [x xs]
(stuff x)
(bother x)) This doesn't let you configure different handling for, say, Were I to go this direction, I would have to have some How does that sound to you? |
Your suggestion sounds great and would cover all cases I can think of right
now.
I'm assuming gt2 stands for greater than two? Does that number include the
bindings vector?
By the way, I don't think writing a doseq in a single line is crazy at all
(though i have a mild preference for inserting a newline). What does
confuse my sense of aesthetics is two sexps in addition to the bindings,
all in one line. But I'm more than happy if I can customize zprint as you
suggest.
On Dec 11, 2016 00:04, "Kim Kinnear" <notifications@github.com> wrote:
Thanks for the discussion! It is pleasure to have someone to discuss this
with, actually.
First, I totally agree that:
1. All of this (i.e., the multi-line nature of do-likes) should be
configurable.
2. zprint, by default, should do a nice job. You shouldn't have to
bother to configure zprint unless you want something a particular way.
(Which is not exactly what you said, I acknowledge).
I'm completely on board with the idea that by zprint should be easily
configurable in order to follow community conventions. That said, there are
multiple communitiies.
The community-style-guide <https://github.com/bbatsov/clojure-style-guide>
has what are to me very strange conventions about the indent depth based on
whether or not a function has "body parameters" or "arguments". Personally,
I see them pretty much the same way, and I have found limited actual code
doing this in practice, though it has been a while since I looked. I did
implement this capability in zprint, because I thought it was important to
be able to do it the way the style guide says, but I am not keen to make
that the default.
I tend to look at clojure.core as a large part of the community, though it
is far from internally consistent.
For defaults I tend to pick what I like from the various example
"communities". Plus my own idiosyncratic issues, like indented second
things in cond and initializers in let.
Enough philosophy, let's talk do-like details.
I found this function in zprint:
(defn map-stop-on-nil
"A utility function to stop on nil."
[f out in]
(when out (let [result (f in)] (when result (conj out result)))))
This must drive you crazy. I realize that an if-let would make it clearer,
but
that's not today's point. You would like it to be:
(defn map-stop-on-nil
"A utility function to stop on nil."
[f out in]
(when out
(let [result (f in)]
(when result
(conj out result)))))
and I don't disagree.
I have added, but not pushed to github, a :fn-type of :gt2-force-nl, to try
to get some 1.9-alpha clojure.core spec files to look better than they do
today without also looking worse. The idea here was to have s/or be
:gt2-force-nl, where if there were more than two arguments, the s/or would
be force-nl. So, you get this:
(s/or :sym ::local-name
:seq ::seq-binding-form
:map ::map-binding-form))
[The reason you this the pairs is because of "constant-pairing", just FYI.]
but you also get this:
(s/or :sym ::local-name)
as opposed to this:
(s/or :sym
::local-name)
which is what you would get if it were :force-nl like s/cat is. This is
what the spec file does
today with s/or.
What I am thinking now is that instead of a :fn-type of :gt2-force-nl, that
there would be several sets like :fn-force-nl, e.g. :gt2-force-nl,
:gt3-force-nl. This way if doseq was :binding, and :binding was in
:gt2-force-nl, then you would get this:
(doseq [x xs] (dostuff x))
and this
(doseq [x xs]
(stuff x)
(bother x))
If, on the other hand, :binding was in :fn-force-nl, then you would get
this:
(doseq [x xs]
(dostuff x))
(doseq [x xs]
(stuff x)
(bother x))
This doesn't let you configure different handling for, say, doseq and let,
as both are :binding functions. It is, however, a bit more general as the
force-nl configuration is taken from the :fn-type, but is not encoded in it
directly. I'm trying to avoid an explosion of :fn-types.
Were I to go this direction, I would have to have some :fn-type to use for
s/or and s/and, so I could put them into the :gt2-force-nl set, as they are
not otherwise configured as anything today.
How does that sound to you?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGfWL3SdXSnahgHr09-q9L87eH1CMDKks5rGy_4gaJpZM4LFt__>
.
|
This is fixed in 0.2.10. I ended up creating two new sets, Thanks for the suggestions! |
Based on clojure code I've read, I would expect each form in the body to be separated by a newline for
do
anddo
-likes (doseq
,dotimes
,dosync
).I think the same is true for a lot of other macros as well, e.g.
with-open
,future
The text was updated successfully, but these errors were encountered: