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

Explicit ordering of destructuring bindings #665

Closed
NoahTheDuke opened this issue Aug 7, 2023 · 2 comments
Closed

Explicit ordering of destructuring bindings #665

NoahTheDuke opened this issue Aug 7, 2023 · 2 comments

Comments

@NoahTheDuke
Copy link
Contributor

NoahTheDuke commented Aug 7, 2023

As discussed in this ask.clojure.org question, I and others have been confused by the ordering of bindings in destructuring forms. There is subtle and implied descriptions of the ordering in the Special Forms: Binding Forms page, but I think it could be helpful to make it much more explicit.

The given example on that page shows it but this specific aspect is not obvious by the number of features being shown at once. Maybe splitting it up into individual examples could be helpful.

@puredanger
Copy link
Member

Isn't this "an :as key in the binding form followed by a symbol binds that symbol to the entire init-expr" already explicit?

@puredanger
Copy link
Member

I think the existing reference is explicit about what :as does (binds the init-expr) and what :or does (supply default values if they are not found in the init-expr). No feature described here implies that init-expr is modified. The semantics of these two features are not order dependent (obviously the implementation has some order, but as nothing modifies init-expr, this is not important). Additionally, the example immediately following covers the case of :or and :as being used together and demonstrates that providing an :or default does not change the init-expr bound by :as. So, I think the existing text covers everything already.

Also, there are additional examples in the destructuring guide https://clojure.org/guides/destructuring.

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

2 participants