Nim Programming Cookbook // Data structures and Algorithms

Nim provides a variety of useful data structures such as arrays, sequences, sets, strings, tuples, tables. We will look at strings in a later chapter.


Unpacking a tuple into separate variables


You have a tuple of N-elements that you want to unpack into N seperate variables.


let address = ("Royal Rd", "Kingville", 11234)
let (s,c,z) = address
echo s
echo c
echo z

Practical uses:

import os
  path = "/usr/local/bin/6m"
  (dir, name, ext) = splitFile(path)
echo dir
echo name
echo ext