tcnstseq.nim 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. discard """
  2. output: '''
  3. AngelikaAnneAnnaAnkaAnja
  4. AngelikaAnneAnnaAnkaAnja
  5. AngelikaAnneAnnaAnkaAnja
  6. onetwothree
  7. onetwothree
  8. onetwothree
  9. one1two2three3
  10. '''
  11. """
  12. # Test the new implicit conversion from sequences to arrays in a constant
  13. # context.
  14. import strutils
  15. block t1:
  16. const
  17. myWords = "Angelika Anne Anna Anka Anja".split()
  18. for x in items(myWords):
  19. write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja
  20. echo ""
  21. block t2:
  22. const
  23. myWords = @["Angelika", "Anne", "Anna", "Anka", "Anja"]
  24. for i in 0 .. high(myWords):
  25. write(stdout, myWords[i]) #OUT AngelikaAnneAnnaAnkaAnja
  26. echo ""
  27. block t3:
  28. for w in items(["Angelika", "Anne", "Anna", "Anka", "Anja"]):
  29. write(stdout, w) #OUT AngelikaAnneAnnaAnkaAnja
  30. echo ""
  31. block t2656:
  32. iterator it1(args: seq[string]): string =
  33. for s in args: yield s
  34. iterator it2(args: seq[string]): string {.closure.} =
  35. for s in args: yield s
  36. iterator it3(args: openArray[string]): string {.closure.} =
  37. for s in args: yield s
  38. iterator it4(args: openArray[(string, string)]): string {.closure.} =
  39. for s1, s2 in items(args): yield s1 & s2
  40. block:
  41. const myConstSeq = @["one", "two", "three"]
  42. for s in it1(myConstSeq):
  43. stdout.write s
  44. echo ""
  45. for s in it2(myConstSeq):
  46. stdout.write s
  47. echo ""
  48. for s in it3(myConstSeq):
  49. stdout.write s
  50. echo ""
  51. block:
  52. const myConstSeq = @[("one", "1"), ("two", "2"), ("three", "3")]
  53. for s in it4(myConstSeq):
  54. stdout.write s
  55. echo ""