-
Notifications
You must be signed in to change notification settings - Fork 28
SIP-70 - Flexible Varargs #105
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
base: main
Are you sure you want to change the base?
Conversation
content/flexible-varargs.md
Outdated
``` | ||
|
||
### Javascript | ||
Javascript's expression `...` syntax works identically to this proposal. In Python, you can mix |
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.
Python should be Javascript
On the pattern side, the old gotcha is scala/bug#7623 (which has a lint on Scala 2). That is where two pat vars are satisfied by a single Seq, i.e., there is a kind of misalignment. (The example may temper ambition for patterns.) |
I started to wander if this SIP could help resolve this issue: scala/scala3#18009 mySelectable.foo(args1*)(args2*) should get desugared to something like mySelectable.applyDynamic("foo")(args1*, args2*).asInstanceOf[Foo] which is now illegal, but would be when this SIP gets implemented |
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.
What's proposed:
- Constructing varargs with multiple splices xs*, interspersed with normal values
- Deconstructing sequences with a single vararg pattern that can be somewhere in the middle of the sequence, not just at the end.
These are clear quality of life improvements. The construction part is the more important one, and it should be straightforward to implement. The pattern matching part is probably also easy to implement, but it might need some care to get good performance for linear sequences. E.g you have a long list and match with List(x, y, ys*, 2, 3)
you want to avoid multiple trips to the end of the list to match the 2
and 3
. Nevertheless, it looks quite doable.
I also think this SIP is a very nice improvement. You mention / suggest to use
I'm not sure if the scala> collection.immutable.ArraySeq.newBuilder.addOne(1).result()
-- [E172] Type Error: ----------------------------------------------------------
1 |collection.immutable.ArraySeq.newBuilder.addOne(1).result()
| ^
| No ClassTag available for Any
1 error found Interestingly, the same line works on Scala 2, the compiler infers If an explicit type argument is needed, the SIP should specify how that type is obtained. For patterns, we'll need to update the spec to say how This SIP doesn't change repeated parameters (of case classes), a repeated parameter will still be last in a case classs definition. An So the spec needs to map the new pattern shape onto to current case class parameter list shape (or unapplySeq return type shape). Note that |
The motivation for
Yes, definitions are unchanged. Not just for
Yes that is right. The trailing |
Co-authored-by: odersky <[email protected]>
Co-authored-by: odersky <[email protected]>
Co-authored-by: odersky <[email protected]>
No, I did not know that. Generally, I think it's better of the SIP does not specify a precise implementation scheme. The scheme might change in the future, and we should not have to change the SIP because of that. The In terms of what we have, it looks like basing the whole thing on |
No description provided.