| Bill Allombert on Sun, 14 Jan 2024 17:36:31 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| New GP function mapapply |
Dear PARI developers, I have added a new GP function mapapply: mapapply(~M,x,f): Applies the closure f to the image y of x by the map M and returns the evaluation of f. The closure f is eventually allowed to modify the components of y in place. To apply f to all entries of M use apply(f, M) instead. There are two main use cases: * performing a computation on a value without copying it: ? M=Map();mapput(~M,"a",mathilbert(100)); ? for(i=1,1000,matsize(mapget(M,"a"))) \\ Slow ? for(i=1,1000,mapapply(M,"a",matsize)) \\ Fast * modifying the components of the value in place, for example to append an element to a value of a map of lists. This require to use ~ in the function declaration. ? maplistput(~M,k,v) = mapapply(~M,k,(~y)->listput(~y,v)); ? M = Map(["a",List(); "b",List()]); ? maplistput(~M,"a",1234); M %3 = Map(["a",List([1234]);"b",List([])]) Cheers, Bill