Max Alekseyev on Thu, 09 May 2024 16:39:39 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

apply / select are inconsistent on Maps


Hello,
The following example shows that 
(i) apply() and select() disagree on what is argument of the function when applied to Map; and
(ii) select() produces List rather than Map as a result.

===
? M = Map()
%1 = Map([;])

? for(i=1,5,mapput(M,i,vector(i)))

? apply(x->print(x);x,M)
[0, 0]
[0]
[0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0, 0]
%3 = Map([1, [0]; 2, [0, 0]; 3, [0, 0, 0]; 4, [0, 0, 0, 0]; 5, [0, 0, 0, 0, 0]])

? select(x->print(x);x,M)
[[2, [0, 0]], Vecsmall([2, 4, 3])]
[[1, [0]], Vecsmall([0, 0, 1])]
[[3, [0, 0, 0]], Vecsmall([0, 0, 1])]
[[4, [0, 0, 0, 0]], Vecsmall([3, 5, 2])]
[[5, [0, 0, 0, 0, 0]], Vecsmall([0, 0, 1])]
%4 = List([[[2, [0, 0]], Vecsmall([2, 4, 3])], [[1, [0]], Vecsmall([0, 0, 1])], [[3, [0, 0, 0]], Vecsmall([0, 0, 1])], [[4, [0, 0, 0, 0]], Vecsmall([3, 5, 2])], [[5, [0, 0, 0, 0, 0]], Vecsmall([0, 0, 1])]])
===

Regards,
Max