Skip to content

Create a Pcase pattern that works like -let.#413

Open
okamsn wants to merge 2 commits intomagnars:masterfrom
okamsn:pcase
Open

Create a Pcase pattern that works like -let.#413
okamsn wants to merge 2 commits intomagnars:masterfrom
okamsn:pcase

Conversation

@okamsn
Copy link
Copy Markdown

@okamsn okamsn commented Mar 3, 2024

This PR is the beginning of a pcase pattern that works like -let. For me, this would resolve #376 (which I opened).

Before I copy the tests for -let and work through the edge cases of the pattern, would you be willing to merge a pcase pattern that works like -let?

@basil-conto basil-conto added the enhancement Suggestion to improve or extend existing behavior label Apr 7, 2024
@okamsn okamsn force-pushed the pcase branch 3 times, most recently from 672d344 to abc48e2 Compare July 21, 2024 02:02
- Create file `dash-pcase.el`.
- Copy tests of `-let` (except for parallel binding tests)
  to test pattern in `pcase` and `pcase-let`.
- Update `README.md` and Info documentation using `make`.
@okamsn okamsn marked this pull request as ready for review July 21, 2024 02:08
@okamsn
Copy link
Copy Markdown
Author

okamsn commented Jul 21, 2024

This is now ready for review.

I've copied the tests of -let for testing the pattern in pcase-let and pcase, except for a test of parallel bindings for pcase, which does not apply in that context.

Should the &hash? for only match hash table, or should it match if the value is nil?

Do you want any changes in how the code works or its style?

Thank you.

- Create a substitute for `gensym` if `gensym` is not available.
- Warn that `dash-pcase` not supported in Emacs versions less than
  25.1.
- Only run tests if `pcase-defmacro` is bound.
@okamsn
Copy link
Copy Markdown
Author

okamsn commented Jul 28, 2024

I have updated the code to use dash--match-make-source-symbol when gensym is not available.

How would you like to handle Emacs versions when pcase-defmacro is not defined? It was added in Emacs 25.1. I put the code in an if expression with a warning if pcase-defmacro isn't bound. Would you like it done some other way?

@okamsn
Copy link
Copy Markdown
Author

okamsn commented Aug 29, 2024

Another option would be making dash-pcase.el a separate package.

@basil-conto, do you have an opinion on how to handle pcase-defmacro not being defined in Emacs 24?

@basil-conto
Copy link
Copy Markdown
Collaborator

Another option would be making dash-pcase.el a separate package.

I don't really have an opinion on this; either way would work for me (I'm also quite unfamiliar with this part of Dash).

@Fuco1, @magnars any thoughts?

@basil-conto, do you have an opinion on how to handle pcase-defmacro not being defined in Emacs 24?

IIUC this feature is about hooking Dash destructuring into pcase, when possible.

IMO if it is not possible, Dash does not need to do anything: users running Emacs 24 should neither expect Dash to invent a pcase feature that pcase does not itself provide; nor should they see warnings about Dash not being able to hook into pcase.

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

Successfully merging this pull request may close these issues.

Make dash--match public?

2 participants