tcnstseq.nim 1.5 KB

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