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

enhancement: List matching on argument lists #1787

Open
jurgenvinju opened this issue Apr 11, 2023 · 1 comment
Open

enhancement: List matching on argument lists #1787

jurgenvinju opened this issue Apr 11, 2023 · 1 comment

Comments

@jurgenvinju
Copy link
Member

Describe the feature

I'd like to be able to list-match on constructor argument lists:

"nodeName"(int x, *value rest) // match an argument list that starts with an int and then zero or more value
and(*Bool args)                          // match the `and` constructor and both Bool arg and bind them to a list[Bool] named `args`

Currently when we have generic code on the level of type node we often have to use getName and getChildren in order to abstract from the number of arguments. The list-matching feature is much more elegant and shorter in such cases.

I'm guessing that this is a large change neither in the compiler nor in the interpreter. All we need to do is call getChildren first and then match the result against the list pattern, but only if at least one of the pattern variables is a list variable.

@jurgenvinju
Copy link
Member Author

Similarly, and for the sake of symmetry, I'd like to be able to splice argument lists for constructors:

list[Bool] args = [b1, b2]
and(*args)
"nodeName"(x, *rest)
  • The static type system would always return node in such a case
  • The dynamic type system would check the validity of the constructed tree against the name of the constructor and the grammar associated to it and throw an exception just like make does from the Type module.
  • like getChildren is hidden by matching, make will be hidden by splicing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant