Max Alekseyev on Fri, 10 May 2024 21:12:16 +0200


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

Re: apply / select are inconsistent on Maps


PS. A typo correction - I meant to say:
However, there is an issue that t_MAP is an *unordered* object, while t_VEC is an ordered one, so perhaps it should return a set (a sorted t_VEC) to make the output well-defined.

On Fri, May 10, 2024 at 3:09 PM Max Alekseyev <maxale@gmail.com> wrote:
Hi Bill,

I trust your best judgement on fitting the requests into the current framework. Hence I sometimes formulate them sketchy.
Anyway, since you requested specifics - here are some thoughts:

I think the default behavior of select() should be returning the object of the same type as its second argument. In the case of t_MAP it should be t_MAP. And the same applies for apply().
A hypothetical example:

===
? M=Map(); for(i=1,5,mapput(M,i,vector(i))); M
Map([1, [0]; 2, [0, 0]; 3, [0, 0, 0]; 4, [0, 0, 0, 0]; 5, [0, 0, 0, 0, 0]])

? select((x,y)->(x%2==1)&&(#y>1),M)
Map([3, [0, 0, 0]; 5, [0, 0, 0, 0, 0]])

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

Obtaining t_VEC output from t_MAP would be a nice optional addition for apply() function, say with flag=1. However, there is an issue that t_MAP is an ordered object, while t_VEC is an ordered one, so perhaps it should return a set (a sorted t_VEC) to make the output well-defined:

? apply((x,y)->-x,M,1)
[-5, -4, -3, -2, -1]

Regards,
Max

On Fri, May 10, 2024 at 11:19 AM Bill Allombert <Bill.Allombert@math.u-bordeaux.fr> wrote:
On Thu, May 09, 2024 at 01:10:57PM -0400, Max Alekseyev wrote:
> Support for binary function would be most general and helpful.

This is not a precise enough specification.
When suggesting an improvement, consider writing the documentation
and give a full example.

Otherwise we are required to guess what you need.

For example should select(f,t_MAP) return a t_MAP or a t_VEC ?

Cheers,
Bill.