Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import strutils
  2.  
  3. # Get a label as a sequence of strings, one for each line in the label.
  4. # Labels are delimited by a line containing only the terminator string.
  5. # Leading blank characters, blank lines and empty labels are discarded.
  6. # An empty label is returned to indicate the end of the input stream.
  7. proc getlabel(stream=stdin, terminator="&"): seq[string] =
  8. result = @[]
  9. for line in stream.lines:
  10. let sline = strip(line)
  11. if sline == terminator:
  12. if result.len != 0:
  13. break
  14. elif sline.len != 0:
  15. result.add(sline)
  16.  
  17. proc group[T](fn: proc: T, groupsize: int): seq[T] =
  18. result = newseq[T](groupsize)
  19. for i in 0..<groupsize:
  20. result[i] = getlabel()
  21.  
  22. while true:
  23. ##### This fails
  24. #var labels = group[seq[string]](getlabel, 2)
  25. ##### but this works
  26. var labels = group[seq[string]](proc: seq[string] = getlabel(), 2)
  27. #####
  28. if labels[0].len == 0:
  29. break
  30. echo "Line of labels: ", labels
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement