-
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
Add clojure style destucturing #1940
Conversation
|
f4d0d4b
to
60ee445
Compare
I think all the tests issues are resolved now. |
Thanks for your work on this. It looks like it's coming along. It looks to me like the syntax for dictionary destructuring is still backwards. For example, to get the number 3 from It's not clear that Test how Test what happens when the destructuring pattern fails to match the rvalue, as in Describe what "This might not be necessary in the future, see #846" — This issue is closed. In the tests, there are places where you use The subroutine In the assertion Don't forget to update the copyright year. Remove all TODO, FIXME, and similar comments. Plans for Hy should go in the issue list, not the code. |
I think that this is a matter of convention. Since I was trying to copy the way clojure does destructuring, it makes sense to me to copy this as well.
Added a test for this. It seems to just work. (=: {:keys [a? -b? c->d]} {:a? 1 :-b? 2 :c->d 3})
[a? -b? c->d] ; => [1 2 3]
Sorry I should have added more documentation. All the 'patterns' return
Done
I made both list destructuring and iterator destructuring convert their arguments into a list and iterator respectively, so the rest argument will be a list or an iterator, not a string. I think that this makes more sense this way as it allows iterable to be passed to both. So something like
I added keyword destructuring to lists, which allows the (defn+ foo [[a b] {:keys [c d]} :& {:strs [e f]}]
"bar foo"
[a b c d e f])
(foo [1 2] {:c 3 :d 4} "e" 5 "f" 6) ; => [1 2 3 4 5 6] Thus you don't really need |
Good work!
I think you forgot this one. Test While it may be true that the special symbols like |
5052db1
to
b0455a5
Compare
Fixed
I didn't think of this, so currently, there the macro doesn't do any explicit mangling. What should be the desirable behaviour? Unmangle everything?
Currently all the special symbols are just treated like any other variable name. So |
Hmm. It's not obvious. Since the introduction of "late mangling" in #1517, the symbol
I think the latter makes sense. And you can add a test that shows that all the would-be special symbols are treated as ordinary in this context. |
Done |
Okay, looking good. Here's what's left:
|
b47b278
to
8248ae6
Compare
I decided to rename |
8248ae6
to
21b0470
Compare
I think that's all done now. |
I think you need to add a link to your new page from |
21b0470
to
d6d8b11
Compare
Thanks! I've added it. |
This makes me unseemly happy! Thank you peaceamongworlds! |
By the way, should we also have |
If you like. |
d6d8b11
to
14b17af
Compare
I've added them now. |
It doesn't look like the async variants actually expand to use the |
14b17af
to
aaf3d2f
Compare
That was silly of me. It's fixed now. |
You dropped this 👑 |
aaf3d2f
to
8c4f31b
Compare
Co-authored-by: gilch <[email protected]>
8c4f31b
to
8f1efac
Compare
This also closes #1326. |
Closes #1936.
Builds on #1328.
Mainly updated old syntax and refactored some of the code, but the main ideas are essentially the same.
Also added
defn+
,fn+
, andlet+
macros, which have clojure-style destructuring within their arguments.