Hello!

I think this is probably a simple answer, but I've been banging on it for too 
long now. I want to process the lines of a file in parallel. The R code I am 
trying to emulate is: 
    
    
    library(parallel)
    library(data.table)
    file <- commandArgs(trailingOnly=T)
    df <- fread('cat /dev/stdin', header=F, sep="\t")
    totals <- mclapply(df, function(x) {
        sum(grepl("bc", x, ignore.case=T))
    }, mc.cores=ncol(df))
    print(sum(unlist(totals))
    
    
    Run

Here is my Nim code: 
    
    
    import strutils, sequtils, threadpool
    {.experimental: "parallel".}
    
    func countBC(line:string): int =
        for val in line.split('\t'):
            if "bc" in toLower(val[1..<4]):
                inc(result)
    
    
    proc main() =
        var count = 0
        var lines = stdin.readAll.splitLines[0 .. ^2]
        var counts = newSeqOfCap[int](lines.len)
        
        parallel:
            for i in 0 .. lines.high:
                counts[i] = spawn countBC(lines[i])
        
        echo foldl(counts, a + b, 0)
    
    main()
    
    
    Run

The error I get is count_lines_parallel_nim.nim(18, 20) Error: cannot prove: i 
<= len(counts) + -1 (bounds check)

What do I need to do to let the compiler know that counts has the same length 
as lines?

Reply via email to