Skip to content

Add syntax for higher order quote pattern holes #8876

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

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented May 4, 2020

  • Make typer explicitly type higher-order quasiquotes
  • Add higher-order quasi-pattern concept to the Matcher (avoid ambiguities with splice applied to arguments)
  • Introduce unambiguous syntax for higher-order quasi-patterns
  • Add documentation
case ${ val a = 3; $body(a): Int } => // higher-order quasi-patterns
case ${ val a = 3; ${fn}(a): Int } => // match an application 

@nicolasstucki nicolasstucki force-pushed the add-syntax-for-higher-order-quote-pattern-holes branch 6 times, most recently from 24a4798 to a0445e3 Compare May 8, 2020 12:38
@nicolasstucki nicolasstucki requested a review from liufengyun May 8, 2020 12:39
@nicolasstucki nicolasstucki marked this pull request as ready for review May 8, 2020 14:33
@nicolasstucki nicolasstucki force-pushed the add-syntax-for-higher-order-quote-pattern-holes branch 2 times, most recently from 555010d to 6e4ac13 Compare May 11, 2020 14:18
@nicolasstucki
Copy link
Contributor Author

As discussed offline, we will try to encode it with the syntax

case ${ val a = 3; ${body}{a}: Int } => 

@nicolasstucki nicolasstucki force-pushed the add-syntax-for-higher-order-quote-pattern-holes branch from 6e4ac13 to 229924f Compare May 13, 2020 08:47
@nicolasstucki
Copy link
Contributor Author

Note that there is a possible improvement for multiple parameters if we allow commas in block in the parser ${f}{x,y,z}.

@nicolasstucki nicolasstucki marked this pull request as draft May 13, 2020 09:49
@nicolasstucki nicolasstucki marked this pull request as ready for review May 18, 2020 06:16
* Make typer explicitly type higher-order quasiquotes
* Add higher-order quasi-pattern concept to the Matcher (avoid ambiguities with splice applied to arguments)
* Introduce unambiguous syntax for higher-order quasi-patterns
* Add documentation
* Warn if old syntax is detected
```scala
case ${ val a = 3; ${body}{a}: Int } =>
```
@nicolasstucki nicolasstucki force-pushed the add-syntax-for-higher-order-quote-pattern-holes branch from b284973 to f6b48a5 Compare May 18, 2020 12:33
@odersky odersky self-assigned this May 18, 2020
@nicolasstucki nicolasstucki requested review from odersky and removed request for liufengyun May 18, 2020 15:23
@odersky
Copy link
Contributor

odersky commented May 24, 2020

I am still not sure about the best syntax. My original proposal was to use

$body{y}

for the instantiated splice, and to reserve ${body}{y} for the case body should be spliced as is and then be applied to the block {y}. But it gets ugly for multiple parameters. I am a fan of neither of the alternatives

$body{y, z}
$body{(y, z)}

The first uses a comma in a block, which never happens otherwise and the second looks like (y, z) is a tupled argument where it is not. If we have to choose, I'd go for the first.

But before settling on this, a question: If we leave it as

$block(y)

how often (relatively speaking) is this a higher-order hole? If that's the common case, can we maybe live with the fallback

${block}(y)

for the uncommon case where $block is spliced in front of the literal argument list (y)?

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have another discussion about the best syntax.

@odersky odersky removed their assignment May 24, 2020
@nicolasstucki nicolasstucki force-pushed the add-syntax-for-higher-order-quote-pattern-holes branch from 7a34f45 to 75d8ba9 Compare May 29, 2020 08:46
@nicolasstucki nicolasstucki force-pushed the add-syntax-for-higher-order-quote-pattern-holes branch from 315cbde to f03d0a3 Compare May 29, 2020 10:55
@nicolasstucki
Copy link
Contributor Author

@odersky I updated the syntax to the one we discussed in the weekly meeting.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

@odersky odersky assigned nicolasstucki and unassigned odersky May 29, 2020
@nicolasstucki nicolasstucki merged commit 1ef1765 into scala:master Jun 2, 2020
@nicolasstucki nicolasstucki deleted the add-syntax-for-higher-order-quote-pattern-holes branch June 2, 2020 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants