tfortupleunpack.nim 630 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. discard """
  2. output: '''
  3. 123
  4. 113283
  5. 0
  6. 123
  7. 1
  8. 113283
  9. @[(88, 99, 11), (88, 99, 11)]
  10. @[(7, 6, -28), (7, 6, -28)]
  11. 12
  12. 110100
  13. '''
  14. """
  15. let t1 = (1, 2, 3)
  16. let t2 = (11, 32, 83)
  17. let s = @[t1, t2]
  18. for (a, b, c) in s:
  19. echo a, b, c
  20. for i, (a, b, c) in s:
  21. echo i
  22. echo a, b, c
  23. var x = @[(1,2,3), (4,5,6)]
  24. for (a, b, c) in x.mitems:
  25. a = 88
  26. b = 99
  27. c = 11
  28. echo x
  29. for i, (a, b, c) in x.mpairs:
  30. a = 7
  31. b = 6
  32. c = -28
  33. echo x
  34. proc test[n]() =
  35. for (a,b) in @[(1,2)]:
  36. echo a,b
  37. test[string]()
  38. iterator tuples: (int, (int, int)) = yield (1,(10, 100))
  39. template t11164 =
  40. for i, (a, b) in tuples():
  41. echo i, a , b
  42. t11164()