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

Ability to define custom destructorings #276

Open
yyoncho opened this issue Nov 19, 2018 · 5 comments
Open

Ability to define custom destructorings #276

yyoncho opened this issue Nov 19, 2018 · 5 comments
Labels
enhancement Suggestion to improve or extend existing behavior

Comments

@yyoncho
Copy link
Contributor

yyoncho commented Nov 19, 2018

At this point, dash supports 4 different destructoring keyword (keys/hash/plist/alist) and from what I can see it will be not hard to add new keywords by providing a destructuring template(or macro?) to generate the getter.

Example usecases:

  • &hash which checks whether the map is empty before applying gethash
  • Custom destructuring for cl-defstruct, e. g.
(-let [(&my/struct slot1 slot2) value]
  ...)
@Fuco1
Copy link
Collaborator

Fuco1 commented Nov 19, 2018

Hi Ivan. This is something I haven't considered but it shouldn't be terribly difficult as you say. One would need to make sure the recursive expansions would still work, but so long as you do not publish your custom getter I guess the contract is your own.

The place to start at would be in the function dash--match in the second condition (consp match-form). Before the default case we can add something that would look at the symbol's property (using get) dash--matcher or something similar and execute that.

Would you be interested in trying to implement this (does what I said make any sense at all? :))

@Fuco1 Fuco1 added the enhancement Suggestion to improve or extend existing behavior label Nov 19, 2018
@yyoncho
Copy link
Contributor Author

yyoncho commented Nov 19, 2018

I have checked the code upfront, just wanted to know whether you are going to accept such PR - check #277 . I have not updated the docs if this is needed.

@yyoncho
Copy link
Contributor Author

yyoncho commented Feb 27, 2019

@Fuco1 is there a change to move this issue forward? In lsp-mode we are want to support both maps and alists and we are going to replace gethash with map-elt but we still do not have a solution for &hash destructoring. We spent a lot of time to migrate our code to use dash and it will be a pity if we now have to rewrite it again to use pcase-let or something like that.

@Fuco1
Copy link
Collaborator

Fuco1 commented Feb 27, 2019

@yyoncho I will merge this today, I promise!

@yyoncho
Copy link
Contributor Author

yyoncho commented Feb 27, 2019

Thank you @Fuco1 . Not sure whether it is ready for merging though (e. g. it lacks documentation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Suggestion to improve or extend existing behavior
Projects
None yet
Development

No branches or pull requests

2 participants