I think this is an unnecessary use of macros here. Here is my version without 
them.
    
    
    type
      mtcars = object
        data : array[11,float64]
    
    const cols : array[11,string] = 
["mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"]
    
    echo(@cols)
    
    proc `-` (x:mtcars,y: mtcars): mtcars =
      for i in low(result.data) .. high(result.data):
        result.data[i] = x.data[i] - y.data[i]
    
    proc sqr (x:mtcars): mtcars =
      for i in low(result.data) .. high(result.data):
        result.data[i] = x.data[i] * x.data[i]
    
    proc difsqrsm (x:mtcars): float =
      for i in low(x.data) .. high(x.data):
        result = result + x.data[i]
    
    proc distance (x:mtcars,y: mtcars): float =
      var dif = x - y
      dif = sqr(dif)
      result = difsqrsm(dif)
    

unfortunately your csv reader depended on the layout with the named values and 
my change broke that. I am sorry that I don't have a solution for this at the 
moment. If you would have a good math library with vectors like those from e.g. 
Matlab or Eigen (c++) then you could use vector arithmetic and wouldn't even 
need to write a single loop. But I don't feel in position to recommend you a 
specific one from the current Nim options, I guess you would have to evaluate 
on your own. I changed your mtcars to contain float64 values only. I don't know 
if the `int` type is essential to you algorithm, I ignorantly assumend it is 
not (sorry if I might be wrong here).

Reply via email to