3

I'm trying to write wrapper for echo the code below doesn't work, playground

import sequtils, strutils, sugar

proc p*(args: varargs[typed, `$`]): void =
  echo args.map((v) => $v).join(" ")

Error:

/usercode/in.nim(3, 8) Error: invalid type: 'typed' in this context: 'proc (args: varargs[typed])' for proc
Alex Craft
  • 13,598
  • 11
  • 69
  • 133

1 Answers1

10
import sequtils, strutils, sugar

proc p*(args: varargs[string, `$`]): void =
  echo args.join(" ")

varargs accepts type to be converted to as first argument, so your code is almost correct, but you need to replace typed with string, and then the function call would be equivalent to p([$arg1, $arg2]) basically.

Nim by example for varargs - link

haxscramper
  • 775
  • 7
  • 17