proc lfecho*[T](data: T) = echo '\L', data
How can I fix:
proc lfecho(x: varargs[typed]) = echo '\L', x
proc lf2echo(x: varargs[typed, `$`]) = echo '\L', x
Can I rename a standard library procedure?
Compiler outputs errors for the lines to be fixed.
The question would be how to declare and pass a varargs set as parameter to a procedure.
I found a solution by using a generic parameter. I wonder if that introduces some level of overhead. In any case I'd like to fix those errors.
proc lf2echo(x: varargs[typed, `$`]) =
echo x
proc lf2echo(x: varargs[typed]) =
echo x
Same error for both forms.
: invalid type: 'typed' in this context: 'proc (x: varargs[typed])' for proc
(26, 10) Error: type mismatch: got <varargs[typed]>
but expected one of:
proc echo(x: varargs[typed, `$`])
first type mismatch at position: 1
required type for x: varargs[typed]
but expression 'x' is of type: varargs[typed]
The way to present echo with the expected
[typed, `$`]
seems to be a macro, quite close to the C va_arg() macro.
Thanks for the exact reference.
proc lfecho*[T](data: T) = echo '\L', data
only works for a single parameter.
The following is the solution:
import strutils
proc lf2echo(data: varargs[string ,`$`]) =
echo '\L', join data
lf2echo "N", ' ', "I'm"
proc lfecho(data: varargs[string ,`$`]) =
write(stdout, "\L")
for s in items(data):
write(stdout, s)