The following code
    
    
    import random, sugar
    from math import cumsummed
    
    type
      Generator[T] = () -> T
      TrafficLight = enum
        red, yellow, green
    
    proc genCDF[T, U](a: openArray[T], cdf: openArray[U]): Generator[T] =
      assert(a.len == cdf.len)
      result = proc(): T =
                random.sample(a, cdf.cumsummed)
    
    proc sample[T](gen: Generator[T], len: Natural = 10): seq[T] =
      result = newSeq[T](len)
      for i in 0..<len:
        result[i] = gen()
    
    var genColors = genCDF([red, yellow, green], [1, 6, 8])
    
    
    Run

results in this error message: 
    
    
     Error: 'a' is of type <openArray[TrafficLight]> which cannot be captured 
as it would violate memory safety
    
    Run

Is there any chance to solve this error?

Reply via email to