libminizinc icon indicating copy to clipboard operation
libminizinc copied to clipboard

Feature request: function to get the dimenstion of Tuple/Record

Open CervEdin opened this issue 2 years ago • 2 comments

I've done a quick look to see if there's a MiniZinc function that can get the dimension of a Record/Tuple but haven't been able to find anything in the standard library. I'm guessing there is no such function.

It would be really neat to have one!

Something like this

type r = par record( int: x, int: y);
int  :  r_size = length(r); % 2

CervEdin avatar Oct 02 '23 11:10 CervEdin

I'm afraid that the type of the argument of the length function requested is currently not expressible in the MiniZinc language. It might be something we could think about in the future. (We are thinking about what (type of) generic operations on records and tuples might need to be added).

Could you tell us what you would like to use this information for?

Dekker1 avatar Oct 18 '23 00:10 Dekker1

The specific case I though of occurred when I was transforming an array of tuples/records to an array of arrays.

I did it something like this

type xy = tuple(int, int);
par xy: t = (1,2);
array[int, int] of int: arr2 = [
  [ t.1, t.2 ][i]
  | i in 1..lenght(t)
];

but hardcoding the length.

I was struck that it may be a useful function, even though one can't access tuples via their index, like in python (I guess?).

Doesn't strike me as an extremely worthwhile function, but perhaps useful enough to warrant consideration in the future.

CervEdin avatar Oct 21 '23 10:10 CervEdin