[nim-dev] Re: Error: illegal capture 'a' -- I have no idea what that means

  • From: Krux02 <arne.doering@xxxxxxx>
  • To: nim-dev@xxxxxxxxxxxxx
  • Date: Wed, 7 Dec 2016 14:04:23 +0000

That has to do with the fact that lambdas in Nim are not as great as in other 
languages. This is how I got it to compile:


```Nim
proc cmp(a, b: int): int =
  (a > b).int - (a < b).int

proc quicksort(a: var openarray[int]; left, right: int; cp: proc (a, b: int): 
int) =
  proc qsort(a: var openarray[int]; left, right: int) =
    var l, r, p: int
    let len = right - left
    let len2 = len div 2
    if true: # insertion sort on tiny array
      for i in left + 1 .. right:
        for j in countdown(i, left + 1):
          if cp(a[j], a[j - 1]) >= 0: break # this is the line with error
          swap(a[j], a[j - 1])
      return
  qsort(a, a.low, a.high)

var
  x: array[2e6.int, int]

quicksort(x, x.low, x.high, cmp)
```

Other related posts: