Re: select()ing a Map
"Ruud H.G. van Tol" <[email protected]> Sun, 12 May 2024 10:20:35 +0200
| Newsgroups | gmane.comp.mathematics.pari.devel |
|---|---|
| Message-ID | <[email protected]> |
On 2024-05-12 02:46, Ilya Zakharevich wrote:
> I see that there is a request for a specification what should select()
> do on a Map.
>
> • In case when the second argument is a Map and flag is 0, the non-0
> values returned by the function f should be either all scalars, or
> all the same non-scalar type.
>
> • In this case, the type of the non-0 values returned by f()
> determines the type returned by select() — when this makes sense.
> (Returning a scalar non-0 value is equivalent to returning a non-0
> Map.)
>
> Hope this helps,
> Ilya
Just showing some Map-related accessors and implicit transformations:
? {
my( m= Map([ 9, "nine"; 6, "six"; [], "empty"; "two", 2; "one", 1;
"ace", 42 ]) );
print( "Map: ", m ); /* the map, in some order */
print( "Mat: ", Mat(m) ); /* same order */
print( "Vec: ", Vec(m) ); /* the keys, same order */
foreach( m, e, print("e_1: ", e[1]) ); /* other order */
}
Map: Map([6, "six"; 9, "nine"; [], "empty"; "ace", 42; "one", 1; "two", 2])
Mat: [6, "six"; 9, "nine"; [], "empty"; "ace", 42; "one", 1; "two", 2]
Vec: [6, 9, [], "ace", "one", "two"]
e_1: [[], "empty"]
e_1: [6, "six"]
e_1: [9, "nine"]
e_1: ["one", 1]
e_1: ["ace", 42]
e_1: ["two", 2]
-- Ruud