-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
Needs TriageIssue needs to be routed/triaged to a particular team stillIssue needs to be routed/triaged to a particular team stillenhancementNew feature or requestNew feature or requestmojoIssues that are related to mojoIssues that are related to mojo
Description
Review Mojo's priorities
- I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
I mainly want to be able to know how many arguments are being passed into a function as requested in #4144. But since we can't modify the behavior of VariadicList itself, then I request that we maybe allow other types like VariadicPack to be built from an argument list. An example:
from testing import assert_equal, assert_false
comptime Several[
elt_is_mutable: Bool,
origin: Origin[mut=elt_is_mutable],
//,
T: AnyType,
times: Int = 1,
is_owned: Bool = False,
] = VariadicPack[
elt_is_mutable=elt_is_mutable,
origin=origin,
is_owned,
type_of(T),
*Variadic.splat[T, times],
]
comptime SeveralTs[
elt_is_mutable: Bool,
origin: Origin[mut=elt_is_mutable],
//,
element_trait: type_of(AnyType),
is_owned: Bool,
*element_types: element_trait,
] = VariadicPack[
elt_is_mutable=elt_is_mutable,
origin=origin,
is_owned,
element_trait,
*element_types,
]
def main():
def test_trivial_type(a: Several[Int]):
@parameter
for i in range(a.__len__()):
assert_equal(a[i], 0)
def test_non_trivial_type(a: Several[String]):
@parameter
for i in range(a.__len__()):
assert_equal(a[i], "")
def test_trait(a: SeveralTs[Boolable]):
@parameter
for i in range(a.__len__()):
assert_false(a[i])
test_trivial_type(0, 0, 0)
test_non_trivial_type("", "", "")
test_trait("", 0, False, [])maybe could solve this doing something similar to how we deal with initializer list or literal collection initializers?
What is your motivation for this change?
#5919 (comment) and several other places.
Any other details?
I also think that if we solve this correctly we'll finally avoid the need of having 2 function signatures for things that receive a VariadicPack per se, and others that receive arguments in the function call itself
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs TriageIssue needs to be routed/triaged to a particular team stillIssue needs to be routed/triaged to a particular team stillenhancementNew feature or requestNew feature or requestmojoIssues that are related to mojoIssues that are related to mojo