I am pretty new to programming in Maple and trying to learn the language. One thing I needed was how to handle lists in a specific way. I have used many hours on this issue now and even asked questions in the Questions section. Other users helped me with clever tricks and I am grateful for that. What is left is however a feeling that one need to know a lot of rather Ad Hoc commands to accomplish your tasks. I looked for operations in the ListTools package, going through all of them. There are a lot of useful operations, but I think some are missing. I will now make some suggestions and you are welcome to shoot it down if I have overlooked some possibilities, which are there already, or make any comments.


1. First thing I needed to remove all numbers from a list A, which was in a list U: 

U := [7, 9, 14];
A := [-2, 7, 8, 12, 9, -78, 0];

After a long time of 'trial and error', messing with the syntax, and looking in the Help menu, I came up with a solution:

E := map(x->`if`(x in U, NULL, x), A);

giving [-2, 8, 12, -78, 0] as wished.

Wouldn't it be a appropriate with a new command in the ListTools package which can do this pretty basic operation, making it possible for people with less knowledge to avoid the rather complex command above?


2. Actually the above was just a sub-problem of what I really wanted. I wanted a list C, where each member is itself a list with two components, made up of two other simple lists A og B. I did the job by using the very nice zip command:

U := [7, 9, 14];
A := [-2, 7, 8, 12, 9, -78, 0];
B := [2, 0, 6, 12, 6, 45, 7];
C := zip((a, b)-> [a, b], A, B);

[[-2, 2], [7, 0], [8, 6], [12, 12], [9, 6], [-78, 45], [0, 7]]

Now I wanted to remove the pair, which had 7, 9 or 14 as first component, listed in U. I tried:

remove(has, C, 7)

but it also removed all the pairs with 7, 9 or 14 in the second component. Then I tried

remove(has, ~op(1, C), 7)

but this time I only received all the first components. Finally I found a way to do it:

E := map(x->`if`(x[1] in U, NULL, x), C);

rather similar to my solution of problem 1. Again I think some new commands in the ListTools package could do the job easier. I know it can only contain basic operations and not ones suited to my exact task. What about a command that could make the first operation as the zip command did? zip is rather general and some people might not even find it, when looking for lists.


3. My third comment is not really about the ListTools package. In my trial and errors I tried the following:

E := map(x->`if`(x[1] not in U, x, NULL), C);

It did not work. Luckily I could reverse the order of NULL and x and just use 'in', but why isn't the syntax 'not in' possible?




Please Wait...