You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For variadic functions the language already implicitly allocates argv slice as it happens e.g. in the following log.Print call:
log.Print(1, 2, 3, 4, "hello")
// ^^^ compiler implicitly allocates argv := []interface{}{1, 2, 3, 4, "hello"}// and essentially passes that argv to log.Print
So from this point of view implicitly allocating new argv2 = append([]interface{}{subject}, argv...) for (subject, argv...) case should be consistent.
I propose: for variadic functions with signature ...T allow merging extra arguments with final argv... if all extra arguments are assignable to T and argv is assignable to []T. If both extra argumens and final argv... are present, a new []T slice is allocated and passed to called function. The content of passed slice is append([]T{extra1, extra2, ..., extraN}, argv...).
Thanks beforehand,
Kirill
The text was updated successfully, but these errors were encountered:
@cznic: log.Print was just an example. The actual case where I hit this was not about log.Print and there was no ...f helpers ready. E.g. it is when you have to use glog.InfoDepth and many other cases. The issue here is about the language, not particular logging case.
@josharian thanks for the pointer. Looks like this could be generalized to (extra1, extra2, argv1..., extra3, argv2..., extra4, argv3...).
Hello up there. Currently the following does not compile:
and gives
to make it work one has to change myprint as follows:
which adds much noise to actual signal.
For variadic functions the language already implicitly allocates argv slice as it happens e.g. in the following log.Print call:
So from this point of view implicitly allocating new
argv2 = append([]interface{}{subject}, argv...)
for(subject, argv...)
case should be consistent.I propose: for variadic functions with signature
...T
allow merging extra arguments with finalargv...
if all extra arguments are assignable to T and argv is assignable to []T. If both extra argumens and finalargv...
are present, a new []T slice is allocated and passed to called function. The content of passed slice isappend([]T{extra1, extra2, ..., extraN}, argv...)
.Thanks beforehand,
Kirill
The text was updated successfully, but these errors were encountered: