Skip to content

Support simple higher order pattern splices #7591

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

Merged
merged 4 commits into from
Dec 12, 2019

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Nov 20, 2019

This fixes the quoted pattern matcher runtime to never return open code.

  • case '{ val x: Int = 3 ; $body } will only match if body does not contain a reference to x. Same for other kind of definitions in the pattern.
  • case '{ val x: Int = 3; ($f: Int => Int)(x) } will match any body of type Int but will wrap it in a lambda that contains x as an argument.
  • Introduce Expr.open that takes a expression of a lambda and explicitly opens it temporarily an provides a way to re-close any subexpression of its body (unsafe if not used properly).

@nicolasstucki nicolasstucki self-assigned this Nov 20, 2019
@nicolasstucki nicolasstucki force-pushed the quoted-pattern-open-holes branch 3 times, most recently from abafaea to 3be5d70 Compare November 21, 2019 11:04
@nicolasstucki nicolasstucki force-pushed the quoted-pattern-open-holes branch 2 times, most recently from 932d63c to 634e976 Compare November 22, 2019 14:55
@nicolasstucki nicolasstucki force-pushed the quoted-pattern-open-holes branch 2 times, most recently from c81f0e1 to 8410346 Compare December 2, 2019 17:16
@nicolasstucki nicolasstucki marked this pull request as ready for review December 2, 2019 17:20
@nicolasstucki nicolasstucki force-pushed the quoted-pattern-open-holes branch from 8410346 to b7937b8 Compare December 5, 2019 13:46
Copy link
Contributor

@liufengyun liufengyun 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

import qctx.tasty.{given, _}
val (params, bodyExpr) = paramsAndBody(f)
content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](e.unseal, params, List(v.unseal)).seal.asInstanceOf[Expr[t]])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear how open/close is useful. I'd suggest removing them for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cannot remove it without breaking some tests. I particular those that test the code infrastructure for what @biboudis is working on.

This fixes the quoted pattern matcher runtime to never return open code.

* `case '{ val x: Int = 3 ; $body }` will only match if body does not contain a reference to `x`. Same for other kind of definitions in the pattern.
* `case '{ val x: Int = 3; ($f: Int => Int)(x) }` will match any body of type `Int` but will wrap it in a lambda that contains `x` as an argument.
* Introduce `Expr.open` that takes a expression of a lambda and explicitly opens it temporarily an provides a way to re-close any subexpression of its body (unsafe if not used properly).
@nicolasstucki nicolasstucki force-pushed the quoted-pattern-open-holes branch from b7937b8 to a5c1ebb Compare December 12, 2019 09:55
@nicolasstucki nicolasstucki added this to the 0.21 Tech Preview milestone Dec 12, 2019
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

@nicolasstucki nicolasstucki merged commit 01dc942 into scala:master Dec 12, 2019
@nicolasstucki nicolasstucki deleted the quoted-pattern-open-holes branch December 12, 2019 13:37
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.

2 participants