Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Join array in nim

I’m not entirely sure why, but I can’t figure out how to join an array in Nim, here’s the code:

import std/strformat

proc check(to: int, multi: int, toreturn: string): string = 
  if to mod multi == 0:
    return toreturn
  else:
    return ""

proc ifempty(str :string, num: int): string =
  if len(str) == 0:
    return fmt"{num}"
  else:
    return str

var i: int = 1
while i <= 100:
  var checks = @[check(i, 3, "Fizz"), check(i, 5, "Buzz")]
  let toecho = ifempty(checks.join(""), i)
  echo(toecho)
  inc(i)

I’m expecting it to join the array, but all I get is the error

/home/runner/FavoriteJointLists/main.nim(18, 30) Error: attempting to call undeclared routine: ‘join’
exit status 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

join is defined in std/strutils, not std/strformat.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading