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

Set of problems should be open-ended #216

Open
gelisam opened this issue Jul 28, 2023 · 1 comment
Open

Set of problems should be open-ended #216

gelisam opened this issue Jul 28, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@gelisam
Copy link
Owner

gelisam commented Jul 28, 2023

Currently, the kernel language defines a Problem datatype which lists a small number of problems which the macro might currently need to solve, such as an expression, a type, or a pattern. It would be nice to allow libraries to extend this list.

For example, imagine an extensible library which provides pattern guards and allows the user to define variants, such as view patterns. The library must define a convention, which the user must follow when writing macros which cooperate with the library. The convention could be:

  1. the current Problem is an expression
  2. you can expect the scope to contain scrutinee, on-success, and on-failure
  3. to make a variable available to the RHS of the branch, generate a let which binds that variable and call on-success within the body of the let
  4. to try the next pattern, generate a call to on-failure

Thanks to this convention, it is now possible for the user to write a macro which cooperates with this library... But consider a macro like list, which makes sense in an expression context as well as a pattern context. Wouldn't it make sense to also allow list to cooperate with the pattern guard library? Alas, it cannot, because which-problem will return the same value, (expression _), in two of those three contexts. If the library could extend the list of possible problems, e.g. to add fancy-pattern, then list could distinguish between those two contexts.

@gelisam gelisam added the enhancement New feature or request label Jul 28, 2023
@gelisam
Copy link
Owner Author

gelisam commented Jul 28, 2023

Here is one possibility.

Once we implement #105, we could scrap which-problem and instead define separate syntax parameters indicating whether the current context is X or not. So the (current-expression-type) syntax parameter would provide a (Maybe Type), the (current-pattern-context) syntax parameter would return a (Maybe Unit), and the library could define a (current-fancy-pattern-context) syntax parameter of type (Maybe (Syntax, Macro Syntax, Macro Syntax)), to explicitly provide scrutinee and the continuations to the user's macro.

One difficulty with that approach is that setting the other syntax parameters to Nothing only a convention, and one which is hard to follow if different libraries can define different syntax parameters and don't know about each other. So maybe the kernel should provide a facility for registering a syntax parameter and setting all the registered syntax parameters to Nothing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant