Question: Should add work on single expressions

This question is about a particularity of a widely used function, which looks like a bug at the first glance, but is not (after carefully studying the help page).

The function “add” (a built-in function with special evaluation rules) is intended to be used on sequences. If for any reason (in a procedure for example) a sequence degenerates to a single scalar expression and add is applied to it, the expression can change. This is most likely undesired. In the case below (simplified from a real case that happened to me) a product is transformed into a nonsense sum.

data := 1.*Unit(m);
accu_length := add(data);
data := data, 2.*Unit(m);
accu_length := add(data);
                       data := 1. Unit(m)

                  accu_length := 1. + Unit(m)

                 data := 1. Unit(m), 2. Unit(m)

                   accu_length := 3. Unit(m)

It is quite likely that the above unit error will be noticed. In the following case it is more likely that a change in value remains unnoticed.

data := 2/5;
add(data);
                                   2
                           data := -
                                   5

                               7

I was wondering whether Maple could issue a warning to prevent this use error of add, when certain types of expressions are passed to add.
Alternatively Maple could return the expression unchanged. So far, I have not found a case where it makes sense to apply add to operands of a scalar expression (excluding set, list, array, ... ).

This leads to the question of whether this functionality (add working on a scalar expression) is needed at all. I tried a few and none of them is useful

[a = b, a^b, a@b, a/b, sin(a), int(f(x), x), a[b]];
map(add, %);
        [        b       a                            ]
        [a = b, a , a@b, -, sin(a), int(f(x), x), a[b]]
        [                b                            ]

          [                         1                ]
          [a + b, a + b, a + b, a + -, a, f(x) + x, b]
          [                         b                ]

Anything else which could make sense?

Please Wait...