-
Notifications
You must be signed in to change notification settings - Fork 213
Uniform tear-off syntax #691
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
Comments
Cf. this discussion on dart-misc: It would also be useful to consider tear-offs of instance methods independently of the receiver. That is, a method with Getters and setters could be handled as described above, we'd just change |
I don't see myself ever using They take the same number of characters, but the closure approach is easier to refactor. What about: #a
#+a
#-a
#a.x
#=a.x
#Foo
#Foo.named ? |
The character doesn't really matter. |
Does this have the semantics of picking a concrete implementation statically? Or will it have the semantics of wrapping with a closure and the concrete implementation is still picked at runtime? I don't think the former would work: class Foo {
int get _private => 1;
int get public => 2;
void doStuff() {
print(_private + public);
}
}
// Some other library.
class Bar implements Foo {
@override
void doStuff() {}
@override
int get public => 3;
// No override of _private possible
}
void main() {
void Function(Foo) tornOff = Foo::doStuff;
tornOff(Foo()); // OK
tornOff(Bar()); // throws? What would the error be?
} I think the latter would be fine. Effectively |
No, the idea is simply that with |
What about a default first parameter name called
|
Right, my point is that I don`t think we really need new tear-off syntax, if we have #265. |
There is one thing that a tear-off is capable of doing that we can't emulate with a manual rewrite, namely the special behavior for equality tests (operator |
Isn't this the same functionality of this proposal that was aproved back in 2015? |
It is similar, but the generalized tear-offs as described in said proposal are not supported in Dart today (not in the specification, not in the implementation). |
Any updates after a year? This question may be related: https://stackoverflow.com/questions/67534998/getter-setter-method-passed-as-a-pseudo-function-pointer-in-dart?noredirect=1#comment119380290_67534998 |
@tatumizer Hi is it implemented? (I see it closed) thanks |
@tatumizer All right :( |
Edit: misread and thought tatumizer was a contributor 😅 |
(based on discussion in #376)
Proposing new syntax for tear-offs to cover several use cases. General form:
obj.(thing-to-tear-off)
Examples:
a.(+) // operator tear-off
a.(unary-)
a.(get x) // getter tear-off
a.(set x) // setter tear-off
Foo.(new) // default constructor tear-off
Foo.(new named) // named constructor tear-off
The text was updated successfully, but these errors were encountered: