Skip to content

Instantly share code, notes, and snippets.

@Yardanico
Created July 16, 2018 13:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yardanico/b6fee43f6da8a3bbf0fe048063357115 to your computer and use it in GitHub Desktop.
Save Yardanico/b6fee43f6da8a3bbf0fe048063357115 to your computer and use it in GitHub Desktop.
import macros
macro unpack*(args: varargs[untyped]): typed =
result = newStmtList()
let arr = args[0]
var i = 0
for arg in args.children:
if i == 0: inc i; continue
result.add quote do:
let `arg` = `arr`[`i` - 1]
inc i
let data = [1, 2, 3, 4, 5]
data.unpack(a, b, c, d, e)
echo a, b, c, d, e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment