So, the scenario is this:
I have an array (ValueArray) of Value`s. (which is a `ref object with a d OrderedTable field).
Long story short, I want to sort this array of Values by dictionary key.
So... this is what I've done:
let sorted: ValueArray = x.a.sorted(
proc (x, y: (Value,Value)): int =
cmp(x.d[aBy], y.d[aBy]), order=SortOrder.Descending)
where aBy is the key by which I want to sort this array of tables.
However, the compiler seems not to know that x and y being Value`s have a `d field:
Error: undeclared field: 'd'
How do I deal with this?
Yes, of course. The Value objects (and their fields) are being used in hundreds of different places across the project.
For some reason, it's inside the custom cmp proc that they're not recognized.
P.S. In case it matters, the code in question is inside a template.
I just spotted it myself! Jesus.
This is the correct one:
let sorted: ValueArray = x.a.sorted(
proc (v1, v2: Value): int =
cmp(v1.d[aBy.s], v2.d[aBy.s]), order=order)
I was using (Value,Value) (a tuple) for the custom cmp proc. And while this valid for sorting OrderedTable instances, it's obviously not for sorting simple arrays.
Thanks a lot for looking into it. My bad!