-
Notifications
You must be signed in to change notification settings - Fork 371
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
Inconsistent for syntax #1723
Comments
More generally, these forms look like:
Are you asking for every iteration clause to get a pair of square brackets, or for the whole set of iteration clauses to get square brackets even when it's not necessary (e.g., for forms other than
or
? Neither really seems like an improvement to me. |
Didn't know about multiple clauses, awesome! To answer your question, of the two, I'd prefer the former, because it's consistent. Another option would be to change
(By the way, I'm aware that I'm opening a lot of issues and giving a lot of feedback while being someone very new to Hy. If I'm overreaching, please let me know.) |
(It's okay. Everybody's new to Hy except for the small handful who stick around.) I don't think we can have |
How about requiring brackets around the bindings in Essentially allowing this: (lfor [x xs y ys]
(body1)
(body2)
(result)) Which would be equivalent to the current syntax: (lfor x xs y ys
(do (body1)
(body2)
(result))) It seems more "lisp-like" to treat the first argument specially (the binding vector) rather than having 2N + 1 arguments and treating the last differently. |
Seconded. I like that solution. |
Generally, |
For constructing intermediate values, especially since there isn't a built-in
|
But that's what |
I recognize this is a bit of a one-off usage, but it will make it much nicer to stick a debug (lfor [n some-iterable]
(print n) ; <-- just put it in there with no worries
(some-function n)) though I am mostly in favor for the sake of consistency. |
But that's what |
Sorry for the noise - I did read the documentation some time ago, but forgot that these special clauses existed. In a way it seems that the Personally I would prefer a natural way of writing these things, i.e just being able to use the standard But it's true that the |
That was my original plan; the default clause type would be to just evaluate the given form, like |
Thanks for the explanation, it's always interesting to hear the rationale behind these syntax decisions :) I guess you had also considered Clojure's syntax for its ;; ===== Clojure =====
(for [x xs
:when (condition x)
:let [p (f1 x)
q (f2 p)]
y ys
:let [r (f3 y)]]
(body1)
(body2)
(g x y))
;; ===== Hy =====
(gfor x xs
:if (condition x)
:setv p (f1 x)
:setv q (f2 p)
y ys
:setv r (f3 y)
:do (body1)
:do (body2)
(g x y)) It's strange how aggressively Hy tends to "flatten" its syntax, considering Clojure already does that to some extent – I find the first one more readable but guess it's a matter of getting used to.. |
I think that I had originally suggested keeping the square brackets for all the comprehensions to make it match Clojure's But you shouldn't need multiple (gfor x xs
:if (condition x)
:setv p (f1 x)
:setv q (f2 p)
y ys
(do (setv r (f3 y))
(body1)
(body2)
(g x y))) If I recall, I was kind of opposed to having a |
I think that the syntax would be nicer if square brackets were used around the arguments for Another case were the syntax is inconsistent is with (loop [n 5
acc 1]
(if (zero? n) acc (recur (dec n) (* n acc)))) instead of (loop [[n 5]
[acc 1]]
(if (zero? n) acc (recur (dec n) (* n acc)))) |
The (defn looped [&optional [n 5] [acc 1]]
(if (zero? n) acc (looped (dec n) (* n acc)))) (Apologies if I'm missing any brackets, I'm used to rainbow parens coloring...) |
As for Hy in general has a very "flat" syntax (consider how |
That is my feeling as well. I got used to it. I'm pretty satisfied now with how the xfor family turned out overall. It's kind of like Hy's version of the Common Lisp loop macro. But keeping the square brackets for all the comprehensions to make it match Clojure's |
I also have a preference towards square brackets for all the comprehensions — it makes it visually consistent with other forms that also assign values to symbols. I'm currently going through the language special forms and macros to generally see what is/isn't consistent and will an issue documenting the results. Some even appear to be bugs, for example the form for |
i'm also in favor of square brackets around comprehensions since they are effectively binding pairs like |
|
|
With the demise of #2102, this is unlikely to change. |
I've noticed that
for
takes the iteration variable and iterable like[var iterable]
whereaslfor
,dfor
, andgfor
take it likevar iterable
:while this isn't huge, it would be nice for these to be consistent, so
lfor
dfor
andgfor
would also look like[item iterable]
.The text was updated successfully, but these errors were encountered: