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

Allow nested destructuring with key->key #289

Open
Fuco1 opened this issue Feb 27, 2019 · 4 comments
Open

Allow nested destructuring with key->key #289

Fuco1 opened this issue Feb 27, 2019 · 4 comments
Labels
discussion enhancement Suggestion to improve or extend existing behavior

Comments

@Fuco1
Copy link
Collaborator

Fuco1 commented Feb 27, 2019

(-let (((&plist :foo->:bar value) (list :foo (list :bar "x"))))
  (message "value is %s" value))

;; should also work like this to support "string"->"keys"
(-let (((&plist :foo -> :bar value) (list :foo (list :bar "x"))))
  (message "value is %s" value)

We can also think about a different delimiter, but not . because that is the cons read syntax.

@cireu
Copy link
Contributor

cireu commented Mar 15, 2019

I think use the form .a.b.c like let-alist to get nested alist is perfectly well.

@Fuco1
Copy link
Collaborator Author

Fuco1 commented Mar 18, 2019

@cireu That works fine if the keys are symbols, but what to do with strings? "foo"."bar" is not correct read syntax, and adding the dot to the string might break lookup for strings with dots.

@cireu
Copy link
Contributor

cireu commented Mar 19, 2019

What about this?

(-let [(&alist (-> "a" "b") value) '((a . (b . 3)))] a)
;; => 3

@twlz0ne
Copy link

twlz0ne commented Apr 8, 2020

Or without any delimiter/indicator:

(-let [(&alist '(a "b") value) '((a . (("b" . 3))))] value)
;; => 3

@Fuco1 Fuco1 added discussion enhancement Suggestion to improve or extend existing behavior labels Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement Suggestion to improve or extend existing behavior
Projects
None yet
Development

No branches or pull requests

3 participants