nim-lang

end parameter in echo for Nim?


Python has end parameter in print()

print("You" , end = '@') 
print("Need2LearnAlot")

Will output --> You@Need2LearnAlot

Does Nim's echo has this kind of parameter?


Solution

  • You can create your own echo procedure, to do so.

    proc print(args: varargs[string, `$`], `end`: string = "\n") =
        for arg in args:
            stdout.write(arg)
        stdout.write(`end`)
    
    print 1, 2, 3, `end` = "\n===\n"
    

    Note that end in Nim is a special identifier, so you must escape it like that. More about varargs: https://nim-by-example.github.io/varargs/