-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use Values
to create and match value Expr
s
#10673
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
Use Values
to create and match value Expr
s
#10673
Conversation
d5a606b
to
23282e9
Compare
I find it counter-intuitive with respect to Scala convention. In Scala, when we call |
We do the same to create an To be complete we could add expr match
case expr: Value[T] => expr.get
case _ => But those operations would be more expensive at runtime than the current ones. |
23282e9
to
ec9e8c0
Compare
* Replace `Expr.apply` with `Value.apply` * Replace `Expr.unapply` with `Value.unapply` * Replace `Exprs.unapply` with `Values.unapply` * Aligns with `expr.value` and `expr.valueOrError` * Deprecate old definitions in 3.0.0-M3 and remove them in 3.0.0-RC1 for simpler migration * Add back deprecated `Unlifted`, `unlift` and `unliftOrError` to help migration from 3.0.0-M2 to 3.0.0-M3
ec9e8c0
to
1d63579
Compare
So now instead of: def intValue: Expr[Int] = Expr(something) It will be? def intValue: Expr[Int] = Value(something) This seems unnecessarily confusing. What is the motivation? It seems this is one of those things that completely makes sense from the internals knowing the internals of the Tasty-Reflect API but it utterly confusing for a new user who might want to learn tasty macros. |
The motivation is that @liufengyun preferred expr match
case '{ foo(${Value(x)})} => x And we need to keep them in sync to avoid further confusion. I did not mind |
Why can't you do something like |
It would be a bit too long for an operation that we use all the time. |
Is there anything else you can do other then rename the Expr constructor? Any other thing you could possibly change the value-match API to? Knowing that 'Value' needs to be used to construct 'Expr' is really, really confusing to a new user that does not know Tasty-Reflect internals. I really want many people to be able to this API easily. Right now it's just me annoying you about this stuff but in half a year when more people start using this API they'll start yelling about these things that will look like inconsistencies to them. Literally, any solution for this is better other renaming the entire Expr-constructor API. |
I was not convinced by this change from the start. I promised I would try it out to find out if it was a good idea. It clearly has more drawbacks than what I originally anticipated. Thank you for all the feedback. |
Currently
Expr(x)
is used to create code that will produce a copy of the value. In extractors, it will take the code that creates a copy of the value and will create a copy of the value and return it. So far it was not always clear to everyone what is the difference betweenExpr(...)
and'{...}
. UsingValue
and constructor/extractor the intention of the code clearer.Expr.apply
withValue.apply
Expr.unapply
withValue.unapply
Exprs.unapply
withValues.unapply
expr.value
andexpr.valueOrError
Unlifted
,unlift
andunliftOrError
to help migration from 3.0.0-M2 to 3.0.0-M3Migration from 3.0.0.M2