Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import strutils
- # Get a label as a sequence of strings, one for each line in the label.
- # Labels are delimited by a line containing only the terminator string.
- # Leading blank characters, blank lines and empty labels are discarded.
- # An empty label is returned to indicate the end of the input stream.
- proc getlabel(stream=stdin, terminator="&"): seq[string] =
- result = @[]
- for line in stream.lines:
- let sline = strip(line)
- if sline == terminator:
- if result.len != 0:
- break
- elif sline.len != 0:
- result.add(sline)
- proc group[T](fn: proc: T, groupsize: int): seq[T] =
- result = newseq[T](groupsize)
- for i in 0..<groupsize:
- result[i] = getlabel()
- while true:
- ##### This fails
- #var labels = group[seq[string]](getlabel, 2)
- ##### but this works
- var labels = group[seq[string]](proc: seq[string] = getlabel(), 2)
- #####
- if labels[0].len == 0:
- break
- echo "Line of labels: ", labels
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement