Does hylang support map destructuring like in clojure?
For example: https://gist.github.com/john2x/e1dca953548bfdfb9844#maps
Hy does not have mapping destructuring built in, though Python's iterable destructuring does work in Hy.
You can destructure maps in Python this way using list comprehensions, but it's limited, for example,
>>> dict(a=1, b=2, c=3)
{'a': 1, 'b': 2, 'c': 3}
>>> a, b, c = [_[k] for k in ['a', 'b', 'c']]
>>> a
1
>>> b
2
>>> c
3
This gets awkward when the dicts are nested in something, but sometimes this is good enough. It would be fairly easy to make a macro for this idiom in Hy.
I've also worked on a hy.contrib.destructure
module. It still hasn't been merged (not really finished), but the mapping destructuring part works. You could try using that if you need to work with deeply nested data. The synatx is similar to Clojure. The macros have docstrings and the unit tests have examples.
peaceamongworlds polished up my old destructuring branch. It was merged into master on January 31, 2021.
See the docs for the new module here.
Python will also have the ability to destructure mappings in its match
/case
statements, as of version 3.10.