[NEW] variable argument list, like va_list
in C, and Varargs
in Java
#2821
Labels
feature
Proposed language feature that solves one or more problems
Hello,
In other, and mature languages like C/CPP, and Java, there is a concept of variable arguments(va),
Prominent use in existing(and mature) langs:
va_list
is used in thestdio.h
'sprintf(format, ...)
function, which takes a minimum of one, and a super-large(but finite) number of additional arguments, andvarargs
are used injava.util.Arrays.asList(T... a)
Why?
Dart is facing a problem, which is "Non-growable lists are implemented more efficiently than growable lists, but creating one is rather verbose and inconvenient"(from #2477(#2477)),
The new syntax, being proposed in that issue, is:
<int>[0, 1, 2]
for growable list, same as current/presentfinal <int>[0, 1, 2]
for non-growable/fixed-length list/arrayconst <int>[0, 1, 2]
for non-modifiable/immutable listProblem
The reserved words,
final
, andconst
are for, and act on the underlyingObject
, which isList<int>
here, and has no relation with the grow-ability or im-mutability of the entity/list, the proposed syntax seem like patchy work to me, and would definitely degrade the quality/logic in the syntax, and the trust of public, in dart's teamSolution
Adding var-args to dart would allow us to:
List<int>(0, 1, 2)
for growable list, with def asList<T>(T... va)
Array<int>(0, 1, 2)
for non-growable/fixed-length list/arrayFirmList<int>(0, 1, 2)
for non-modifiable/immutable listArrayList
overArray
, is possible, but more chars, and same forImmutableList
/UnmodifiableList
overFirmList
, maybeImmuList
/UnmodList
could be used,thanks
va_list
in C: cppreference.com, cprogramming.comVarargs
in Java: docs.oracle.comThe text was updated successfully, but these errors were encountered: