-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add scala.quoted.Expr.unapply
as dual of Expr.apply
#10580
Conversation
@liufengyun this improves the issues with the |
1d3a751
to
25cd0b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the diff below, I find Const
make the program more readable and easily understandable:
- case '{ power($x, ${Const(y)}) } =>
+ case '{ power($x, ${Expr(y)}) } =>
The point of this PR is to improve the usability of - case '{ power(${Unlifted(x)}, ${Unlifted(y)}) } => Expr(power(x, y))
+ case '{ power(${Expr(x)}, ${Expr(y)}) } => Expr(power(x, y)) |
b55981b
to
4d746f5
Compare
If we look at the full code it is actually much clearer with - case '{ power($x, ${Const(y)}) } =>
- if y == 0 then Expr(1)
- else '{ times($x, power($x, ${Expr(y-1)})) }
+ case '{ power($x, ${Expr(y)}) } =>
+ if y == 0 then Expr(1)
+ else '{ times($x, power($x, ${Expr(y-1)})) } Though this is out of scope for this PR |
4d746f5
to
8fb7783
Compare
This is clearly the most intuitive version we had so far due to the symmetry between Expr(4) match
case Expr(n) => Expr(n) '{ println(5) } match
case '{ println(5) } =>
'{ println(5) } '{ println(${Expr(5)}) } match
case '{ println(${Expr(n)}) } =>
'{ println(${Expr(n)}) } |
`Expr.unapply` replaces `Unlifted.unapply` using the same signature that uses an `Unliftable` to perform the unlifting. The overload the works on sequences of expression is moved to `Exprs.unapply` (similar to `Consts.unapply`).
8fb7783
to
f969052
Compare
Having an |
|
Right, by the |
Expr.unapply
replacesUnlifted.unapply
using the same signature that uses anUnliftable
to perform the unlifting. The overload the works on sequences of expression is moved toExprs.unapply
(similar toConsts.unapply
).Migration