Question: how to use this mapping with the ~ notation?

given A := [[1, 0,9], [5, 0, 6], [4, 0, 0]]; and to remove 0 from each entry, I used map2(remove,has,A,0) which gives 

                   [[1, 9], [5, 6], [4]]

Is it possible to do the same thing using ~ notation for mapping?  (Element-wise Operator). Where now each element is each entry in A? I can't figure what the syntax would be if possible.  remove(has,??,0)~A

For exmaple in Mathematica one would use what is called slot number #. So the above mapping would look like in Maple as doing remove(has,#,0)~A  where now acts as place holder to be filled by each entry taken one at a time from list A as the mapping runs.  But do not know if this is possible in Maple.   

map2 does the job, but can be tricky to use when the function to map takes number of different arguments.

One work around is to make seperate function, and use that for mapping, as follows

f:= x->remove(has,x,0);
f~(A)

which gives  [[1, 9], [5, 6], [4]] correctly. 

So I find the above easier to understand and more clear than map2, and I am not unhappy with it, and so I see no reason to use map2 vs. ~ in this case.

But wanted to see if it was possible to use ~ without making separate function, but do it in-line if you well (using what is called pure function, or unamed function in functional programming).

 

Please Wait...